From cf2cc4f73779cccb315d8af96087c51a42091fbd Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Mon, 30 Oct 2023 14:04:44 +0100 Subject: [PATCH] Improve state transitioning during actions --- src/redux-state/thunks/island.ts | 17 +++++++++++++---- .../Transactions/TransactionProgress.tsx | 8 +++++--- src/shared/types/transaction.ts | 1 + src/shared/utils/transactions.ts | 1 + 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/redux-state/thunks/island.ts b/src/redux-state/thunks/island.ts index 55051e37a..1afcd3876 100644 --- a/src/redux-state/thunks/island.ts +++ b/src/redux-state/thunks/island.ts @@ -192,6 +192,15 @@ export const ensureAllowance = createDappAsyncThunk( } ) + // Update on "parent transaction" to make it possible to track them together in the UI + dispatch( + updateTransactionStatus({ + id, + status: receipt + ? TransactionProgressStatus.Approved + : TransactionProgressStatus.Failed, + }) + ) return !!receipt } @@ -209,7 +218,7 @@ export const stakeTaho = createDappAsyncThunk( }: { id: string; realmContractAddress: string; amount: bigint }, { dispatch, extra: { transactionService } } ) => { - const allowanceCorrect = await dispatch( + const { payload } = await dispatch( ensureAllowance({ id, tokenAddress: TAHO_ADDRESS, @@ -218,7 +227,7 @@ export const stakeTaho = createDappAsyncThunk( }) ) - if (!allowanceCorrect) { + if (!payload) { return false } @@ -252,7 +261,7 @@ export const unstakeTaho = createDappAsyncThunk( }, { dispatch, extra: { transactionService } } ) => { - const allowanceCorrect = await dispatch( + const { payload } = await dispatch( ensureAllowance({ id, tokenAddress: veTokenContractAddress, @@ -261,7 +270,7 @@ export const unstakeTaho = createDappAsyncThunk( }) ) - if (!allowanceCorrect) { + if (!payload) { return false } diff --git a/src/shared/components/Transactions/TransactionProgress.tsx b/src/shared/components/Transactions/TransactionProgress.tsx index da75e8ddf..bc81cd28c 100644 --- a/src/shared/components/Transactions/TransactionProgress.tsx +++ b/src/shared/components/Transactions/TransactionProgress.tsx @@ -46,10 +46,12 @@ const statusToElementProps = [ id: "signing", getLabel: (status: TransactionProgressStatus): string => { if (status === TransactionProgressStatus.Approving) return "Approving" + if (status === TransactionProgressStatus.Approved) return "Signed" - return status === TransactionProgressStatus.Idle - ? "Waiting for signature" - : "Signed" + if (status === TransactionProgressStatus.Signing) + return "Waiting for signature" + + return "Signed" }, getStatus: createGetStatusFunction(TransactionProgressStatus.Signing), }, diff --git a/src/shared/types/transaction.ts b/src/shared/types/transaction.ts index d2bd2aa49..248b75c65 100644 --- a/src/shared/types/transaction.ts +++ b/src/shared/types/transaction.ts @@ -3,6 +3,7 @@ import { ethers } from "ethers" export enum TransactionProgressStatus { Idle, Approving, + Approved, Signing, Sending, Done, diff --git a/src/shared/utils/transactions.ts b/src/shared/utils/transactions.ts index 85e974bc9..32fa6e004 100644 --- a/src/shared/utils/transactions.ts +++ b/src/shared/utils/transactions.ts @@ -3,6 +3,7 @@ import { TransactionProgressStatus } from "shared/types" // eslint-disable-next-line import/prefer-default-export export const isTransactionPending = (status: TransactionProgressStatus) => status === TransactionProgressStatus.Approving || + status === TransactionProgressStatus.Approved || status === TransactionProgressStatus.Signing || status === TransactionProgressStatus.Sending