Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into feat/adjust-points-page-to…
Browse files Browse the repository at this point in the history
…-mobile
  • Loading branch information
rozanagy committed Sep 26, 2024
2 parents 6057690 + ebbf01f commit c7706d7
Show file tree
Hide file tree
Showing 59 changed files with 1,549 additions and 1,237 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@ledgerhq/hw-transport-webusb": "^6.28.6",
"@netlify/functions": "^2.8.1",
"@reduxjs/toolkit": "^1.9.7",
"@tanstack/react-form": "^0.33.0",
"@tanstack/react-query": "^5.51.16",
"@trivago/prettier-plugin-sort-imports": "^4.2.1",
"@types/chrome": "^0.0.248",
Expand All @@ -43,7 +44,7 @@
"concurrently": "^8.2.2",
"d3": "^7.9.0",
"decimal.js": "^10.4.3",
"dlc-btc-lib": "^2.2.7",
"dlc-btc-lib": "2.2.7",
"dotenv": "^16.3.1",
"ethers": "5.7.2",
"formik": "^2.4.5",
Expand Down
6 changes: 3 additions & 3 deletions src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MyVaults } from '@pages/my-vaults/my-vaults';
import { PointsPage } from '@pages/points/points-page';
import { ProofOfReservePage } from '@pages/proof-of-reserve/proof-of-reserve-page';
import { BalanceContextProvider } from '@providers/balance-context-provider';
import { BlockchainHeightContextProvider } from '@providers/bitcoin-query-provider';
import { BitcoinTransactionConfirmationsProvider } from '@providers/bitcoin-query-provider';
import { BitcoinWalletContextProvider } from '@providers/bitcoin-wallet-context-provider';
import { EthereumNetworkConfigurationContextProvider } from '@providers/ethereum-network-configuration.provider';
import { EthereumObserverProvider } from '@providers/ethereum-observer-provider';
Expand All @@ -32,7 +32,7 @@ export function App(): React.JSX.Element {
<EthereumObserverProvider>
<BitcoinWalletContextProvider>
<VaultContextProvider>
<BlockchainHeightContextProvider>
<BitcoinTransactionConfirmationsProvider>
<BalanceContextProvider>
<ProofOfReserveContextProvider>
<AppLayout>
Expand All @@ -50,7 +50,7 @@ export function App(): React.JSX.Element {
</AppLayout>
</ProofOfReserveContextProvider>
</BalanceContextProvider>
</BlockchainHeightContextProvider>
</BitcoinTransactionConfirmationsProvider>
</VaultContextProvider>
</BitcoinWalletContextProvider>
</EthereumObserverProvider>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { useContext } from 'react';
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 { shiftValue } from 'dlc-btc-lib/utilities';
import { useAccount } from 'wagmi';

interface BurnTokenTransactionFormProps {
isBitcoinWalletLoading: [boolean, string];
userEthereumAddressRiskLevel: string;
fetchUserEthereumAddressRiskLevel: () => Promise<string>;
isUserEthereumAddressRiskLevelLoading: boolean;
}

export function BurnTokenTransactionForm({
isBitcoinWalletLoading,
userEthereumAddressRiskLevel,
fetchUserEthereumAddressRiskLevel,
isUserEthereumAddressRiskLevelLoading,
}: BurnTokenTransactionFormProps): React.JSX.Element {
const toast = useToast();
const dispatch = useDispatch();

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 currentVault = allVaults.find(vault => vault.uuid === unmintStep[1]);

async function handleButtonClick(withdrawAmount: number): Promise<void> {
if (!currentVault) return;

try {
const currentRisk = await fetchUserEthereumAddressRiskLevel();
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
);

await getAndFormatVault(currentVault.uuid, ethereumNetworkConfiguration.dlcManagerContract)
.then(vault => {
dispatch(
vaultActions.swapVault({
vaultUUID: currentVault.uuid,
updatedVault: vault,
networkID: chainId?.toString() as EthereumNetworkID,
})
);
})
.then(() => {
dispatch(mintUnmintActions.setUnmintStep([1, currentVault.uuid]));
});
} catch (error) {
toast({
title: 'Failed to sign Transaction',
description: error instanceof Error ? error.message : '',
status: 'error',
duration: 9000,
isClosable: true,
});
}
}

function handleCancel() {
dispatch(mintUnmintActions.setUnmintStep([0, '']));
}

return (
<VStack w={'45%'}>
<Vault vault={currentVault!} />
<VaultTransactionForm
vault={currentVault!}
type={'burn'}
currentBitcoinPrice={bitcoinPrice}
handleButtonClick={handleButtonClick}
depositLimit={depositLimit}
bitcoinWalletContextState={bitcoinWalletContextState}
isBitcoinWalletLoading={isBitcoinWalletLoading}
userEthereumAddressRiskLevel={userEthereumAddressRiskLevel}
isUserEthereumAddressRiskLevelLoading={isUserEthereumAddressRiskLevelLoading}
handleCancelButtonClick={handleCancel}
/>
</VStack>
);
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
import { useContext, useState } from 'react';
import { useContext } from 'react';
import { useDispatch, useSelector } from 'react-redux';

import { useToast } from '@chakra-ui/react';
import { BitcoinWalletContext } from '@providers/bitcoin-wallet-context-provider';
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 {
BitcoinWalletContext,
BitcoinWalletContextState,
} from '@providers/bitcoin-wallet-context-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 { modalActions } from '@store/slices/modal/modal.actions';

import { DepositBitcoinTransactionForm } from './components/transaction-form';

interface SignFundingTransactionScreenProps {
interface DepositTransactionScreenProps {
handleSignFundingTransaction: (vaultUUID: string, depositAmount: number) => Promise<void>;
isBitcoinWalletLoading: [boolean, string];
userEthereumAddressRiskLevel: string;
fetchUserEthereumAddressRiskLevel: () => Promise<string>;
isUserEthereumAddressRiskLevelLoading: boolean;
}

export function SignFundingTransactionScreen({
export function DepositTransactionScreen({
handleSignFundingTransaction,
isBitcoinWalletLoading,
userEthereumAddressRiskLevel,
fetchUserEthereumAddressRiskLevel,
isUserEthereumAddressRiskLevelLoading,
}: SignFundingTransactionScreenProps): React.JSX.Element {
}: DepositTransactionScreenProps): React.JSX.Element {
const toast = useToast();
const dispatch = useDispatch();

Expand All @@ -34,10 +37,6 @@ export function SignFundingTransactionScreen({
const { bitcoinPrice, depositLimit } = useContext(ProofOfReserveContext);
const { allVaults } = useContext(VaultContext);

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

const [isAttestorApprovePending, setIsAttestorApprovePending] = useState(false);

const { mintStep } = useSelector((state: RootState) => state.mintunmint);

const currentVault = allVaults.find(vault => vault.uuid === mintStep[1]);
Expand All @@ -46,14 +45,10 @@ export function SignFundingTransactionScreen({
if (!currentVault) return;

try {
setIsSubmitting(true);
const currentRisk = await fetchUserEthereumAddressRiskLevel();
if (currentRisk === 'High') throw new Error('Risk Level is too high');
await handleSignFundingTransaction(currentVault.uuid, depositAmount);
setIsAttestorApprovePending(true);
} catch (error: any) {
setIsSubmitting(false);
setIsAttestorApprovePending(false);
toast({
title: 'Failed to sign Deposit Transaction',
description: error.message,
Expand All @@ -73,20 +68,27 @@ export function SignFundingTransactionScreen({
dispatch(mintUnmintActions.setMintStep([0, '']));
}

async function handleButtonClick(assetAmount: number) {
bitcoinWalletContextState === BitcoinWalletContextState.READY
? await handleDeposit(assetAmount)
: handleConnect();
}

return (
<DepositBitcoinTransactionForm
vault={currentVault}
bitcoinWalletContextState={bitcoinWalletContextState}
isBitcoinWalletLoading={isBitcoinWalletLoading}
bitcoinPrice={bitcoinPrice}
isSubmitting={isSubmitting}
isAttestorApprovePending={isAttestorApprovePending}
userEthereumAddressRiskLevel={userEthereumAddressRiskLevel}
isUserEthereumAddressRiskLevelLoading={isUserEthereumAddressRiskLevelLoading}
depositLimit={depositLimit}
handleConnect={handleConnect}
handleDeposit={handleDeposit}
handleCancel={handleCancel}
/>
<VStack w={'45%'} spacing={'15px'}>
<Vault vault={currentVault!} />
<VaultTransactionForm
vault={currentVault!}
type={'deposit'}
currentBitcoinPrice={bitcoinPrice}
bitcoinWalletContextState={bitcoinWalletContextState}
isBitcoinWalletLoading={isBitcoinWalletLoading}
userEthereumAddressRiskLevel={userEthereumAddressRiskLevel}
isUserEthereumAddressRiskLevelLoading={isUserEthereumAddressRiskLevelLoading}
handleButtonClick={handleButtonClick}
handleCancelButtonClick={handleCancel}
depositLimit={depositLimit}
/>
</VStack>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export function MintUnmintLayout({ children }: MintUnmintLayoutProps): React.JSX
return (
<VStack
px={'15px'}
w={'930px'}
h={'625px'}
w={'68.5%'}
h={'825px'}
bg={'background.container.01'}
border={'1px solid'}
borderRadius={'md'}
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/mint-unmint/components/mint/mint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { usePSBT } from '@hooks/use-psbt';
import { useRisk } from '@hooks/use-risk';
import { RootState } from '@store/index';

import { DepositTransactionScreen } from '../deposit-transaction-screen/deposit-transaction-screen';
import { ProgressTimeline } from '../progress-timeline/progress-timeline';
import { SetupVaultScreen } from '../setup-vault-screen/setup-vault-screen';
import { SignFundingTransactionScreen } from '../sign-transaction-screen/sign-funding-transaction-screen';
import { TransactionSummary } from '../transaction-summary/transaction-summary';
import { Walkthrough } from '../walkthrough/walkthrough';
import { MintLayout } from './components/mint.layout';
Expand All @@ -29,7 +29,7 @@ export function Mint(): React.JSX.Element {
<Walkthrough flow={'mint'} currentStep={mintStep[0]} />
{[0].includes(mintStep[0]) && <SetupVaultScreen />}
{[1].includes(mintStep[0]) && (
<SignFundingTransactionScreen
<DepositTransactionScreen
handleSignFundingTransaction={handleSignFundingTransaction}
isBitcoinWalletLoading={isBitcoinWalletLoading}
userEthereumAddressRiskLevel={risk!}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import { HasChildren } from '@models/has-children';

export function RiskBoxLayout({ children }: HasChildren): React.JSX.Element {
return (
<VStack w={'100%'} alignItems={'flex-start'} gap={'0px'}>
<VStack
alignContent={'flex-start'}
p={'15px'}
bgColor={'none'}
border={'1px solid'}
borderColor={'white.03'}
borderRadius={'md'}
>
{children}
</VStack>
);
Expand Down
42 changes: 24 additions & 18 deletions src/app/components/mint-unmint/components/risk-box/risk-box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,38 @@ interface RiskBoxProps {
isRiskLoading: boolean;
}

export function RiskBox({ risk }: RiskBoxProps): React.JSX.Element {
export function RiskBox({ risk }: RiskBoxProps): React.JSX.Element | false {
if (!['High', 'Severe'].includes(risk)) return false;

return (
<RiskBoxLayout>
<HStack spacing={'5px'}>
<Text color={'accent.lightBlue.01'} fontSize={'md'} fontWeight={200}>
<HStack w={'100%'}>
<Text color={'accent.lightBlue.01'} fontSize={'sm'} fontWeight={200}>
Address Risk Level:
</Text>
<Text color={'error.01'} fontSize={'md'} fontWeight={800}>
{risk}
</Text>
</HStack>
<VStack gap={'0px'}>
<Text color={'white.01'} fontWeight={200}>
Potential suspicious activity detected, redemptions are temporarily suspended.
</Text>
<Text color={'white.01'}>
<Link
color={'accent.lightBlue.01'}
href="mailto:[email protected]"
isExternal
textDecoration={'underline'}
>
Get in touch
</Link>{' '}
with your DLC.Link representative to resolve this issue.
</Text>
<VStack>
<HStack w={'100%'}>
<Text color={'white.01'} fontSize={'small'} fontWeight={'bold'}>
Potential suspicious activity detected, redemptions are temporarily suspended.
</Text>
</HStack>
<HStack w={'100%'}>
<Text color={'white.01'} fontSize={'sm'}>
<Link
color={'accent.lightBlue.01'}
href="mailto:[email protected]"
isExternal
textDecoration={'underline'}
>
Get in touch
</Link>{' '}
with your DLC.Link representative to resolve this issue.
</Text>
</HStack>
</VStack>
</RiskBoxLayout>
);
Expand Down
Loading

0 comments on commit c7706d7

Please sign in to comment.