Skip to content

Commit

Permalink
feat: modify vault query
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Oct 2, 2024
1 parent 10dbed3 commit f073de6
Show file tree
Hide file tree
Showing 19 changed files with 343 additions and 279 deletions.
2 changes: 1 addition & 1 deletion config.devnet.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"appEnvironment": "devnet",
"coordinatorURL": "https://devnet.dlc.link/attestor-1",
"coordinatorURL": "http://localhost:8811",
"enabledEthereumNetworkIDs": ["421614", "84532", "11155111"],
"bitcoinNetwork": "regtest",
"bitcoinNetworkIndex": 1,
Expand Down
13 changes: 5 additions & 8 deletions src/app/components/account/components/account-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChevronDownIcon } from '@chakra-ui/icons';
import { HStack, Image, Menu, MenuButton, MenuItem, MenuList, Text } from '@chakra-ui/react';
import { HStack, Image, Menu, MenuButton, MenuItem, MenuList, Stack, Text } from '@chakra-ui/react';
import { truncateAddress } from 'dlc-btc-lib/utilities';
import { Connector } from 'wagmi';

Expand All @@ -19,13 +19,10 @@ export function AccountMenu({
<Menu variant={'account'}>
<MenuButton>
<HStack justifyContent={'space-evenly'}>
<Image
p={'2.5px'}
src={'./images/logos/xpr-logo.svg'}
alt={;'xrpl'}
boxSize={'35px'}
/>
<Text>{truncateAddress(address)}</Text>
<Stack bg={'white.01'} borderRadius={'full'} p={'5px'}>
<Image p={'2.5px'} src={'./images/logos/xpr-logo.svg'} alt={'xrpl'} boxSize={'25px'} />
</Stack>
<Text>{truncateAddress('rNHKCxi2FNFrj9jsz3aagJ64Si8v14Knx')}</Text>
<ChevronDownIcon boxSize={'35px'} color={'white'} />
</HStack>
</MenuButton>
Expand Down
6 changes: 5 additions & 1 deletion src/app/components/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export function Header(): React.JSX.Element {
const [showBanner, setShowBanner] = useState<boolean>(false);
const [isNetworkMenuOpen, setIsNetworkMenuOpen] = useState<boolean>(false);

console.log('isNetworkMenuOpen', isNetworkMenuOpen);

const handleTabClick = (route: string) => {
navigate(route);
};
Expand Down Expand Up @@ -48,7 +50,9 @@ export function Header(): React.JSX.Element {
<NavigationTabs activeTab={location.pathname} handleTabClick={handleTabClick} />
</HStack>
<HStack>
{/* <NetworkBox isMenuOpen={isNetworkMenuOpen} setIsMenuOpen={setIsNetworkMenuOpen} /> */}
{(0 + 1 === 2) === true && (
<NetworkBox isMenuOpen={isNetworkMenuOpen} setIsMenuOpen={setIsNetworkMenuOpen} />
)}
<Account />
</HStack>
</HeaderLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@ import { useDispatch, useSelector } from 'react-redux';
import { VStack, useToast } from '@chakra-ui/react';
import { VaultTransactionForm } from '@components/transaction-screen/transaction-screen.transaction-form/components/transaction-screen.transaction-form/transaction-screen.transaction-form';
import { Vault } from '@components/vault/vault';
import { useEthersSigner } from '@functions/configuration.functions';
import { getAndFormatVault } from '@functions/vault.functions';
import { BitcoinWalletContext } from '@providers/bitcoin-wallet-context-provider';
import { EthereumNetworkConfigurationContext } from '@providers/ethereum-network-configuration.provider';
import { ProofOfReserveContext } from '@providers/proof-of-reserve-context-provider';
import { VaultContext } from '@providers/vault-context-provider';
import { RootState } from '@store/index';
import { mintUnmintActions } from '@store/slices/mintunmint/mintunmint.actions';
import { vaultActions } from '@store/slices/vault/vault.actions';
import { withdraw } from 'dlc-btc-lib/ethereum-functions';
import { EthereumNetworkID } from 'dlc-btc-lib/models';
import { RippleHandler } from 'dlc-btc-lib';
import { shiftValue } from 'dlc-btc-lib/utilities';
import { useAccount } from 'wagmi';

interface BurnTokenTransactionFormProps {
isBitcoinWalletLoading: [boolean, string];
Expand All @@ -36,18 +29,12 @@ export function BurnTokenTransactionForm({

const { bitcoinWalletContextState } = useContext(BitcoinWalletContext);

const { ethereumNetworkConfiguration } = useContext(EthereumNetworkConfigurationContext);
const { bitcoinPrice, depositLimit } = useContext(ProofOfReserveContext);
const { allVaults } = useContext(VaultContext);

const { chainId } = useAccount();

const signer = useEthersSigner();

const { unmintStep } = useSelector((state: RootState) => state.mintunmint);
const [isSubmitting, setIsSubmitting] = useState(false);

const currentVault = allVaults.find(vault => vault.uuid === unmintStep[1]);
const currentVault = unmintStep[2];

async function handleButtonClick(withdrawAmount: number): Promise<void> {
if (!currentVault) return;
Expand All @@ -57,25 +44,22 @@ export function BurnTokenTransactionForm({
if (currentRisk === 'High') throw new Error('Risk Level is too high');
const formattedWithdrawAmount = BigInt(shiftValue(withdrawAmount));

await withdraw(
ethereumNetworkConfiguration.dlcManagerContract.connect(signer!),
currentVault.uuid,
formattedWithdrawAmount
);
const xrplHandler = RippleHandler.fromWhatever();
await xrplHandler.createCheck(formattedWithdrawAmount.toString(), currentVault.uuid);

const updatedVault = await getAndFormatVault(
currentVault.uuid,
ethereumNetworkConfiguration.dlcManagerContract
);
dispatch(
vaultActions.swapVault({
vaultUUID: currentVault.uuid,
updatedVault: updatedVault,
networkID: chainId?.toString() as EthereumNetworkID,
})
);
dispatch(mintUnmintActions.setUnmintStep([1, currentVault.uuid]));
setIsSubmitting(false);
// const updatedVault = await getAndFormatVault(
// currentVault.uuid,
// ethereumNetworkConfiguration.dlcManagerContract
// );
// dispatch(
// vaultActions.swapVault({
// vaultUUID: currentVault.uuid,
// updatedVault: updatedVault,
// networkID: chainId?.toString() as EthereumNetworkID,
// })
// );
// dispatch(mintUnmintActions.setUnmintStep([1, currentVault.uuid]));
// setIsSubmitting(false);
} catch (error) {
setIsSubmitting(false);
toast({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function DepositTransactionScreen({

console.log('allVaultsDEPOSIT', allVaults);

const currentVault = allVaults.find(vault => vault.uuid === mintStep[1]);
const currentVault = mintStep[2];

console.log('currentVaultDEPOSIT', currentVault);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { useContext, useState } from 'react';
import { useState } from 'react';

import { Button, VStack, useToast } from '@chakra-ui/react';
import { useEthersSigner } from '@functions/configuration.functions';
import { EthereumNetworkConfigurationContext } from '@providers/ethereum-network-configuration.provider';
import { RippleHandler } from 'dlc-btc-lib';
import { setupVault } from 'dlc-btc-lib/ethereum-functions';

import { SetupVaultScreenVaultGraphics } from './components/setup-vault-screen.vault-graphics';

export function SetupVaultScreen(): React.JSX.Element {
const toast = useToast();

const { ethereumNetworkConfiguration } = useContext(EthereumNetworkConfigurationContext);

const signer = useEthersSigner();

const [isSubmitting, setIsSubmitting] = useState(false);

async function handleSetup() {
Expand Down
13 changes: 10 additions & 3 deletions src/app/components/modals/components/modal-container.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';

import { SelectWalletModal } from '@components/modals/select-wallet-modal/select-wallet-modal';
Expand Down Expand Up @@ -27,6 +28,10 @@ export function ModalContainer(): React.JSX.Element {
dispatch(actionCreator());
};

useEffect(() => {
console.log(isSuccesfulFlowModalOpen);
}, [isSuccesfulFlowModalOpen]);

return (
<>
<SelectWalletModal
Expand All @@ -35,18 +40,20 @@ export function ModalContainer(): React.JSX.Element {
/>
<SuccessfulFlowModal
isOpen={isSuccesfulFlowModalOpen[0]}
flow={isSuccesfulFlowModalOpen[2] as 'mint' | 'burn'}
assetAmount={isSuccesfulFlowModalOpen[3]}
vault={isSuccesfulFlowModalOpen[1]!}
flow={isSuccesfulFlowModalOpen[3] as 'mint' | 'burn'}
assetAmount={isSuccesfulFlowModalOpen[4]}
handleClose={() =>
handleClosingModal(() =>
modalActions.toggleSuccessfulFlowModalVisibility({
vaultUUID: '',
vault: undefined,
flow: 'mint',
assetAmount: 0,
})
)
}
vaultUUID={isSuccesfulFlowModalOpen[1] ? isSuccesfulFlowModalOpen[1] : ''}
vaultUUID={isSuccesfulFlowModalOpen[2] ? isSuccesfulFlowModalOpen[2] : ''}
/>
<SelectBitcoinWalletModal
isOpen={isSelectBitcoinWalletModalOpen}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { useContext } from 'react';

import { HStack, Text, VStack } from '@chakra-ui/react';
import { TransactionFormNavigateButtonGroup } from '@components/transaction-screen/transaction-screen.transaction-form/components/transaction-screen.transaction-form/components/transaction-screen.transaction-form.navigate-button-group';
import { Vault } from '@components/vault/vault';
import { VaultContext } from '@providers/vault-context-provider';
import { Vault as VaultModel } from '@models/vault';

import { ModalComponentProps } from '../components/modal-container';
import { ModalVaultLayout } from '../components/modal.vault.layout';

interface SuccessfulFlowModalProps extends ModalComponentProps {
vaultUUID: string;
vault: VaultModel;
flow: 'mint' | 'burn';
assetAmount: number;
}
Expand All @@ -26,12 +25,11 @@ export function SuccessfulFlowModal({
isOpen,
handleClose,
vaultUUID,
vault,
flow,
assetAmount,
}: SuccessfulFlowModalProps): React.JSX.Element {
const { allVaults } = useContext(VaultContext);

const currentVault = allVaults.find(vault => vault.uuid === vaultUUID);
console.log('vaultUUID', vaultUUID);

return (
<ModalVaultLayout title={'Success!'} isOpen={isOpen} onClose={() => handleClose()}>
Expand All @@ -41,7 +39,7 @@ export function SuccessfulFlowModal({
{getModalText(flow, assetAmount)}
</Text>
</HStack>
<Vault vault={currentVault!} />
<Vault vault={vault!} />
<TransactionFormNavigateButtonGroup flow={flow} />
</VStack>
</ModalVaultLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function TransactionFormSubmitButtonGroup({
handleCancelButtonClick,
isSubmitting,
}: TransactionFormSubmitButtonGroupProps): React.JSX.Element {
console.log('userEthereumAddressRiskLevel', userEthereumAddressRiskLevel);
const formProperties = getFormProperties(flow, currentStep);
return (
<VStack w={'100%'} spacing={'15px'}>
Expand All @@ -63,11 +64,7 @@ export function TransactionFormSubmitButtonGroup({
bgColor={formProperties.color}
_hover={{ bgColor: 'accent.lightBlue.01' }}
type="submit"
isDisabled={
userEthereumAddressRiskLevel
? ['High', 'Severe'].includes(userEthereumAddressRiskLevel) || !canSubmit
: !canSubmit || isSubmitting
}
isDisabled={!canSubmit || isSubmitting}
>
{getButtonLabel(flow, currentStep, isSubmitting, bitcoinWalletContextState)}
</Button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useContext } from 'react';
import { useDispatch } from 'react-redux';
import { useNavigate } from 'react-router-dom';

import { Collapse, Stack, VStack } from '@chakra-ui/react';
import { VaultContext } from '@providers/vault-context-provider';
import { mintUnmintActions } from '@store/slices/mintunmint/mintunmint.actions';
import { VaultState } from 'dlc-btc-lib/models';

Expand Down Expand Up @@ -32,17 +34,20 @@ export function VaultDetails({
const navigate = useNavigate();
const dispatch = useDispatch();

const { allVaults } = useContext(VaultContext);
const vault = allVaults.find(vault => vault.uuid === vaultUUID);

function handleDepositClick() {
navigate('/mint-withdraw');
dispatch(mintUnmintActions.setMintStep([1, vaultUUID]));
dispatch(mintUnmintActions.setMintStep([1, vaultUUID, vault]));
}

function handleWithdrawClick() {
navigate('/mint-withdraw');
if (vaultTotalLockedValue === vaultTotalMintedValue) {
dispatch(mintUnmintActions.setUnmintStep([0, vaultUUID]));
dispatch(mintUnmintActions.setUnmintStep([0, vaultUUID, vault]));
} else {
dispatch(mintUnmintActions.setUnmintStep([1, vaultUUID]));
dispatch(mintUnmintActions.setUnmintStep([1, vaultUUID, vault]));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/components/vault/vault.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function Vault({ vault, variant }: VaultProps): React.JSX.Element {
function handleMainButtonClick() {
if (variant === 'select') {
const step = vault.valueLocked === vault.valueMinted ? 0 : 1;
dispatch(mintUnmintActions.setUnmintStep([step, vault.uuid]));
dispatch(mintUnmintActions.setUnmintStep([step, vault.uuid, vault]));
} else {
setIsVaultExpanded(!isVaultExpanded);
}
Expand Down
38 changes: 18 additions & 20 deletions src/app/functions/configuration.functions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { useMemo } from 'react';

import { supportedEthereumNetworks } from 'dlc-btc-lib/constants';
import { getEthereumContract, getProvider } from 'dlc-btc-lib/ethereum-functions';
import { EthereumDeploymentPlan, EthereumNetwork, EthereumNetworkID } from 'dlc-btc-lib/models';
import { Contract, providers } from 'ethers';
import { Contract } from 'ethers';
import { filter, fromPairs, includes, map, pipe } from 'ramda';
import { Account, Chain, Client, HttpTransport, Transport, http } from 'viem';
import { Config, createConfig, useConnectorClient } from 'wagmi';
import { Chain, HttpTransport, http } from 'viem';
import { Config, createConfig } from 'wagmi';
import { walletConnect } from 'wagmi/connectors';

import { SUPPORTED_VIEM_CHAINS } from '@shared/constants/ethereum.constants';
Expand Down Expand Up @@ -74,20 +72,20 @@ export function getWagmiConfiguration(ethereumNetworkIDs: EthereumNetworkID[]):
});
}

function clientToSigner(client: Client<Transport, Chain, Account>): providers.JsonRpcSigner {
const { account, chain, transport } = client;
// function clientToSigner(client: Client<Transport, Chain, Account>): providers.JsonRpcSigner {
// const { account, chain, transport } = client;

const network = {
chainId: chain.id,
name: chain.name,
ensAddress: chain.contracts?.ensRegistry?.address,
};
return new providers.Web3Provider(transport, network).getSigner(account.address);
}
// const network = {
// chainId: chain.id,
// name: chain.name,
// ensAddress: chain.contracts?.ensRegistry?.address,
// };
// return new providers.Web3Provider(transport, network).getSigner(account.address);
// }

export function useEthersSigner({ chainId }: { chainId?: number } = {}):
| providers.JsonRpcSigner
| undefined {
const { data: client } = useConnectorClient<Config>({ chainId });
return useMemo(() => (client ? clientToSigner(client) : undefined), [client]);
}
// export function useEthersSigner({ chainId }: { chainId?: number } = {}):
// | providers.JsonRpcSigner
// | undefined {
// const { data: client } = useConnectorClient<Config>({ chainId });
// return useMemo(() => (client ? clientToSigner(client) : undefined), [client]);
// }
Loading

0 comments on commit f073de6

Please sign in to comment.