-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: some refactors, missing tests added
- Loading branch information
Showing
7 changed files
with
287 additions
and
80 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
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,36 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { ChainId } from '@avalabs/core-chains-sdk'; | ||
import { JsonRpcBatchInternal } from '@avalabs/core-wallets-sdk'; | ||
|
||
import { useNetworkContext } from '@src/contexts/NetworkProvider'; | ||
import { getProviderForNetwork } from '@src/utils/network/getProviderForNetwork'; | ||
|
||
export const useAvalancheCProvider = (isTestnet) => { | ||
const { getNetwork } = useNetworkContext(); | ||
|
||
const [provider, setProvider] = useState<JsonRpcBatchInternal>(); | ||
|
||
useEffect(() => { | ||
const cChain = getNetwork( | ||
isTestnet ? ChainId.AVALANCHE_MAINNET_ID : ChainId.AVALANCHE_TESTNET_ID | ||
); | ||
|
||
if (!cChain) { | ||
return; | ||
} | ||
|
||
let isMounted = true; | ||
|
||
getProviderForNetwork(cChain).then((cChainProvider) => { | ||
if (isMounted && cChainProvider instanceof JsonRpcBatchInternal) { | ||
setProvider(cChainProvider); | ||
} | ||
}); | ||
|
||
return () => { | ||
isMounted = false; | ||
}; | ||
}); | ||
|
||
return provider; | ||
}; |
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,36 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { ChainId } from '@avalabs/core-chains-sdk'; | ||
import { BitcoinProvider } from '@avalabs/core-wallets-sdk'; | ||
|
||
import { useNetworkContext } from '@src/contexts/NetworkProvider'; | ||
import { getProviderForNetwork } from '@src/utils/network/getProviderForNetwork'; | ||
|
||
export const useBitcoinProvider = (isTestnet) => { | ||
const { getNetwork } = useNetworkContext(); | ||
|
||
const [provider, setProvider] = useState<BitcoinProvider>(); | ||
|
||
useEffect(() => { | ||
const btcNetwork = getNetwork( | ||
isTestnet ? ChainId.BITCOIN_TESTNET : ChainId.BITCOIN | ||
); | ||
|
||
if (!btcNetwork) { | ||
return; | ||
} | ||
|
||
let isMounted = true; | ||
|
||
getProviderForNetwork(btcNetwork).then((bitcoinProvider) => { | ||
if (isMounted && bitcoinProvider instanceof BitcoinProvider) { | ||
setProvider(bitcoinProvider); | ||
} | ||
}); | ||
|
||
return () => { | ||
isMounted = false; | ||
}; | ||
}); | ||
|
||
return provider; | ||
}; |
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,36 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { ChainId } from '@avalabs/core-chains-sdk'; | ||
import { JsonRpcBatchInternal } from '@avalabs/core-wallets-sdk'; | ||
|
||
import { useNetworkContext } from '@src/contexts/NetworkProvider'; | ||
import { getProviderForNetwork } from '@src/utils/network/getProviderForNetwork'; | ||
|
||
export const useEthereumProvider = (isTestnet) => { | ||
const { getNetwork } = useNetworkContext(); | ||
|
||
const [provider, setProvider] = useState<JsonRpcBatchInternal>(); | ||
|
||
useEffect(() => { | ||
const ethNetwork = getNetwork( | ||
isTestnet ? ChainId.ETHEREUM_TEST_SEPOLIA : ChainId.ETHEREUM_HOMESTEAD | ||
); | ||
|
||
if (!ethNetwork) { | ||
return; | ||
} | ||
|
||
let isMounted = true; | ||
|
||
getProviderForNetwork(ethNetwork).then((ethProvider) => { | ||
if (isMounted && ethProvider instanceof JsonRpcBatchInternal) { | ||
setProvider(ethProvider); | ||
} | ||
}); | ||
|
||
return () => { | ||
isMounted = false; | ||
}; | ||
}); | ||
|
||
return provider; | ||
}; |
Oops, something went wrong.