-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: encoding and decoding with right decimals
- Loading branch information
1 parent
716638f
commit 2d51624
Showing
4 changed files
with
51 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useMemo } from "react"; | ||
import { useFormContext, useWatch } from "react-hook-form"; | ||
import { parseUnits } from "viem"; | ||
import type { FormType } from "#/types"; | ||
import { useSelectedPool } from "./useSelectedPool"; | ||
|
||
export function useDepositAmounts(): Record<string, bigint> { | ||
const { control } = useFormContext<FormType>(); | ||
const amounts = useWatch({ control, name: "amounts" }); | ||
const selectedPool = useSelectedPool(); | ||
|
||
return useMemo(() => { | ||
if (!selectedPool) return {}; | ||
|
||
return Object.fromEntries( | ||
Object.entries(amounts).map(([key, value]) => { | ||
const token = selectedPool.allTokens.find( | ||
(token) => token.address.toLowerCase() === key.toLowerCase(), | ||
); | ||
if (!token) return [key, parseUnits(value, 18)]; | ||
|
||
return [key, parseUnits(value, token.decimals)]; | ||
}), | ||
); | ||
}, [selectedPool, amounts]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters