From 70c7850344ebcf9bd05b5c2922583703f8193384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rard=20Dethier?= Date: Thu, 18 Apr 2024 08:57:41 +0200 Subject: [PATCH] feat: do not wait for finalization. logion-network/logion-internal#1222 --- src/ExtrinsicSubmissionResult.test.tsx | 16 +- src/ExtrinsicSubmitter.test.tsx | 20 +-- .../ExtrinsicSubmissionResult.test.tsx.snap | 44 ++--- src/common/PendingVaultTransferRequests.tsx | 2 +- src/common/RequestToCancel.tsx | 4 +- src/common/WalletGauge.tsx | 144 +++++++-------- .../__snapshots__/WalletGauge.test.tsx.snap | 168 +++++++++--------- .../vault/PendingVaultTransferRequests.tsx | 6 +- .../vault/VaultTransferRequestsHistory.tsx | 2 +- src/loc/AcknowledgeButton.tsx | 1 + src/loc/LocPublishButton.test.tsx | 4 +- src/loc/LocPublishButton.tsx | 2 +- src/loc/__snapshots__/LocItems.test.tsx.snap | 4 +- src/logion-chain/LogionChainContext.tsx | 14 +- src/logion-chain/__mocks__/LogionChainMock.ts | 18 +- src/logion-chain/__mocks__/SignatureMock.tsx | 8 +- 16 files changed, 227 insertions(+), 230 deletions(-) diff --git a/src/ExtrinsicSubmissionResult.test.tsx b/src/ExtrinsicSubmissionResult.test.tsx index 28deaa2e..e2c4daa4 100644 --- a/src/ExtrinsicSubmissionResult.test.tsx +++ b/src/ExtrinsicSubmissionResult.test.tsx @@ -13,23 +13,23 @@ test("No result, error", () => { expect(tree).toMatchSnapshot(); }); -test("Non-finalized result, error", () => { - const tree = render(); +test("In progress result, error", () => { + const tree = render(); expect(tree).toMatchSnapshot(); }); -test("Non-finalized result, no error", () => { - const tree = render(); +test("In progress result, no error", () => { + const tree = render(); expect(tree).toMatchSnapshot(); }); -test("Finalized result, no error", () => { - const tree = render(); +test("Done result, no error", () => { + const tree = render(); expect(tree).toMatchSnapshot(); }); -test("Finalized result, no error, custom message", () => { - const tree = render(); +test("Done result, no error, custom message", () => { + const tree = render(); expect(tree).toMatchSnapshot(); }); diff --git a/src/ExtrinsicSubmitter.test.tsx b/src/ExtrinsicSubmitter.test.tsx index 045f1967..4eac91ea 100644 --- a/src/ExtrinsicSubmitter.test.tsx +++ b/src/ExtrinsicSubmitter.test.tsx @@ -21,8 +21,8 @@ describe("ExtrinsicSubmitter", () => { />); expect(screen.getByRole('generic')).toBeEmptyDOMElement(); - expect(onSuccess).not.toBeCalled(); - expect(onError).not.toBeCalled(); + expect(onSuccess).not.toHaveBeenCalled(); + expect(onError).not.toHaveBeenCalled(); }); it("is initially showing submitting", async () => { @@ -39,8 +39,8 @@ describe("ExtrinsicSubmitter", () => { />); await waitFor(() => expectSubmitting()); - expect(onSuccess).not.toBeCalled(); - expect(onError).not.toBeCalled(); + expect(onSuccess).not.toHaveBeenCalled(); + expect(onError).not.toHaveBeenCalled(); }); it("shows error and calls onError", async () => { @@ -57,8 +57,8 @@ describe("ExtrinsicSubmitter", () => { />); await waitFor(() => expect(screen.getByText("Submission failed: error")).toBeInTheDocument()); - expect(onSuccess).not.toBeCalled(); - expect(onError).toBeCalled(); + expect(onSuccess).not.toHaveBeenCalled(); + expect(onError).toHaveBeenCalled(); }); it("shows progress", async () => { @@ -75,8 +75,8 @@ describe("ExtrinsicSubmitter", () => { />); await waitFor(() => expect(screen.getByText("Current status: undefined")).toBeInTheDocument()); - expect(onSuccess).not.toBeCalled(); - expect(onError).not.toBeCalled(); + expect(onSuccess).not.toHaveBeenCalled(); + expect(onError).not.toHaveBeenCalled(); }); it("shows success and calls onSuccess", async () => { @@ -93,8 +93,8 @@ describe("ExtrinsicSubmitter", () => { />); await waitFor(() => expect(screen.getByText("Submission successful.")).toBeInTheDocument()); - expect(onSuccess).toBeCalledWith("extrinsicId"); - expect(onError).not.toBeCalled(); + expect(onSuccess).toHaveBeenCalledWith("extrinsicId"); + expect(onError).not.toHaveBeenCalled(); }); }); diff --git a/src/__snapshots__/ExtrinsicSubmissionResult.test.tsx.snap b/src/__snapshots__/ExtrinsicSubmissionResult.test.tsx.snap index e8abdfd6..e41eb1c3 100644 --- a/src/__snapshots__/ExtrinsicSubmissionResult.test.tsx.snap +++ b/src/__snapshots__/ExtrinsicSubmissionResult.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Finalized result, no error 1`] = ` +exports[`Done result, no error 1`] = `
@@ -20,7 +20,7 @@ exports[`Finalized result, no error 1`] = `
`; -exports[`Finalized result, no error, custom message 1`] = ` +exports[`Done result, no error, custom message 1`] = `
@@ -38,7 +38,7 @@ exports[`Finalized result, no error, custom message 1`] = `
`; -exports[`No result, error 1`] = ` +exports[`In progress result, error 1`] = `
@@ -58,45 +58,50 @@ exports[`No result, error 1`] = `
`; -exports[`No result, error, custom message 1`] = ` +exports[`In progress result, no error 1`] = `
- Error +
+

