-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64c3711
commit 4145d48
Showing
8 changed files
with
168 additions
and
29 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
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
2 changes: 2 additions & 0 deletions
2
packages/dapp-kit-react-privy/src/DAppKitPrivyProvider/hooks/index.ts
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export * from "./useB3TRBalance"; | ||
export * from "./useWalletAdapter"; | ||
export * from "./useTxReceipt"; | ||
export * from "./useVOT3Balance"; | ||
export * from "./useSendAccountAbstractedTransaction"; | ||
export * from "./useSmartAccount"; |
33 changes: 33 additions & 0 deletions
33
packages/dapp-kit-react-privy/src/DAppKitPrivyProvider/hooks/useB3TRBalance.tsx
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,33 @@ | ||
import { useQuery, UseQueryResult } from "@tanstack/react-query"; | ||
import { B3TR_CONTRACT } from "../utils/consts"; | ||
import { FixedPointNumber, Units } from "@vechain/sdk-core"; | ||
|
||
export const useB3TRBalance = ({ | ||
address | ||
}: { | ||
address: string; | ||
}): UseQueryResult<string, unknown> => { | ||
return useQuery({ | ||
queryKey: ["useB3TRBalance", address], | ||
queryFn: async () => { | ||
if (address !== null && address !== undefined && address === '') { | ||
return '0'; | ||
} | ||
try { | ||
const balanceB3TR = ( | ||
await B3TR_CONTRACT.read.balanceOf(address) | ||
)[0] as bigint; | ||
|
||
return Units.formatEther( | ||
FixedPointNumber.of(balanceB3TR) | ||
); | ||
} catch (error) { | ||
console.error('Failed to fetch B3TR balance:', error); | ||
return 'error'; | ||
} | ||
}, | ||
staleTime: 3000, | ||
refetchInterval: 10000, | ||
enabled: address !== null && address !== undefined && address !== '' | ||
}); | ||
}; |
33 changes: 33 additions & 0 deletions
33
packages/dapp-kit-react-privy/src/DAppKitPrivyProvider/hooks/useVOT3Balance.tsx
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,33 @@ | ||
import { useQuery, UseQueryResult } from "@tanstack/react-query"; | ||
import { VOT3_CONTRACT } from "../utils/consts"; | ||
import { FixedPointNumber, Units } from "@vechain/sdk-core"; | ||
|
||
export const useVOT3Balance = ({ | ||
address | ||
}: { | ||
address: string; | ||
}): UseQueryResult<string, unknown> => { | ||
return useQuery({ | ||
queryKey: ["useVOT3Balance", address], | ||
queryFn: async () => { | ||
if (address !== null && address !== undefined && address === '') { | ||
return '0'; | ||
} | ||
try { | ||
const balanceVOT3 = ( | ||
await VOT3_CONTRACT.read.balanceOf(address) | ||
)[0] as bigint; | ||
|
||
return Units.formatEther( | ||
FixedPointNumber.of(balanceVOT3) | ||
); | ||
} catch (error) { | ||
console.error('Failed to fetch VOT3 balance:', error); | ||
return 'error'; | ||
} | ||
}, | ||
staleTime: 3000, | ||
refetchInterval: 10000, | ||
enabled: address !== null && address !== undefined && address !== '' | ||
}); | ||
}; |
23 changes: 23 additions & 0 deletions
23
packages/dapp-kit-react-privy/src/DAppKitPrivyProvider/utils/consts.ts
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,23 @@ | ||
import { B3TR, VOT3 } from '@vechain/vebetterdao-contracts'; | ||
import { ThorClient } from '@vechain/sdk-network'; | ||
|
||
/** | ||
* Thor client instance | ||
*/ | ||
export const THOR_CLIENT = ThorClient.at('https://mainnet.vechain.org'); | ||
|
||
/** | ||
* B3TR contract instance | ||
*/ | ||
export const B3TR_CONTRACT = THOR_CLIENT.contracts.load( | ||
B3TR.address.mainnet, | ||
B3TR.abi | ||
); | ||
|
||
/** | ||
* VOT3 contract instance | ||
*/ | ||
export const VOT3_CONTRACT = THOR_CLIENT.contracts.load( | ||
VOT3.address.mainnet, | ||
VOT3.abi | ||
); |
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 |
---|---|---|
|
@@ -4837,11 +4837,21 @@ | |
read-package-json-fast "^3.0.0" | ||
which "^3.0.0" | ||
|
||
"@openzeppelin/[email protected]": | ||
version "5.0.2" | ||
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-5.0.2.tgz#3e5321a2ecdd0b206064356798c21225b6ec7105" | ||
integrity sha512-0MmkHSHiW2NRFiT9/r5Lu4eJq5UJ4/tzlOgYXNAIj/ONkQTVnz22pLxDvp4C4uZ9he7ZFvGn3Driptn1/iU7tQ== | ||
|
||
"@openzeppelin/contracts-upgradeable@^5.0.2": | ||
version "5.1.0" | ||
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-5.1.0.tgz#4d37648b7402929c53e2ff6e45749ecff91eb2b6" | ||
integrity sha512-AIElwP5Ck+cslNE+Hkemf5SxjJoF4wBvvjxc27Rp+9jaPs/CLIaUBMYe1FNzhdiN0cYuwGRmYaRHmmntuiju4Q== | ||
|
||
"@openzeppelin/[email protected]": | ||
version "5.0.2" | ||
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-5.0.2.tgz#b1d03075e49290d06570b2fd42154d76c2a5d210" | ||
integrity sha512-ytPc6eLGcHHnapAZ9S+5qsdomhjo6QBHTDRRBFfTxXIpsicMhVPouPgmUPebZZZGX7vt9USA+Z+0M0dSVtSUEA== | ||
|
||
"@openzeppelin/contracts@^5.0.2": | ||
version "5.1.0" | ||
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-5.1.0.tgz#4e61162f2a2bf414c4e10c45eca98ce5f1aadbd4" | ||
|
@@ -7525,6 +7535,15 @@ | |
"@openzeppelin/contracts-upgradeable" "^5.0.2" | ||
ethers "^6.9.0" | ||
|
||
"@vechain/vebetterdao-contracts@^4.1.0": | ||
version "4.1.0" | ||
resolved "https://registry.yarnpkg.com/@vechain/vebetterdao-contracts/-/vebetterdao-contracts-4.1.0.tgz#5a081bf9c548ea777fe16dcab40536d6d2cc1a62" | ||
integrity sha512-vLxxErpvHuVisrkgvrrqgz8hkhbhreEmOyjolcRGpYF9ozzhEm1wTZKelO9qmKoNi/mviMG6ZYZU3Ykwg9LfIw== | ||
dependencies: | ||
"@openzeppelin/contracts" "5.0.2" | ||
"@openzeppelin/contracts-upgradeable" "5.0.2" | ||
ethers "^6.9.0" | ||
|
||
"@vitejs/[email protected]": | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/@vitejs/plugin-basic-ssl/-/plugin-basic-ssl-1.0.1.tgz#48c46eab21e0730921986ce742563ae83fe7fe34" | ||
|