Skip to content

Commit

Permalink
fix no account form loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitayutanov committed Nov 20, 2024
1 parent fb0b786 commit 2d9a048
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@ type Props = {
symbol: string | undefined;
amount: string;
isVaraNetwork: boolean;
isLoading: boolean;
};

function FTAllowanceTip({ allowance, decimals, symbol, amount, isVaraNetwork }: Props) {
const isLoading = isUndefined(allowance) || !decimals || !symbol;
if (isLoading) return <Skeleton width="14px" height="14px" borderRadius="50%" className={styles.skeleton} />;
function FTAllowanceTip({ allowance, decimals, symbol, amount, isVaraNetwork, isLoading }: Props) {
const isEmpty = isUndefined(allowance) || !decimals || !symbol;

if (isLoading || isEmpty)
return (
<Skeleton
width="14px"
height="14px"
borderRadius="50%"
className={styles.skeleton}
disabled={!isLoading && isEmpty}
/>
);

const formattedAllowance = formatUnits(allowance, decimals);
const contractName = isVaraNetwork ? 'VFT' : 'ERC20';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ function SwapForm({
symbol={symbol}
amount={amount}
isVaraNetwork={isVaraNetwork}
isLoading={bridge.isLoading || allowance.isLoading}
/>
</div>
</footer>
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/features/swap/hooks/eth/use-eth-ft-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function useEthFTBalance(address: HexString | undefined, decimals: number | unde
const ethAccount = useEthAccount();

// TODO: logger
const { data, isPending } = useReadContract({
const { data, isLoading } = useReadContract({
address,
abi,
functionName: FUNCTION_NAME.FUNGIBLE_TOKEN_BALANCE,
Expand All @@ -29,7 +29,6 @@ function useEthFTBalance(address: HexString | undefined, decimals: number | unde

const value = data;
const formattedValue = !isUndefined(value) && !isUndefined(decimals) ? formatUnits(value, decimals) : undefined;
const isLoading = ethAccount.isConnected && isPending;

return { value, formattedValue, decimals, isLoading };
}
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/features/swap/hooks/vara/use-vara-ft-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function useVaraFTBalance(address: HexString | undefined, decimals: number | und
id: address,
});

const { data, isPending } = useProgramQuery({
const { data, isLoading } = useProgramQuery({
program,
serviceName: SERVICE_NAME.VFT,
functionName: QUERY_NAME.BALANCE,
Expand All @@ -25,7 +25,6 @@ function useVaraFTBalance(address: HexString | undefined, decimals: number | und

const value = data;
const formattedValue = !isUndefined(value) && !isUndefined(decimals) ? formatUnits(value, decimals) : undefined;
const isLoading = isPending;

return { value, formattedValue, decimals, isLoading };
}
Expand Down

0 comments on commit 2d9a048

Please sign in to comment.