Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Unit tests in Wallet migration branch #988

Open
wants to merge 50 commits into
base: new-delegate-factory
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
29c4c2a
Add wagmi config and start replacing web3-react
hernandoagf Mar 4, 2025
ead5e44
Replace network param from web3-react hooks
hernandoagf Mar 5, 2025
b9bb625
Remove chain id and address imports from web3-react
hernandoagf Mar 5, 2025
629ddb0
Add wagmi cli and generate abis
hernandoagf Mar 5, 2025
3aa106f
Add wagmi CLI and and start implementing read hooks
hernandoagf Mar 5, 2025
ed060be
Replace DSR logic to use bigint
hernandoagf Mar 6, 2025
428b258
Replace remaining read contract calls for Viem read contracts
hernandoagf Mar 6, 2025
11f0211
Update some BigNumber references to big int
hernandoagf Mar 6, 2025
b81512b
Update first write hook to wagmi flow
hernandoagf Mar 6, 2025
61bbfd0
Update approve write hook to new flow
hernandoagf Mar 7, 2025
1048323
Update MKR deposit hook to new write flow
hernandoagf Mar 7, 2025
4648e8d
Update MKR withdraw hooks to new flow
hernandoagf Mar 7, 2025
90af873
Update ESM burn write hook to new flow
hernandoagf Mar 7, 2025
03465be
Migrate the ESM shutdown write hook to new flow
hernandoagf Mar 7, 2025
b4b44fd
Migrate delegate create write hook to new flow
hernandoagf Mar 7, 2025
09a28d4
Migrate executive vote hooks to new flow
hernandoagf Mar 7, 2025
9be0b77
Migrate poll creation hook to new flow
hernandoagf Mar 7, 2025
6b2cafe
Migrate delegate lock hook to new flow
hernandoagf Mar 10, 2025
1f09bd6
Migrate delegate free hook to new flow
hernandoagf Mar 10, 2025
4a00ce4
Update poll vote and gasless vote flows to use Viem
hernandoagf Mar 11, 2025
24fb0e6
Remove dethcrypto/eth-sdk packages and related code
hernandoagf Mar 11, 2025
f537ecc
Replace ethers references for viem
hernandoagf Mar 11, 2025
610b388
Update lockfile
hernandoagf Mar 11, 2025
26e8549
Remove remaining Ethers references
hernandoagf Mar 12, 2025
e24c0cf
Replace all bignumber references for bigint
hernandoagf Mar 12, 2025
5f916a1
Remove unused dependencies and code
hernandoagf Mar 13, 2025
9d24302
Fix issue when fetching logs
hernandoagf Mar 13, 2025
e7f5331
Update typescript to v5 and theme-ui to v0.16
hernandoagf Mar 13, 2025
fa2a2c8
Merge branch 'new-delegate-factory' into wallet-refactor
hernandoagf Mar 14, 2025
1215752
Fix big int formatting issues
hernandoagf Mar 14, 2025
0ffd12b
Remove unnecessary step in CI
hernandoagf Mar 14, 2025
61a3653
Fix wallet connection in e2e tests
hernandoagf Mar 14, 2025
da6192c
Fix wallet connection in e2e tests
hernandoagf Mar 14, 2025
36e576c
Fixes for e2e tests
hernandoagf Mar 14, 2025
d59b4e5
Merge branch 'new-delegate-factory' into wallet-refactor
hernandoagf Mar 14, 2025
c747d26
Handle 0n balance
adamgoth Mar 17, 2025
30a6fdc
Remove ethers peer dependency from defender relay client
hernandoagf Mar 17, 2025
85af6a0
Update file extensions
hernandoagf Mar 17, 2025
74e4745
Install Vitest packages
hernandoagf Mar 17, 2025
aa34188
Update Jest references to Vitest
hernandoagf Mar 17, 2025
ca85138
Fix tests
hernandoagf Mar 18, 2025
74e4e86
Fix remaining unit tests
hernandoagf Mar 18, 2025
e1f04d8
Add test:ci command
hernandoagf Mar 18, 2025
4c26f33
Add missing coverage package
hernandoagf Mar 18, 2025
ad1b8d2
Merge branch 'new-delegate-factory' into wallet-refactor
hernandoagf Mar 18, 2025
cee83c2
Remove new BigNumber references
hernandoagf Mar 18, 2025
d321973
Merge branch 'wallet-refactor' into replace-jest-for-vitest
hernandoagf Mar 18, 2025
fda4d90
Merge branch 'new-delegate-factory' into replace-jest-for-vitest
hernandoagf Mar 18, 2025
29241f5
Update mock function
hernandoagf Mar 18, 2025
1379b00
Merge branch 'new-delegate-factory' into replace-jest-for-vitest
hernandoagf Mar 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrate the ESM shutdown write hook to new flow
hernandoagf committed Mar 7, 2025
commit 03465bea2567a7d01271f09038531e7c18c4fbfc
28 changes: 19 additions & 9 deletions modules/esm/components/ShutdownModal.tsx
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ import { Flex, Button, Text, Grid, Close, Spinner } from 'theme-ui';
import { useState } from 'react';
import { formatValue } from 'lib/string';
import { Icon } from '@makerdao/dai-ui-icons';
import { TXMined } from 'modules/web3/types/transaction';
import { useEsmShutdown } from '../hooks/useEsmShutdown';
import EtherscanLink from 'modules/web3/components/EtherscanLink';
import { useNetwork } from 'modules/app/hooks/useNetwork';
@@ -23,8 +22,22 @@ const ModalContent = ({
thresholdAmount?: bigint;
}): React.ReactElement => {
const [step, setStep] = useState('default');
const [txHash, setTxHash] = useState<`0x${string}` | undefined>();

const network = useNetwork();
const { shutdown, tx } = useEsmShutdown();
const shutdown = useEsmShutdown({
onStart: (hash: `0x${string}`) => {
setTxHash(hash);
setStep('pending');
},
onSuccess: (hash: `0x${string}`) => {
setTxHash(hash);
close(); // TBD maybe show a separate "done" dialog,
},
onError: () => {
setStep('failed');
}
});

const close = () => {
setShowDialog(false);
@@ -47,13 +60,10 @@ const ModalContent = ({
Cancel
</Button>
<Button
disabled={shutdown.isLoading || !shutdown.prepared}
onClick={() => {
shutdown({
initialized: () => setStep('signing'),
pending: () => setStep('pending'),
mined: () => close(), // TBD maybe show a separate "done" dialog,
error: () => setStep('failed')
});
setStep('signing');
shutdown.execute();
}}
variant="outline"
sx={{ color: 'onNotice', borderColor: 'notice' }}
@@ -104,7 +114,7 @@ const ModalContent = ({
Shutdown will update once the transaction has been confirmed.
</Text>

<EtherscanLink hash={(tx as TXMined).hash} type="transaction" network={network} />
{txHash && <EtherscanLink hash={txHash} type="transaction" network={network} />}

<Button
onClick={close}
85 changes: 25 additions & 60 deletions modules/esm/hooks/useEsmShutdown.ts
Original file line number Diff line number Diff line change
@@ -6,64 +6,29 @@ SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { Dispatch, SetStateAction, useState } from 'react';
import useTransactionStore, {
transactionsSelectors,
transactionsApi
} from 'modules/web3/stores/transactions';
import { shallow } from 'zustand/shallow';
import { Transaction } from 'modules/web3/types/transaction';
import { useContracts } from 'modules/web3/hooks/useContracts';
import { useAccount } from 'modules/app/hooks/useAccount';
import { useWeb3 } from 'modules/web3/hooks/useWeb3';
import { sendTransaction } from 'modules/web3/helpers/sendTransaction';

type ShutdownResponse = {
txId: string | null;
setTxId: Dispatch<SetStateAction<string | null>>;
shutdown: (callbacks?: Record<string, (id?: string) => void>) => void;
tx: Transaction | null;
};

export const useEsmShutdown = (): ShutdownResponse => {
const [txId, setTxId] = useState<string | null>(null);

const { account } = useAccount();
const { provider } = useWeb3();
const { esm } = useContracts();

const [track, tx] = useTransactionStore(
state => [state.track, txId ? transactionsSelectors.getTransaction(state, txId) : null],
shallow
);

const shutdown = callbacks => {
if (!account || !provider) {
return;
}

const shutdownTxCreator = async () => {
const populatedTransaction = await esm.populateTransaction.fire();
return sendTransaction(populatedTransaction, provider, account);
};

const txId = track(shutdownTxCreator, account, 'Shutting Down Dai Credit System', {
initialized: () => {
if (typeof callbacks?.initialized === 'function') callbacks.initialized();
},
pending: () => {
if (typeof callbacks?.pending === 'function') callbacks.pending();
},
mined: txId => {
transactionsApi.getState().setMessage(txId, 'Dai Credit System has been Shutdown');
if (typeof callbacks?.mined === 'function') callbacks.mined();
},
error: () => {
if (typeof callbacks?.error === 'function') callbacks.error();
}
});
setTxId(txId);
};

return { txId, setTxId, shutdown, tx };
import { useChainId } from 'wagmi';
import { useWriteContractFlow } from 'modules/web3/hooks/useWriteContractFlow';
import { WriteHook, WriteHookParams } from 'modules/web3/types/hooks';
import { esmAbi, esmAddress } from 'modules/contracts/generated';

export const useEsmShutdown = ({
gas,
enabled: paramEnabled = true,
onSuccess,
onError,
onStart
}: WriteHookParams): WriteHook => {
const chainId = useChainId();

return useWriteContractFlow({
address: esmAddress[chainId],
abi: esmAbi,
functionName: 'fire',
chainId,
enabled: paramEnabled,
gas,
onSuccess,
onError,
onStart
});
};