Skip to content

Commit

Permalink
Merge branch '467-miscalculation-amout-when-click-on-use-all-button' …
Browse files Browse the repository at this point in the history
…into 'dev'

Resolve "Miscalculation amout when click on use all button"

Closes #467

See merge request ergo/rosen-bridge/ui!390
  • Loading branch information
zargarzadehm committed Dec 16, 2024
2 parents c4aca04 + d264d69 commit 37f7d3f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-chairs-bow.md
Original file line number Diff line number Diff line change
@@ -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
12 changes: 2 additions & 10 deletions apps/rosen/app/_hooks/useMaxTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const useMaxTransfer = () => {
const loading = isTokenBalanceLoading || isTransitionLoading;

const load = useCallback(async () => {
setMax(0n);

const skip =
!amount ||
isTokenBalanceLoading ||
Expand All @@ -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,
{
Expand Down
10 changes: 7 additions & 3 deletions apps/rosen/app/_hooks/useTokenBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
);
Expand Down
8 changes: 7 additions & 1 deletion apps/rosen/app/_safeServerAction/safeServerAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 37f7d3f

Please sign in to comment.