Skip to content

Commit

Permalink
feat: modify hook return types
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Mar 18, 2024
2 parents 74c180a + 8b90d60 commit bd69126
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 21 deletions.
20 changes: 20 additions & 0 deletions .env template
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# VITE_ATTESTOR_API_URLS_EXAMPLE: https://example/attestor-1,https://example/attestor-2,https://example/attestor-3

# Regtest

VITE_ETHEREUM_DEPLOYMENT_BRANCH=dev
VITE_ETHEREUM_DEPLOYMENT_VERSION=1
VITE_ENABLED_ETHEREUM_NETWORKS='11155111'
VITE_ATTESTOR_API_URLS=
VITE_BITCOIN_NETWORK=regtest
VITE_BITCOIN_EXPLORER_API_URL=https://devnet.dlc.link/electrs/tx/
VITE_BITCOIN_BLOCKCHAIN_API_URL=https://devnet.dlc.link/electrs

# # Testnet
# VITE_ETHEREUM_DEPLOYMENT_BRANCH=dev
# VITE_ETHEREUM_DEPLOYMENT_VERSION=1
# VITE_ENABLED_ETHEREUM_NETWORKS='11155111'
# VITE_ATTESTOR_API_URLS=
# VITE_BITCOIN_NETWORK=testnet
# VITE_BITCOIN_EXPLORER_API_URL=https://mempool.space/testnet/tx/
# VITE_BITCOIN_BLOCKCHAIN_API_URL=https://testnet.dlc.link/electrs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { ModalLayout } from '@components/modals/components/modal.layout';
import { SelectWalletMenu } from '@components/modals/select-wallet-modal/components/select-wallet-menu';
import { SelectNetworkButton } from '@components/select-network-button/select-network-button';
import { useEthereumAccount } from '@hooks/use-ethereum-account';
import { Network } from '@models/ethereum-network';
import { EthereumNetwork } from '@models/ethereum-network';
import { WalletType, ethereumWallets } from '@models/wallet';

