Skip to content

Commit

Permalink
feat: refactor ethereum hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Mar 15, 2024
1 parent 7cbfe8a commit 217217e
Show file tree
Hide file tree
Showing 22 changed files with 489 additions and 518 deletions.
25 changes: 14 additions & 11 deletions src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@ import { AppLayout } from '@components/app.layout';
import { MyVaults } from '@pages/my-vaults/my-vaults';
import { ProofOfReservePage } from '@pages/proof-of-reserve/proof-of-reserve-page';
import { BalanceContextProvider } from '@providers/balance-context-provider';
import { EthereumObserverProvider } from '@providers/ethereum-observer-provider';

import { About } from './pages/about/about';
import { Dashboard } from './pages/dashboard/dashboard';
import { EthereumContextProvider } from './providers/blockchain-context-provider';
import { EthereumContextProvider } from './providers/ethereum-context-provider';
import { VaultContextProvider } from './providers/vault-context-provider';

export function App(): React.JSX.Element {
return (
<EthereumContextProvider>
<VaultContextProvider>
<BalanceContextProvider>
<AppLayout>
<Route path="/" element={<Dashboard />} />
<Route path="/my-vaults" element={<MyVaults />} />
<Route path="/how-it-works" element={<About />} />
<Route path="/proof-of-reserve" element={<ProofOfReservePage />} />
</AppLayout>
</BalanceContextProvider>
</VaultContextProvider>
<EthereumObserverProvider>
<VaultContextProvider>
<BalanceContextProvider>
<AppLayout>
<Route path="/" element={<Dashboard />} />
<Route path="/my-vaults" element={<MyVaults />} />
<Route path="/how-it-works" element={<About />} />
<Route path="/proof-of-reserve" element={<ProofOfReservePage />} />
</AppLayout>
</BalanceContextProvider>
</VaultContextProvider>
</EthereumObserverProvider>
</EthereumContextProvider>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { useDispatch } from 'react-redux';

import { Button, VStack, useToast } from '@chakra-ui/react';
import { VaultCard } from '@components/vault/vault-card';
import { UseBitcoinReturnType, useBitcoin } from '@hooks/use-bitcoin';
import { UseEthereumReturnType, useEthereum } from '@hooks/use-ethereum';
import { UseSignPSBTReturnType } from '@hooks/use-psbt';
import { useBitcoin } from '@hooks/use-bitcoin';
import { useEthereum } from '@hooks/use-ethereum';
import { usePSBT } from '@hooks/use-psbt';
import { useVaults } from '@hooks/use-vaults';
import { BitcoinError } from '@models/error-types';
import { Vault } from '@models/vault';
Expand All @@ -21,14 +21,10 @@ export function LockScreen({ currentStep }: LockScreenProps): React.JSX.Element
const toast = useToast();
const dispatch = useDispatch();

const bitcoinHandler = useBitcoin();
const ethereumHandler = useEthereum();

const { bitcoinPrice } = useBitcoin();
const { getProtocolFee } = useEthereum();
const { readyVaults } = useVaults();

const { bitcoinPrice } = bitcoinHandler;
const { getProtocolFee } = ethereumHandler;
const { handleSignFundingTransaction } = psbtHandler;
const { handleSignFundingTransaction } = usePSBT();

const [isSubmitting, setIsSubmitting] = useState(false);
const [protocolFeePercentage, setProtocolFeePercentage] = useState<number | undefined>(undefined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import { ModalComponentProps } from '@components/modals/components/modal-contain
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 copy';
import { Network } from '@models/network';
import { useEthereumAccount } from '@hooks/use-ethereum-account';
import { Network } from '@models/ethereum-network';

Check failure on line 10 in src/app/components/modals/select-wallet-modal/select-wallet-modal.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Module '"@models/ethereum-network"' has no exported member '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);

async function handleLogin(walletType: WalletType) {
if (!currentNetwork) throw new Error('No network selected');
await ethereumAccountHandler?.connectEthereumAccount(currentNetwork, walletType);
await ethereumAccountHandler?.connectEthereumAccount(walletType, currentNetwork);
setCurrentNetwork(undefined);
handleClose();
}
Expand Down Expand Up @@ -44,7 +45,7 @@ export function SelectWalletModal({ isOpen, handleClose }: ModalComponentProps):
<SelectWalletMenu
key={wallet.name}
wallet={wallet}
handleClick={() => handleLogin(WalletType.Metamask)}
handleClick={() => handleLogin(wallet.id)}
/>
))}
</VStack>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChevronDownIcon } from '@chakra-ui/icons';
import { HStack, Menu, MenuButton, MenuItem, MenuList, Text } from '@chakra-ui/react';
import { Network, ethereumNetworks } from '@models/network';
import { Network, ethereumNetworks } from '@models/ethereum-network';

Check failure on line 3 in src/app/components/select-network-button/select-network-button.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Module '"@models/ethereum-network"' has no exported member 'Network'.

interface SelectNetworkButtonProps {
handleClick: (network: Network) => void;
Expand Down
18 changes: 0 additions & 18 deletions src/app/hooks/use-blockchain-context.ts

This file was deleted.

8 changes: 4 additions & 4 deletions src/app/hooks/use-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
import { useSelector } from 'react-redux';

import { BitcoinNetwork, bitcoin, regtest, testnet } from '@models/bitcoin-network';
import { EthereumNetwork } from '@models/network';
import { EthereumNetworkID } from '@models/ethereum-network';
import { RootState } from '@store/index';

interface NetworkEndpoints {
Expand Down Expand Up @@ -57,23 +57,23 @@ export function useEndpoints(): NetworkEndpoints {
}

switch (network?.id) {
case EthereumNetwork.Sepolia:
case EthereumNetworkID.Sepolia:
return {
attestorAPIURLs,
ethereumExplorerAPIURL: 'https://sepolia.etherscan.io/tx/',
bitcoinExplorerAPIURL: 'http://devnet.dlc.link/electrs/tx/',
bitcoinBlockchainAPIURL: 'https://devnet.dlc.link/electrs',
bitcoinNetwork,
};
case EthereumNetwork.Goerli:
case EthereumNetworkID.Goerli:
return {
attestorAPIURLs,
ethereumExplorerAPIURL: 'https://goerli.etherscan.io/tx/',
bitcoinExplorerAPIURL: 'https://blockstream.info/testnet/tx/',
bitcoinBlockchainAPIURL: 'https://devnet.dlc.link/electrs',
bitcoinNetwork,
};
case EthereumNetwork.X1Testnet:
case EthereumNetworkID.X1Testnet:
return {
attestorAPIURLs,
ethereumExplorerAPIURL: 'https://www.oklink.com/x1-test/tx/',
Expand Down
214 changes: 0 additions & 214 deletions src/app/hooks/use-ethereum copy.ts

This file was deleted.

Loading

0 comments on commit 217217e

Please sign in to comment.