-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transitioned all send components to use reducer
- Loading branch information
1 parent
d93e6d4
commit 4222512
Showing
7 changed files
with
323 additions
and
360 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import { useEffect } from 'react'; | ||
import { useMemo } from 'react'; | ||
import Web3 from 'web3'; | ||
|
||
import { EVM_ENDPOINT } from '@/constant'; | ||
|
||
import { useNetworkStore } from '../stores/networkStore'; | ||
import { useProviderStore } from '../stores/providerStore'; | ||
|
||
export const useWeb3 = () => { | ||
const { currentNetwork: network } = useNetworkStore(); | ||
|
||
const providerStore = useProviderStore(); | ||
|
||
useEffect(() => { | ||
providerStore.setWeb3Instance(network); | ||
}, [network, providerStore]); | ||
const { currentNetwork } = useNetworkStore(); | ||
const network = currentNetwork || 'mainnet'; | ||
const web3instance = useMemo(() => { | ||
const provider = new Web3.providers.HttpProvider(EVM_ENDPOINT[network]); | ||
return new Web3(provider); | ||
}, [network]); | ||
|
||
return providerStore.web3Instance; | ||
return web3instance; | ||
}; |
Oops, something went wrong.