-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: simplify and refactor usePSBT hook (#243)
* feat: modify usePSBT hook, abstract logic into hooks, dry functions
- Loading branch information
1 parent
76c0705
commit 03ce993
Showing
14 changed files
with
326 additions
and
397 deletions.
There are no files selected for viewing
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
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { EthereumNetworkConfigurationContext } from '@providers/ethereum-network-configuration.provider'; | ||
import { NetworkConfigurationContext } from '@providers/network-configuration.provider'; | ||
import { RippleNetworkConfigurationContext } from '@providers/ripple-network-configuration.provider'; | ||
import { getRawVault } from 'dlc-btc-lib/ethereum-functions'; | ||
import { RawVault } from 'dlc-btc-lib/models'; | ||
import { getRippleVault } from 'dlc-btc-lib/ripple-functions'; | ||
|
||
import { NetworkType } from '@shared/constants/network.constants'; | ||
|
||
interface UseFetchVault { | ||
fetchVault: (vaultUUID: string) => Promise<RawVault>; | ||
} | ||
|
||
export function useFetchVault(): UseFetchVault { | ||
const { networkType } = useContext(NetworkConfigurationContext); | ||
|
||
const { | ||
ethereumNetworkConfiguration: { dlcManagerContract }, | ||
} = useContext(EthereumNetworkConfigurationContext); | ||
|
||
const { rippleClient } = useContext(RippleNetworkConfigurationContext); | ||
|
||
const fetchEVMVault = async (vaultUUID: string): Promise<RawVault> => { | ||
return await getRawVault(dlcManagerContract, vaultUUID); | ||
}; | ||
|
||
const fetchXRPLVault = async (vaultUUID: string): Promise<RawVault> => { | ||
return await getRippleVault(rippleClient, appConfiguration.rippleIssuerAddress, vaultUUID); | ||
}; | ||
|
||
const fetchVault = async (vaultUUID: string): Promise<RawVault> => { | ||
try { | ||
switch (networkType) { | ||
case NetworkType.EVM: | ||
return fetchEVMVault(vaultUUID); | ||
case NetworkType.XRPL: | ||
return fetchXRPLVault(vaultUUID); | ||
} | ||
} catch (error) { | ||
throw new Error('Error getting Vault: ' + error); | ||
} | ||
}; | ||
|
||
return { | ||
fetchVault, | ||
}; | ||
} |
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.