export function SelectWalletModal({ isOpen, handleClose }: ModalComponentProps): React.JSX.Element {
const ethereumAccountHandler = useEthereumAccount();

const [currentNetwork, setCurrentNetwork] = useState<Network | undefined>(undefined);
const [currentNetwork, setCurrentNetwork] = useState<EthereumNetwork | undefined>(undefined);

async function handleLogin(walletType: WalletType) {
if (!currentNetwork) throw new Error('No network selected');
Expand All @@ -22,7 +22,7 @@ export function SelectWalletModal({ isOpen, handleClose }: ModalComponentProps):
handleClose();
}

const handleNetworkChange = (currentNetwork: Network) => {
const handleNetworkChange = (currentNetwork: EthereumNetwork) => {
setCurrentNetwork(currentNetwork);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ChevronDownIcon } from '@chakra-ui/icons';
import { HStack, Menu, MenuButton, MenuItem, MenuList, Text } from '@chakra-ui/react';
import { Network, ethereumNetworks } from '@models/ethereum-network';
import { EthereumNetwork, ethereumNetworks } from '@models/ethereum-network';

interface SelectNetworkButtonProps {
handleClick: (network: Network) => void;
currentNetwork?: Network;
handleClick: (network: EthereumNetwork) => void;
currentNetwork?: EthereumNetwork;
}

export function SelectNetworkButton({
Expand Down
2 changes: 1 addition & 1 deletion src/app/hooks/use-attestors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AttestorError } from '@models/error-types';

import { useEndpoints } from './use-endpoints';

export interface UseAttestorsReturnType {
interface UseAttestorsReturnType {
getAttestorGroupPublicKey: () => Promise<string>;
sendClosingTransactionToAttestors: (
closingPSBT: string,
Expand Down
2 changes: 1 addition & 1 deletion src/app/hooks/use-bitcoin-price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';

import { BitcoinError } from '@models/error-types';

export interface UseBitcoinPriceReturnType {
interface UseBitcoinPriceReturnType {
bitcoinPrice: number;
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/hooks/use-bitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ interface RpcResponse {
result: RpcResult;
}

export interface UseBitcoinReturnType {
interface UseBitcoinReturnType {
signAndBroadcastFundingPSBT: (btcAmount: number) => Promise<{
fundingTransaction: btc.Transaction;
multisigTransaction: btc.P2TROut;
Expand Down
14 changes: 8 additions & 6 deletions src/app/hooks/use-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export function useEndpoints(): NetworkEndpoints {
const attestorAPIURLs: string[] = import.meta.env.VITE_ATTESTOR_API_URLS.split(',');

const bitcoinNetworkName = import.meta.env.VITE_BITCOIN_NETWORK;
const bitcoinBlockchainAPIURL = import.meta.env.VITE_BITCOIN_BLOCKCHAIN_API_URL;
const bitcoinExplorerAPIURL = import.meta.env.VITE_BITCOIN_EXPLORER_API_URL;
let bitcoinNetwork;

switch (bitcoinNetworkName) {
Expand All @@ -72,8 +74,8 @@ export function useEndpoints(): NetworkEndpoints {
attestorAPIURLs,
ethereumExplorerAPIURL: 'https://sepolia.etherscan.io/tx/',
ethereumAttestorChainID: 'evm-sepolia',
bitcoinExplorerAPIURL: 'http://devnet.dlc.link/electrs/tx/',
bitcoinBlockchainAPIURL: 'https://devnet.dlc.link/electrs',
bitcoinExplorerAPIURL,
bitcoinBlockchainAPIURL,
bitcoinNetwork,
bitcoinNetworkName,
};
Expand All @@ -82,8 +84,8 @@ export function useEndpoints(): NetworkEndpoints {
attestorAPIURLs,
ethereumExplorerAPIURL: 'https://goerli.etherscan.io/tx/',
ethereumAttestorChainID: 'evm-goerli',
bitcoinExplorerAPIURL: 'https://blockstream.info/testnet/tx/',
bitcoinBlockchainAPIURL: 'https://devnet.dlc.link/electrs',
bitcoinExplorerAPIURL,
bitcoinBlockchainAPIURL,
bitcoinNetwork,
bitcoinNetworkName,
};
Expand All @@ -92,8 +94,8 @@ export function useEndpoints(): NetworkEndpoints {
attestorAPIURLs,
ethereumExplorerAPIURL: 'https://www.oklink.com/x1-test/tx/',
ethereumAttestorChainID: 'evm-x1-test',
bitcoinExplorerAPIURL: 'http://devnet.dlc.link/electrs/tx/',
bitcoinBlockchainAPIURL: 'https://devnet.dlc.link/electrs',
bitcoinExplorerAPIURL,
bitcoinBlockchainAPIURL,
bitcoinNetwork,
bitcoinNetworkName,
};
Expand Down
4 changes: 2 additions & 2 deletions src/app/hooks/use-ethereum-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ethers } from 'ethers';
import { throwEthereumError } from './use-ethereum';
import { useEthereumContext } from './use-ethereum-context';

export interface UseEthereumReturnType {
interface UseEthereumAccountReturnType {
connectEthereumAccount: (walletType: WalletType, network: EthereumNetwork) => Promise<void>;
recommendTokenToMetamask: () => Promise<boolean>;
isLoaded: boolean;
Expand All @@ -41,7 +41,7 @@ function alertNetworkNotSupported(ethereumNetworkID: string): void {
throw new Error(`Unsupported Ethereum network, ID: ${ethereumNetworkID}`);
}

export function useEthereumAccount(): UseEthereumReturnType {
export function useEthereumAccount(): UseEthereumAccountReturnType {
const { dlcBTCContract, getEthereumContracts } = useEthereumContext();

const { address, walletType, network } = useSelector((state: RootState) => state.account);
Expand Down
2 changes: 1 addition & 1 deletion src/app/hooks/use-ethereum-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EthereumError } from '@models/error-types';
import { EthereumNetwork } from '@models/ethereum-network';
import { Contract, ethers } from 'ethers';

export interface UseEthereumContractsReturnType {
interface UseEthereumContractsReturnType {
getEthereumContracts: (
ethereumSigner: ethers.providers.JsonRpcSigner,
ethereumNetwork: EthereumNetwork
Expand Down
2 changes: 1 addition & 1 deletion src/app/hooks/use-ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Logger } from 'ethers/lib/utils';

import { useEthereumContext } from './use-ethereum-context';

export interface UseEthereumReturnType {
interface UseEthereumReturnType {
getDLCBTCBalance: () => Promise<number | undefined>;
getLockedBTCBalance: () => Promise<number | undefined>;
getProtocolFee: () => Promise<number | undefined>;
Expand Down
4 changes: 2 additions & 2 deletions src/app/hooks/use-psbt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { vaultActions } from '@store/slices/vault/vault.actions';

import { useBitcoin } from './use-bitcoin';

export interface UseSignPSBTReturnType {
interface UsePSBTReturnType {
handleSignFundingTransaction: (btcAmount: number, vaultUUID: string) => Promise<void>;
handleSignClosingTransaction: () => Promise<void>;
}

export function usePSBT(): UseSignPSBTReturnType {
export function usePSBT(): UsePSBTReturnType {
const dispatch = useDispatch();
const { signAndBroadcastFundingPSBT, signAndSendClosingPSBT, broadcastTransaction } =
useBitcoin();
Expand Down

0 comments on commit bd69126

Please sign in to comment.