From 593ddc6bb5efe7d4dc8ee55af3023fd21ece593d Mon Sep 17 00:00:00 2001 From: Maxwell Lasky Date: Fri, 8 Sep 2023 13:53:02 -0600 Subject: [PATCH 1/7] WIP removing neoscan dep --- app/actions/balancesActions.js | 42 ++++------- app/actions/nodeStorageActions.js | 1 + app/actions/voteActions.js | 6 +- .../Blockchain/Transaction/Transaction.jsx | 13 +--- app/core/constants.js | 1 - app/core/explorer.js | 11 +-- app/core/wallet.js | 1 + app/modules/transactions.js | 73 ++++++++++--------- flow-typed/declarations.js | 1 - 9 files changed, 67 insertions(+), 82 deletions(-) diff --git a/app/actions/balancesActions.js b/app/actions/balancesActions.js index 783fc4cb5..518f19e66 100644 --- a/app/actions/balancesActions.js +++ b/app/actions/balancesActions.js @@ -279,42 +279,30 @@ async function getBalances({ net, address, isRetry = false, chain }: Props) { } }) - // asset balances - const assetBalances = await api - .getBalanceFrom({ net, address }, api.neoscan) - .catch(e => console.error(e)) + const assetBalances = {} + const mainnetBalances = await axios.get( + `https://dora.coz.io/api/v1/neo2/mainnet/get_balance/${address}`, + ) + mainnetBalances.data.balance.forEach(token => { + assetBalances[token.asset_symbol || token.symbol] = { + balance: token.amount, + hash: token.asset_hash, + } + }) const testnetBalances = await axios.get( `https://dora.coz.io/api/v1/neo2/testnet/get_balance/${address}`, ) const parsedTestNetBalances = {} - testnetBalances.data.balance.forEach(token => { - parsedTestNetBalances[token.asset_symbol || token.symbol] = { + parsedTestNetBalances[token.asset] = { balance: token.amount, hash: token.asset_hash, } }) - - const assets = - net === 'MainNet' - ? get(assetBalances, 'balance.assets', {}) - : parsedTestNetBalances - - // The API doesn't always return NEO or GAS keys if, for example, the address only has one asset - // eslint-disable-next-line - const neoBalance = assets.NEO - ? net === 'MainNet' - ? assets.NEO.balance.toString() - : assets.NEO.balance - : '0' - // eslint-disable-next-line - const gasBalance = assets.GAS - ? net === 'MainNet' - ? assets.GAS.balance.round(COIN_DECIMAL_LENGTH).toString() - : assets.GAS.balance - : '0' - + const assets = net === 'MainNet' ? assetBalances : parsedTestNetBalances + const neoBalance = assets?.NEO?.balance ?? '0' + const gasBalance = assets.GAS?.balance ?? '0' const parsedAssets = [ { [ASSETS.NEO]: neoBalance }, { [ASSETS.GAS]: gasBalance }, @@ -356,6 +344,8 @@ async function getBalances({ net, address, isRetry = false, chain }: Props) { resetAudioTrigger() inMemoryNetwork = net // $FlowFixMe + + console.log(extend({}, ...parsedTokenBalances, ...parsedAssets)) return extend({}, ...parsedTokenBalances, ...parsedAssets) } diff --git a/app/actions/nodeStorageActions.js b/app/actions/nodeStorageActions.js index 24f1770bc..e9658a690 100644 --- a/app/actions/nodeStorageActions.js +++ b/app/actions/nodeStorageActions.js @@ -140,6 +140,7 @@ export const getRPCEndpoint = async ( error, }, ) + // TODO: update this fallback, neoscan is deprecated and this will not work const endpoint = await api.getRPCEndpointFrom({ net }, api.neoscan) return endpoint } finally { diff --git a/app/actions/voteActions.js b/app/actions/voteActions.js index d26c94c03..937a24247 100644 --- a/app/actions/voteActions.js +++ b/app/actions/voteActions.js @@ -3,6 +3,7 @@ import { api, rpc } from '@cityofzion/neon-js-legacy' import { createActions } from 'spunky' import { getNetworkById } from '../core/deprecated' +import { getNode, getRPCEndpoint } from './nodeStorageActions' type Props = { networkId: string, @@ -15,7 +16,10 @@ export default createActions( ID, ({ networkId, address }: Props = {}) => async () => { const net = getNetworkById(networkId) - const endpoint = await api.getRPCEndpointFrom({ net }, api.neoscan) + let endpoint = await getNode(net) + if (!endpoint) { + endpoint = await getRPCEndpoint(net) + } const client = new rpc.RPCClient(endpoint) const validators = await client.getValidators() diff --git a/app/components/Blockchain/Transaction/Transaction.jsx b/app/components/Blockchain/Transaction/Transaction.jsx index 6635779ce..5c495e01e 100644 --- a/app/components/Blockchain/Transaction/Transaction.jsx +++ b/app/components/Blockchain/Transaction/Transaction.jsx @@ -49,14 +49,7 @@ type Props = { } export default function Transaction(props: Props) { - const { - tx: { type }, - chain, - className, - isPending, - renderN2Tx, - address, - } = props + const { tx, chain, className, isPending, renderN2Tx, address } = props const { contacts } = useContactsContext() @@ -150,7 +143,7 @@ export default function Transaction(props: Props) { ) } - switch (type) { + switch (tx?.type) { case TX_TYPES.CLAIM: return case TX_TYPES.SEND: @@ -217,7 +210,7 @@ export default function Transaction(props: Props) {
{chain === 'neo3' && !renderN2Tx ? renderAbstractN3() - : renderAbstract(type)} + : renderAbstract(tx?.type)} {!isPending && (