Skip to content

Commit

Permalink
fetch currently selected chain balance in useEvmBalance
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharqiewicz committed Jan 3, 2025
1 parent 544b4f8 commit a07a2de
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/hooks/useInputTokenBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ import { nativeToDecimal, USDC_DECIMALS } from '../helpers/parseNumbers';
import { usePolkadotWalletState } from '../contexts/polkadotWallet';
import { useAssetHubNode } from '../contexts/polkadotNode';
import { useVortexAccount } from './useVortexAccount';
import { useNetwork } from '../contexts/network';
import { getNetworkId } from '../helpers/networks';

// TODO maybe improve: if the user switches the network in the selector and REJECTS the switch in wallet, then balance will be 0.
const useEvmBalance = (
tokenAddress: `0x${string}` | undefined,
fromToken: InputTokenDetails | undefined,
): string | undefined => {
const { address } = useVortexAccount();
const { selectedNetwork } = useNetwork();

const { data: balance } = useReadContract({
address: tokenAddress,
abi: erc20ABI,
functionName: 'balanceOf',
args: [address],
chainId: getNetworkId(selectedNetwork),
});
if (!fromToken || (!balance && balance !== BigInt(0))) return undefined;
return multiplyByPowerOfTen(Big(balance.toString()), -fromToken.decimals).toFixed(2, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/services/phases/signedTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { prepareNablaApproveTransaction, prepareNablaSwapTransaction } from './n
import { setUpAccountAndOperations, stellarCreateEphemeral } from './stellar';
import { prepareSpacewalkRedeemTransaction } from './polkadot';

export const getTransactionPhase = (network: Networks): 'squidRouter' | 'pendulumFundEphemeral' => {
const getNextPhase = (network: Networks): 'squidRouter' | 'pendulumFundEphemeral' => {
// For AssetHub we skip the squidRouter and go straight to the pendulumFundEphemeral phase
return isNetworkEVM(network) ? 'squidRouter' : 'pendulumFundEphemeral';
};
Expand Down Expand Up @@ -99,6 +99,6 @@ export async function prepareTransactions(state: OfframpingState, context: Execu
return {
...state,
transactions,
phase: getTransactionPhase(state.network),
phase: getNextPhase(state.network),
};
}

0 comments on commit a07a2de

Please sign in to comment.