Skip to content

Commit

Permalink
Fix token change (#589)
Browse files Browse the repository at this point in the history
* Fix max check of balance-input

* Fix token onChange
  • Loading branch information
JayJay1024 authored Dec 1, 2023
1 parent c008f45 commit bc73733
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/apps/src/components/balance-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function BalanceInput({
if (token && !Number.isNaN(Number(input))) {
parsed = parseValue(input, token.decimals);
insufficientRef.current = balance !== undefined && balance < parsed.value ? true : false;
exceededRef.current = max && max < parsed.value ? true : false;
exceededRef.current = typeof max === "bigint" && max < parsed.value ? true : false;
valid = !(insufficientRef.current || exceededRef.current);
onChange({ valid, ...parsed });
}
Expand Down Expand Up @@ -128,7 +128,7 @@ export function BalanceInput({
if (token && token.decimals !== tokenRef.current?.decimals) {
const parsed = parseValue(value.input, token.decimals);
insufficientRef.current = balance !== undefined && balance < parsed.value ? true : false;
exceededRef.current = max && max < parsed.value ? true : false;
exceededRef.current = typeof max === "bigint" && max < parsed.value ? true : false;
const valid = !(insufficientRef.current || exceededRef.current);
onChange({ valid, ...parsed });
}
Expand All @@ -141,7 +141,7 @@ export function BalanceInput({
const decimals = token.decimals;
const parsed = parseValue(formatUnits(max ?? 0n, decimals), decimals);
insufficientRef.current = balance !== undefined && balance < parsed.value ? true : false;
exceededRef.current = max && max < parsed.value ? true : false;
exceededRef.current = typeof max === "bigint" && max < parsed.value ? true : false;
const valid = !(insufficientRef.current || exceededRef.current);
onChange({ valid, ...parsed });
}
Expand Down
12 changes: 10 additions & 2 deletions packages/apps/src/components/transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default function Transfer() {
}, [address, bridgeInstance, updateSourceBalance]);

useEffect(() => {
setBridgeCategory(bridgeOptions.at(0));
setBridgeCategory((prevValue) => prevValue ?? bridgeOptions.at(0));
}, [bridgeOptions, setBridgeCategory]);

useEffect(() => {
Expand Down Expand Up @@ -292,7 +292,15 @@ export default function Transfer() {
tokenOptions={getAvailableSourceTokens(sourceChain, targetChain)}
onBalanceRefresh={refreshBalance}
onChange={setTransferAmount}
onTokenChange={setSourceToken}
onTokenChange={(_sourceToken) => {
const _targetTokens = getAvailableTargetTokens(sourceChain, targetChain, _sourceToken);
const _targetToken = _targetTokens.at(0);
const _category = getAvailableBridges(sourceChain, targetChain, _sourceToken).at(0);
setBridgeCategory(_category);
setSourceToken(_sourceToken);
setTargetToken(_targetToken);
handleUrlParams({ _category, _sourceToken, _targetToken });
}}
/>
</Label>

Expand Down

0 comments on commit bc73733

Please sign in to comment.