+ Current status: Ready +

`; -exports[`No result, no error 1`] = ` +exports[`No result, error 1`] = `

- Submitting... + Submission failed: error

`; -exports[`Non-finalized result, error 1`] = ` +exports[`No result, error, custom message 1`] = `
@@ -109,14 +114,12 @@ exports[`Non-finalized result, error 1`] = ` } } > -

- Submission failed: error -

+ Error
`; -exports[`Non-finalized result, no error 1`] = ` +exports[`No result, no error 1`] = `
@@ -129,11 +132,8 @@ exports[`Non-finalized result, no error 1`] = ` } } > -

- Current status: Ready + Submitting...

diff --git a/src/common/PendingVaultTransferRequests.tsx b/src/common/PendingVaultTransferRequests.tsx index 38deeedf..ea69a419 100644 --- a/src/common/PendingVaultTransferRequests.tsx +++ b/src/common/PendingVaultTransferRequests.tsx @@ -71,7 +71,7 @@ export default function PendingVaultTransferRequests() { }, ]} data={ pendingRequests } - renderEmpty={ () => No pending vault-out transfers } + renderEmpty={ () => No pending vault withdrawals } /> -

Cancel vault-out transfer

+

Cancel vault withdrawal

-

This will cancel the vault-out transfer. Your Legal Officer will be notified.

+

This will cancel the vault withdrawal. Your Legal Officer will be notified.

diff --git a/src/common/WalletGauge.tsx b/src/common/WalletGauge.tsx index 6d57671e..945ecfca 100644 --- a/src/common/WalletGauge.tsx +++ b/src/common/WalletGauge.tsx @@ -1,5 +1,5 @@ -import { useState, useCallback, useMemo, useEffect } from 'react'; -import { Form, Spinner, InputGroup, DropdownButton, Dropdown } from 'react-bootstrap'; +import { useState, useCallback, useMemo } from 'react'; +import { Form, InputGroup, DropdownButton, Dropdown } from 'react-bootstrap'; import { BalanceState } from '@logion/client'; import { Numbers, CoinBalance, Lgnt, ValidAccountId } from '@logion/node-api'; @@ -10,7 +10,7 @@ import Button from './Button'; import Icon from './Icon'; import Dialog from './Dialog'; import FormGroup from './FormGroup'; -import { ExpectNewTransactionStatus, useCommonContext } from './CommonContext'; +import { useCommonContext } from './CommonContext'; import Alert from './Alert'; import './WalletGauge.css'; @@ -40,12 +40,13 @@ const HIDDEN_DIALOG: TransferDialogState = { export default function WalletGauge(props: Props) { const { accounts, signer, client, submitCall, extrinsicSubmissionState, clearSubmissionState } = useLogionChain(); - const { colorTheme, mutateBalanceState, expectNewTransaction, expectNewTransactionState, stopExpectNewTransaction } = useCommonContext(); + const { colorTheme, mutateBalanceState } = useCommonContext(); const [ destination, setDestination ] = useState(""); const [ amount, setAmount ] = useState(""); const [ unit, setUnit ] = useState(Numbers.NONE); const [ transferDialogState, setTransferDialogState ] = useState(HIDDEN_DIALOG); const { vaultAccount, sendButton } = props; + const [ done, setDone ] = useState(false); const transfer = useMemo(() => { return async (callback: CallCallback) => { @@ -57,9 +58,9 @@ export default function WalletGauge(props: Props) { signer: signer! }); }); - expectNewTransaction(); + setDone(true); }; - }, [ amount, destination, unit, mutateBalanceState, signer, expectNewTransaction ]); + }, [ amount, destination, unit, mutateBalanceState, signer ]); const sendCallback = useCallback(async () => { try { @@ -75,15 +76,9 @@ export default function WalletGauge(props: Props) { const closeCallback = useCallback(() => { clearFormCallback(); - stopExpectNewTransaction(); clearSubmissionState(); - }, [ clearFormCallback, stopExpectNewTransaction, clearSubmissionState ]); - - useEffect(() => { - if(expectNewTransactionState.status === ExpectNewTransactionStatus.DONE) { - closeCallback(); - } - }, [ expectNewTransactionState, closeCallback ]); + setDone(false); + }, [ clearFormCallback, clearSubmissionState ]); if(!client) { return null; @@ -148,76 +143,71 @@ export default function WalletGauge(props: Props) { buttonText: "Send", buttonVariant: 'polkadot', callback: sendCallback, - disabled: !extrinsicSubmissionState.canSubmit() || !client.isValidAddress(destination) || isNaN(Number(amount)) || Number(amount) === 0 || destination === accounts!.current!.accountId.address + disabled: done || !extrinsicSubmissionState.canSubmit() || !client.isValidAddress(destination) || isNaN(Number(amount)) || Number(amount) === 0 || destination === accounts!.current!.accountId.address } ] } size="lg" >

{ transferDialogState.title }

- { - expectNewTransactionState.status === ExpectNewTransactionStatus.IDLE && - <> - { transferDialogState.destination && - setDestination(value.target.value) } - /> } - colors={ colorTheme.dialog } - /> - } - - setAmount(value.target.value) } - /> - { - [ - Numbers.NONE, - Numbers.MILLI, - Numbers.MICRO, - Numbers.NANO, - Numbers.PICO, - Numbers.FEMTO, - Numbers.ATTO - ].map(unit => setUnit(unit) }>{ `${ unit.symbol }${ Lgnt.CODE }` }) - } - - Please enter a valid amount. - - - } - colors={ colorTheme.dialog } - /> - - + { transferDialogState.destination && + setDestination(value.target.value) } + /> } + colors={ colorTheme.dialog } + /> } + + setAmount(value.target.value) } + /> + { + [ + Numbers.NONE, + Numbers.MILLI, + Numbers.MICRO, + Numbers.NANO, + Numbers.PICO, + Numbers.FEMTO, + Numbers.ATTO + ].map(unit => setUnit(unit) }>{ `${ unit.symbol }${ Lgnt.CODE }` }) + } + + Please enter a valid amount. + + + } + colors={ colorTheme.dialog } + /> + { - expectNewTransactionState.status === ExpectNewTransactionStatus.WAITING_NEW_TRANSACTION && - - -

Transfer successful, waiting for the transaction to be finalized.

-

Note that this may take up to 30 seconds. If you want to proceed, you can safely - click on close but your transaction may not show up yet.

+ done && + + It may take some time (up to 1 minute) before the transaction actually shows up + in your history. } diff --git a/src/common/__snapshots__/WalletGauge.test.tsx.snap b/src/common/__snapshots__/WalletGauge.test.tsx.snap index c58727e1..60bb23f8 100644 --- a/src/common/__snapshots__/WalletGauge.test.tsx.snap +++ b/src/common/__snapshots__/WalletGauge.test.tsx.snap @@ -108,101 +108,99 @@ exports[`WalletGauge renders 1`] = `

