diff --git a/.changeset/plenty-chairs-bow.md b/.changeset/plenty-chairs-bow.md new file mode 100644 index 00000000..597bba94 --- /dev/null +++ b/.changeset/plenty-chairs-bow.md @@ -0,0 +1,5 @@ +--- +'@rosen-bridge/rosen-app': patch +--- + +Address the issue where selecting a token with assets and then switching to a token without any causes the 'use all' button to display an incorrect amount instead of zero diff --git a/apps/rosen/app/_hooks/useMaxTransfer.ts b/apps/rosen/app/_hooks/useMaxTransfer.ts index f8a350bd..96b67f36 100644 --- a/apps/rosen/app/_hooks/useMaxTransfer.ts +++ b/apps/rosen/app/_hooks/useMaxTransfer.ts @@ -33,6 +33,8 @@ export const useMaxTransfer = () => { const loading = isTokenBalanceLoading || isTransitionLoading; const load = useCallback(async () => { + setMax(0n); + const skip = !amount || isTokenBalanceLoading || @@ -46,16 +48,6 @@ export const useMaxTransfer = () => { setError(false); try { - let eventData: any; - - if (selectedSource.name === NETWORKS.BITCOIN) { - eventData = { - fromAddress: await selectedWallet.getAddress(), - toAddress: walletAddressValue, - toChain: targetValue, - }; - } - const max = await getMaxTransfer( selectedSource, { diff --git a/apps/rosen/app/_hooks/useTokenBalance.ts b/apps/rosen/app/_hooks/useTokenBalance.ts index 865f71d9..0677f2ff 100644 --- a/apps/rosen/app/_hooks/useTokenBalance.ts +++ b/apps/rosen/app/_hooks/useTokenBalance.ts @@ -34,9 +34,13 @@ export const useTokenBalance = () => { const getAssetBalance = useCallback( async (wallet: Wallet) => { setBalanceState({ isLoading: true, amount: 0n, token: null }); - // THIS IS A WRAPPED-VALUE - const balance = await wallet.getBalance(token); - setBalanceState({ isLoading: false, amount: balance || 0n, token }); + try { + // THIS IS A WRAPPED-VALUE + const balance = await wallet.getBalance(token); + setBalanceState({ isLoading: false, amount: balance || 0n, token }); + } catch { + setBalanceState({ isLoading: false, amount: 0n, token }); + } }, [token], ); diff --git a/apps/rosen/app/_safeServerAction/safeServerAction.ts b/apps/rosen/app/_safeServerAction/safeServerAction.ts index 3d010153..f05ff3a7 100644 --- a/apps/rosen/app/_safeServerAction/safeServerAction.ts +++ b/apps/rosen/app/_safeServerAction/safeServerAction.ts @@ -103,7 +103,13 @@ export const createSafeAction = (config: CreateSafeActionConfig) => { return async (...args) => { const key = [ actions.get(action), - ...args.map((arg) => arg.toString()), + ...args.map((arg) => { + try { + return JSON.stringify(arg); + } catch { + return arg.toString(); + } + }), ].join('_'); const handler = fromSafeData(action);