-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Ether deposit validation on change and display balance (#294)
- Loading branch information
1 parent
07636a8
commit 1713cd5
Showing
8 changed files
with
430 additions
and
283 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,42 @@ | ||
import { isNotNil, propOr } from "ramda"; | ||
import { useMemo } from "react"; | ||
import { formatUnits } from "viem"; | ||
import { useAccount, useBalance } from "wagmi"; | ||
|
||
type DataType = | ||
| { | ||
decimals: number; | ||
formatted: string; | ||
symbol: string; | ||
value: bigint; | ||
} | ||
| undefined; | ||
|
||
/** | ||
* Check the ETH balance of the connected account. | ||
* returns the value, decimals, symbol, formatted value and fn to refresh the information. | ||
* @returns | ||
*/ | ||
export const useAccountBalance = () => { | ||
const { address } = useAccount(); | ||
const { data, refetch } = useBalance({ | ||
address, | ||
}); | ||
|
||
const result = useMemo(() => { | ||
const value = propOr<bigint, DataType, bigint>(0n, "value", data); | ||
const decimals = propOr<number, DataType, number>(18, "decimals", data); | ||
const symbol = propOr<string, DataType, string>("ETH", "symbol", data); | ||
const formatted = isNotNil(data) ? formatUnits(value, decimals) : "0"; | ||
|
||
return { | ||
value, | ||
decimals, | ||
symbol, | ||
formatted, | ||
refetch, | ||
}; | ||
}, [data, refetch]); | ||
|
||
return result; | ||
}; |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.