Skip to content

Commit

Permalink
change input amount when selected token changes
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjah committed Jun 20, 2024
1 parent c4cce52 commit 5f629fc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/store/tokenStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ export const useTokenStore = create<TokenStoreState>((set, get) => ({
if (!selectedToken) {
set({ selectedToken });
}
const currentSelectedToken = get().selectedToken;
const inputAmount = useOperationStore.getState().inputAmount;
if (
inputAmount &&
currentSelectedToken?.decimals !== selectedToken?.decimals
) {
const decsDiff = selectedToken!.decimals - currentSelectedToken!.decimals;
let newAmount: bigint;
if (decsDiff > 0) {
newAmount = inputAmount * 10n ** BigInt(decsDiff);
} else {
newAmount = inputAmount / 10n ** BigInt(-decsDiff);
}
useOperationStore.setState({ inputAmount: newAmount });
}
// if selected token is not in the list, set first selectable token
// selectable is the token supported on the current evm chain selected
const selectable = get().getTokens();
Expand Down

0 comments on commit 5f629fc

Please sign in to comment.