- - + } + id="destination" + label="Destination" + /> + - } - id="destination" - label="Destination" - /> - - - - - LGNT - - - mLGNT - - - µLGNT - - - nLGNT - - - pLGNT - - - fLGNT - - - aLGNT - - - + - Please enter a valid amount. - - - } - id="amount" - label="Amount" - noFeedback={true} - /> - - + mLGNT + + + µLGNT + + + nLGNT + + + pLGNT + + + fLGNT + + + aLGNT + + + + Please enter a valid amount. + + + } + id="amount" + label="Amount" + noFeedback={true} + /> + `; diff --git a/src/legal-officer/vault/PendingVaultTransferRequests.tsx b/src/legal-officer/vault/PendingVaultTransferRequests.tsx index 852e26cd..4a0544e6 100644 --- a/src/legal-officer/vault/PendingVaultTransferRequests.tsx +++ b/src/legal-officer/vault/PendingVaultTransferRequests.tsx @@ -155,7 +155,7 @@ export default function PendingVaultTransferRequests() { }, ]} data={ pendingVaultTransferRequests } - renderEmpty={ () => No pending vault-out transfers } + renderEmpty={ () => No pending vault withdrawals } /> -

Accepting vault-out transfer

+

Accepting vault withdrawal

You are about to accept and sign a transfer authorization from the user's Vault.

@@ -236,7 +236,7 @@ export default function PendingVaultTransferRequests() { ]} size="lg" > -

Reject vault-out transfer

+

Reject vault withdrawal

No pending vault-out transfers } + renderEmpty={ () => No pending vault withdrawals } /> ); diff --git a/src/loc/AcknowledgeButton.tsx b/src/loc/AcknowledgeButton.tsx index 241339e7..247fbb7e 100644 --- a/src/loc/AcknowledgeButton.tsx +++ b/src/loc/AcknowledgeButton.tsx @@ -120,6 +120,7 @@ export default function AcknowledgeButton(props: Props) { diff --git a/src/loc/LocPublishButton.test.tsx b/src/loc/LocPublishButton.test.tsx index 5b400978..cc65b350 100644 --- a/src/loc/LocPublishButton.test.tsx +++ b/src/loc/LocPublishButton.test.tsx @@ -21,7 +21,7 @@ describe("LocPublishButton", () => { const locItem = new MetadataItem( { type: "Data", - status: "DRAFT", + status: "REVIEW_ACCEPTED", submitter: TEST_WALLET_USER, timestamp: null, newItem: false, @@ -61,7 +61,7 @@ describe("LocPublishButton", () => { const locItem = new MetadataItem( { type: "Data", - status: "DRAFT", + status: "REVIEW_ACCEPTED", submitter: TEST_WALLET_USER, timestamp: null, newItem: false, diff --git a/src/loc/LocPublishButton.tsx b/src/loc/LocPublishButton.tsx index 2b18ed0a..54891420 100644 --- a/src/loc/LocPublishButton.tsx +++ b/src/loc/LocPublishButton.tsx @@ -34,7 +34,7 @@ export default function LocPublishButton(props: PublishProps) { }, [ submitCall, call ]); useEffect(() => { - if(fees === undefined) { + if(fees === undefined && props.locItem.status === "REVIEW_ACCEPTED") { setFees(null); (async function() { setFees(await props.feesEstimator()); diff --git a/src/loc/__snapshots__/LocItems.test.tsx.snap b/src/loc/__snapshots__/LocItems.test.tsx.snap index c0b1d023..a6812895 100644 --- a/src/loc/__snapshots__/LocItems.test.tsx.snap +++ b/src/loc/__snapshots__/LocItems.test.tsx.snap @@ -327,7 +327,7 @@ exports[`LOLocItems renders with single draft item 1`] = ` >