Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use GET request with queryString for most of requests #151

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b324282
feat: use GET request with queryString for most of requests
nrsirapop Oct 30, 2024
626080d
chore: remove unused break
nrsirapop Oct 30, 2024
13a912d
Merge branch 'main' into feat/httpRequest
nrsirapop Nov 1, 2024
13d239d
Merge branch 'main' into feat/httpRequest
nrsirapop Nov 1, 2024
1c717f2
Merge branch 'main' into feat/httpRequest
nrsirapop Nov 4, 2024
40ea392
Merge branch 'main' into feat/httpRequest
nrsirapop Nov 5, 2024
e9f4d22
Merge branch 'main' into feat/httpRequest
nrsirapop Nov 8, 2024
2d93c3a
Merge branch 'main' into feat/httpRequest
nrsirapop Nov 13, 2024
3547dcc
Merge branch 'main' into feat/httpRequest
nrsirapop Nov 13, 2024
03ad504
Merge branch 'main' into feat/httpRequest
nrsirapop Nov 13, 2024
633ffc8
Merge branch 'main' into feat/httpRequest
nrsirapop Dec 4, 2024
c9b90e2
Merge branch 'main' into feat/httpRequest
nrsirapop Dec 4, 2024
371ff5e
Merge branch 'main' into feat/httpRequest
nrsirapop Dec 5, 2024
6483632
Merge branch 'main' into feat/httpRequest
nrsirapop Dec 12, 2024
15fc676
Merge branch 'main' into feat/httpRequest
nrsirapop Dec 18, 2024
db64562
Merge branch 'main' into feat/httpRequest
nrsirapop Dec 18, 2024
0785d70
Merge branch 'main' into feat/httpRequest
nrsirapop Dec 18, 2024
9c5e41a
Merge branch 'main' into feat/httpRequest
nrsirapop Dec 18, 2024
ffbca37
Merge branch 'main' into feat/httpRequest
nrsirapop Dec 19, 2024
3c00850
Merge branch 'main' into feat/httpRequest
nrsirapop Dec 19, 2024
afdd430
Merge branch 'main' into feat/httpRequest
nrsirapop Dec 19, 2024
e49d5ae
Merge branch 'main' into feat/httpRequest
nrsirapop Dec 19, 2024
8d86386
Merge branch 'main' into feat/httpRequest
nrsirapop Dec 30, 2024
98e5594
Merge branch 'main' into feat/httpRequest
nrsirapop Jan 8, 2025
f55cbbb
Merge branch 'main' into feat/httpRequest
nrsirapop Jan 20, 2025
d324292
Merge branch 'main' into feat/httpRequest
nrsirapop Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/components/Account.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ function Delegations({ data }) {
return toArray(delegations?.data).length > 0
case 'redelegations':
return toArray(redelegations?.data).length > 0
break
case 'unstakings':
return toArray(unbondings?.data).length > 0
default:
Expand Down
6 changes: 4 additions & 2 deletions src/lib/api/axelarscan.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const request = async (method, params) => {
const response = await fetch(`${process.env.NEXT_PUBLIC_AXELARSCAN_API_URL}/${method}`, { method: 'POST', body: JSON.stringify(params) }).catch(error => { return null })
import { objToQS } from '@/lib/parser'

const request = async (method, params, requestMethod = 'GET') => {
const response = await fetch(`${process.env.NEXT_PUBLIC_AXELARSCAN_API_URL}/${method}${requestMethod === 'GET' ? objToQS(params) : ''}`, { method: requestMethod, body: requestMethod === 'GET' ? undefined : JSON.stringify(params) }).catch(error => { return null })
return response && await response.json()
}

Expand Down
6 changes: 4 additions & 2 deletions src/lib/api/gmp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const request = async (method, params) => {
const response = await fetch(`${process.env.NEXT_PUBLIC_GMP_API_URL}/${method}`, { method: 'POST', body: JSON.stringify(params) }).catch(error => { return null })
import { objToQS } from '@/lib/parser'

const request = async (method, params, requestMethod = 'GET') => {
const response = await fetch(`${process.env.NEXT_PUBLIC_GMP_API_URL}/${method}${requestMethod === 'GET' ? objToQS(params) : ''}`, { method: requestMethod, body: requestMethod === 'GET' ? undefined : JSON.stringify(params) }).catch(error => { return null })
return response && await response.json()
}

Expand Down
8 changes: 5 additions & 3 deletions src/lib/api/token-transfer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const request = async (method, params) => {
const response = await fetch(`${process.env.NEXT_PUBLIC_TOKEN_TRANSFER_API_URL}/${method}`, { method: 'POST', body: JSON.stringify(params) }).catch(error => { return null })
import { objToQS } from '@/lib/parser'

const request = async (method, params, requestMethod = 'GET') => {
const response = await fetch(`${process.env.NEXT_PUBLIC_TOKEN_TRANSFER_API_URL}/${method}${requestMethod === 'GET' ? objToQS(params) : ''}`, { method: requestMethod, body: requestMethod === 'GET' ? undefined : JSON.stringify(params) }).catch(error => { return null })
return response && await response.json()
}

Expand All @@ -12,4 +14,4 @@ export const transfersTotalActiveUsers = async params => await request('transfer
export const transfersTopUsers = async params => await request('transfersTopUsers', params)
export const searchDepositAddresses = async params => await request('searchDepositAddresses', params)
export const searchBatches = async params => await request('searchBatches', params)
export const getBatch = async (chain, batchId) => await request('lcd', { path: `/axelar/evm/v1beta1/batched_commands/${chain}/${batchId}` })
export const getBatch = async (chain, batchId) => await request('lcd', { path: `/axelar/evm/v1beta1/batched_commands/${chain}/${batchId}` }, 'POST')
18 changes: 10 additions & 8 deletions src/lib/api/validator.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const request = async (method, params) => {
const response = await fetch(`${process.env.NEXT_PUBLIC_VALIDATOR_API_URL}/${method}`, { method: 'POST', body: JSON.stringify(params) }).catch(error => { return null })
import { objToQS } from '@/lib/parser'

const request = async (method, params, requestMethod = 'GET') => {
const response = await fetch(`${process.env.NEXT_PUBLIC_VALIDATOR_API_URL}/${method}${requestMethod === 'GET' ? objToQS(params) : ''}`, { method: requestMethod, body: requestMethod === 'GET' ? undefined : JSON.stringify(params) }).catch(error => { return null })
return response && await response.json()
}

export const rpc = async params => await request('rpc', params)
export const getRPCStatus = async params => await request('rpc', { ...params, path: '/status' })
export const lcd = async params => await request('lcd', params)
export const getBlock = async height => await request('lcd', { path: `/cosmos/base/tendermint/v1beta1/blocks/${height}` })
export const getValidatorSets = async (height = 'latest') => await request('lcd', { path: `/validatorsets/${height}` })
export const getTransaction = async txhash => await request('lcd', { path: `/cosmos/tx/v1beta1/txs/${txhash}` })
export const rpc = async params => await request('rpc', params, 'POST')
export const getRPCStatus = async params => await request('rpc', { ...params, path: '/status' }, 'POST')
export const lcd = async params => await request('lcd', params, 'POST')
export const getBlock = async height => await request('lcd', { path: `/cosmos/base/tendermint/v1beta1/blocks/${height}` }, 'POST')
export const getValidatorSets = async (height = 'latest') => await request('lcd', { path: `/validatorsets/${height}` }, 'POST')
export const getTransaction = async txhash => await request('lcd', { path: `/cosmos/tx/v1beta1/txs/${txhash}` }, 'POST')
export const searchBlocks = async params => await request('searchBlocks', params)
export const searchTransactions = async params => await request('searchTransactions', params)
export const getTransactions = async params => await request('getTransactions', params)
Expand Down
6 changes: 6 additions & 0 deletions src/lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ const { base64, getAddress, hexlify, toUtf8String } = { ...utils }
const decodeBase64 = base64.decode
import _ from 'lodash'

export const objToQS = obj => {
const qs = Object.entries({ ...obj }).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join('&')
if (!qs) return ''
return `?${qs}`
}

export const getIcapAddress = string => {
try {
return string?.startsWith('0x') ? getAddress(string) : string
Expand Down