diff --git a/src/components/Account.jsx b/src/components/Account.jsx index f8b6f1f5..b3bfaa1b 100644 --- a/src/components/Account.jsx +++ b/src/components/Account.jsx @@ -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: diff --git a/src/lib/api/axelarscan.js b/src/lib/api/axelarscan.js index 61da1635..054f93d3 100644 --- a/src/lib/api/axelarscan.js +++ b/src/lib/api/axelarscan.js @@ -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() } diff --git a/src/lib/api/gmp.js b/src/lib/api/gmp.js index f504a067..52eecc81 100644 --- a/src/lib/api/gmp.js +++ b/src/lib/api/gmp.js @@ -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() } diff --git a/src/lib/api/token-transfer.js b/src/lib/api/token-transfer.js index 4bbc1216..b0117403 100644 --- a/src/lib/api/token-transfer.js +++ b/src/lib/api/token-transfer.js @@ -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() } @@ -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') diff --git a/src/lib/api/validator.js b/src/lib/api/validator.js index f70025ff..0a129afd 100644 --- a/src/lib/api/validator.js +++ b/src/lib/api/validator.js @@ -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) diff --git a/src/lib/parser.js b/src/lib/parser.js index 71a36083..16f2eb6c 100644 --- a/src/lib/parser.js +++ b/src/lib/parser.js @@ -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