Skip to content

Commit

Permalink
Fix 0 balance, fix undefined symbol (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
toddkao authored Nov 1, 2024
1 parent 8d1df58 commit f02e27e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
10 changes: 10 additions & 0 deletions packages/widget-v2/src/hooks/useGetSourceBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ export const useGetSourceBalance = () => {
const { chainID, denom } = sourceAsset;
if (!denom || !chainID) return;

const denomsExists = !!skipBalances?.chains?.[chainID]?.denoms;
const sourceBalance = skipBalances?.chains?.[chainID]?.denoms?.[denom];

if (denomsExists && sourceBalance === undefined) {
return {
amount: 0,
formattedAmount: "0",
error: undefined,
};
}
return skipBalances?.chains?.[chainID]?.denoms?.[denom];
}, [sourceAsset, sourceAccount, skipBalances]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ export const ConnectedWalletContent = () => {
const connectedWalletModal = useModal(ConnectedWalletModal);

const formattedBalance = useMemo(() => {
const symbol = sourceDetails?.symbol ? ` ${sourceDetails?.symbol}` : "";
if (sourceBalance?.error?.message) return "--";
if (sourceBalance === undefined) return `0 ${sourceDetails?.symbol}`;
if (sourceBalance === undefined) return;

const amount = sourceBalance?.amount;
let formattedBalanceAmount = sourceBalance?.formattedAmount;
Expand All @@ -38,7 +39,8 @@ export const ConnectedWalletContent = () => {
formattedBalanceAmount = amount;
}

return `${limitDecimalsDisplayed(formattedBalanceAmount)} ${sourceDetails?.symbol}`;
return `${limitDecimalsDisplayed(formattedBalanceAmount)
}${symbol}`;
}, [sourceBalance, sourceDetails?.symbol]);
if (!sourceAccount) return null;
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/widget-v2/src/providers/CosmosProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const CosmosProvider: React.FC<CosmosProviderProps> = ({
<GrazProvider grazOptions={{
// @ts-expect-error mismatch keplr types version
chains: mainnetChains,
autoReconnect: true,
autoReconnect: false,
walletDefaultOptions: {
sign: {
preferNoSetFee: true,
Expand Down

0 comments on commit f02e27e

Please sign in to comment.