From 273614af457d4ec3065b20b677f66433efaf5070 Mon Sep 17 00:00:00 2001 From: Norton Andreev Date: Wed, 27 Nov 2024 14:29:51 +0200 Subject: [PATCH] web-wallet: Reword "Withdraw" to "Claim" Rewards Resolves #3076 --- web-wallet/CHANGELOG.md | 4 +++- .../ContractOperations.svelte | 3 ++- .../src/lib/components/Stake/Stake.svelte | 13 +++++++++---- .../__tests__/ContractOperations.spec.js | 4 ++-- .../src/lib/components/__tests__/Stake.spec.js | 14 +++++++------- .../ContractOperations.spec.js.snap | 4 ++-- .../StakeContract/StakeContract.svelte | 18 +++++++++--------- .../src/lib/contracts/contract-descriptors.js | 4 ++-- web-wallet/src/lib/contracts/contracts.d.ts | 2 +- .../lib/stores/__tests__/walletStore.spec.js | 6 +++--- web-wallet/src/lib/stores/stores.d.ts | 2 +- web-wallet/src/lib/stores/walletStore.js | 6 +++--- .../__tests__/__snapshots__/page.spec.js.snap | 4 ++-- 13 files changed, 46 insertions(+), 38 deletions(-) diff --git a/web-wallet/CHANGELOG.md b/web-wallet/CHANGELOG.md index f1837ced15..8136e8dfc2 100644 --- a/web-wallet/CHANGELOG.md +++ b/web-wallet/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Update Transactions list design [#1922] +- Reword "Withdraw Rewards" operation to "Claim Rewards" [#3076] ### Removed @@ -48,7 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Added gas settings validation on Unstake / Widthdraw Rewards flows [#2000] +- Added gas settings validation on Unstake / Withdraw Rewards flows [#2000] - Add temporary link to the block explorer on the dashboard [#2882] - Add Staking-Related Functionality Utilizing w3sper [#3006] - Add minimum stake amount supplied by w3sper instead of using an env var [#3010] @@ -400,6 +401,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#3069]: https://github.com/dusk-network/rusk/issues/3069 [#3071]: https://github.com/dusk-network/rusk/issues/3071 [#3073]: https://github.com/dusk-network/rusk/issues/3073 +[#3076]: https://github.com/dusk-network/rusk/issues/3076 diff --git a/web-wallet/src/lib/components/ContractOperations/ContractOperations.svelte b/web-wallet/src/lib/components/ContractOperations/ContractOperations.svelte index 200f782889..fbf30e6dc6 100644 --- a/web-wallet/src/lib/components/ContractOperations/ContractOperations.svelte +++ b/web-wallet/src/lib/components/ContractOperations/ContractOperations.svelte @@ -8,6 +8,7 @@ mdiArrowUpBoldBoxOutline, mdiDatabaseArrowDownOutline, mdiDatabaseOutline, + mdiGiftOpenOutline, mdiHelpCircleOutline, } from "@mdi/js"; @@ -21,11 +22,11 @@ /** @type {Record} */ const operationIcons = { + "claim-rewards": mdiGiftOpenOutline, receive: mdiArrowDownBoldBoxOutline, send: mdiArrowUpBoldBoxOutline, stake: mdiDatabaseOutline, unstake: mdiDatabaseArrowDownOutline, - "withdraw-rewards": mdiDatabaseArrowDownOutline, }; diff --git a/web-wallet/src/lib/components/Stake/Stake.svelte b/web-wallet/src/lib/components/Stake/Stake.svelte index 6b844680a4..25847b6d6e 100644 --- a/web-wallet/src/lib/components/Stake/Stake.svelte +++ b/web-wallet/src/lib/components/Stake/Stake.svelte @@ -7,6 +7,7 @@ mdiAlertOutline, mdiDatabaseArrowDownOutline, mdiDatabaseOutline, + mdiGiftOpenOutline, } from "@mdi/js"; import { DOCUMENTATION_LINKS, MESSAGES } from "$lib/constants"; @@ -83,24 +84,24 @@ */ let stakeAmount = luxToDusk( { + "claim-rewards": rewards, stake: minAllowedStake, unstake: staked, - "withdraw-rewards": rewards, }[flow] ); /** @type {Record} */ const confirmLabels = { + "claim-rewards": "Claim", stake: "Stake", unstake: "Unstake", - "withdraw-rewards": "Withdraw", }; /** @type {Record} */ const overviewLabels = { + "claim-rewards": "Rewards Amount", stake: "Amount", unstake: "Unstake Amount", - "withdraw-rewards": "Withdraw Rewards", }; const steps = getStepperSteps(); @@ -323,7 +324,11 @@ disabled: flow === "stake" ? stakeAmount === 0 : !isGasValid, icon: { path: - flow === "stake" ? mdiDatabaseOutline : mdiDatabaseArrowDownOutline, + flow === "unstake" + ? mdiDatabaseArrowDownOutline + : flow === "stake" + ? mdiDatabaseOutline + : mdiGiftOpenOutline, position: "before", }, label: confirmLabels[flow], diff --git a/web-wallet/src/lib/components/__tests__/ContractOperations.spec.js b/web-wallet/src/lib/components/__tests__/ContractOperations.spec.js index 3eb707ff91..b9dd523174 100644 --- a/web-wallet/src/lib/components/__tests__/ContractOperations.spec.js +++ b/web-wallet/src/lib/components/__tests__/ContractOperations.spec.js @@ -32,8 +32,8 @@ describe("ContractOperations", () => { }, { disabled: false, - id: "withdraw-rewards", - label: "withdraw rewards", + id: "claim-rewards", + label: "claim rewards", primary: false, }, ], diff --git a/web-wallet/src/lib/components/__tests__/Stake.spec.js b/web-wallet/src/lib/components/__tests__/Stake.spec.js index a4e0226bd0..fe2f3db453 100644 --- a/web-wallet/src/lib/components/__tests__/Stake.spec.js +++ b/web-wallet/src/lib/components/__tests__/Stake.spec.js @@ -349,7 +349,7 @@ describe("Stake", () => { }); }); - describe("Withdraw Rewards operation", () => { + describe("Claim Rewards operation", () => { const expectedExplorerLink = `/explorer/transactions/transaction?id=${lastTxId}`; beforeAll(() => { @@ -360,15 +360,15 @@ describe("Stake", () => { vi.useRealTimers(); }); - it("should perform a withdraw rewards, give a success message and supply a link to see the transaction in the explorer", async () => { + it("should perform a claim rewards, give a success message and supply a link to see the transaction in the explorer", async () => { /** @type {import("svelte").ComponentProps} */ - const props = { ...baseProps, flow: "withdraw-rewards" }; + const props = { ...baseProps, flow: "claim-rewards" }; const { getByRole, getByText } = render(Stake, props); await vi.advanceTimersToNextTimerAsync(); - await fireEvent.click(getByRole("button", { name: "Withdraw" })); + await fireEvent.click(getByRole("button", { name: "Claim" })); expect(baseProps.execute).toHaveBeenCalledTimes(1); expect(baseProps.execute).toHaveBeenCalledWith( @@ -387,7 +387,7 @@ describe("Stake", () => { /** @type {import("svelte").ComponentProps} */ const props = { ...baseProps, - flow: "unstake", + flow: "claim-rewards", gasSettings: { gasLimit: 29000000090n, gasPrice: 1n }, }; @@ -395,9 +395,9 @@ describe("Stake", () => { await vi.advanceTimersToNextTimerAsync(); - const unstakeButton = getByRole("button", { name: "Unstake" }); + const claimButton = getByRole("button", { name: "Claim" }); - expect(unstakeButton).toBeDisabled(); + expect(claimButton).toBeDisabled(); }); }); }); diff --git a/web-wallet/src/lib/components/__tests__/__snapshots__/ContractOperations.spec.js.snap b/web-wallet/src/lib/components/__tests__/__snapshots__/ContractOperations.spec.js.snap index 1e0e0aa3c2..426e6c30c6 100644 --- a/web-wallet/src/lib/components/__tests__/__snapshots__/ContractOperations.spec.js.snap +++ b/web-wallet/src/lib/components/__tests__/__snapshots__/ContractOperations.spec.js.snap @@ -158,7 +158,7 @@ exports[`ContractOperations > should render the \`ContractOperations\` component viewBox="0 0 24 24" > @@ -166,7 +166,7 @@ exports[`ContractOperations > should render the \`ContractOperations\` component - withdraw rewards + claim rewards diff --git a/web-wallet/src/lib/containers/StakeContract/StakeContract.svelte b/web-wallet/src/lib/containers/StakeContract/StakeContract.svelte index 10d2312da2..9b7c7d999a 100644 --- a/web-wallet/src/lib/containers/StakeContract/StakeContract.svelte +++ b/web-wallet/src/lib/containers/StakeContract/StakeContract.svelte @@ -58,13 +58,20 @@ /** @type {Record boolean>} */ const disablingConditions = { + "claim-rewards": (info) => info.reward <= 0n, stake: (info) => !!info.amount, unstake: (info) => !info.amount || info.amount.total === 0n, - "withdraw-rewards": (info) => info.reward <= 0n, }; /** @type {Record Promise>} */ const executeOperations = { + "claim-rewards": (gasPrice, gasLimit) => + walletStore + .claimRewards( + $walletStore.stakeInfo.reward, + new Gas({ limit: gasLimit, price: gasPrice }) + ) + .then(getKey("hash")), stake: (amount, gasPrice, gasLimit) => walletStore .stake(amount, new Gas({ limit: gasLimit, price: gasPrice })) @@ -73,13 +80,6 @@ walletStore .unstake(new Gas({ limit: gasLimit, price: gasPrice })) .then(getKey("hash")), - "withdraw-rewards": (gasPrice, gasLimit) => - walletStore - .withdrawReward( - $walletStore.stakeInfo.reward, - new Gas({ limit: gasLimit, price: gasPrice }) - ) - .then(getKey("hash")), }; /** @type {(operations: ContractOperation[]) => ContractOperation[]} */ @@ -87,7 +87,7 @@ /** @type {(operationId: string) => operationId is StakeType} */ const isStakeOperation = (operationId) => - ["stake", "unstake", "withdraw-rewards"].includes(operationId); + ["stake", "unstake", "claim-rewards"].includes(operationId); /** * We want to update the disabled status ourselves only diff --git a/web-wallet/src/lib/contracts/contract-descriptors.js b/web-wallet/src/lib/contracts/contract-descriptors.js index 5f4b16a980..1d231e0fba 100644 --- a/web-wallet/src/lib/contracts/contract-descriptors.js +++ b/web-wallet/src/lib/contracts/contract-descriptors.js @@ -37,8 +37,8 @@ export default [ }, { disabled: false, - id: "withdraw-rewards", - label: "withdraw rewards", + id: "claim-rewards", + label: "claim rewards", primary: false, }, ], diff --git a/web-wallet/src/lib/contracts/contracts.d.ts b/web-wallet/src/lib/contracts/contracts.d.ts index 8084acc3c2..bc3fb1ade7 100644 --- a/web-wallet/src/lib/contracts/contracts.d.ts +++ b/web-wallet/src/lib/contracts/contracts.d.ts @@ -22,4 +22,4 @@ type ContractStatus = { value: string | null; }; -type StakeType = "stake" | "unstake" | "withdraw-rewards"; +type StakeType = "stake" | "unstake" | "claim-rewards"; diff --git a/web-wallet/src/lib/stores/__tests__/walletStore.spec.js b/web-wallet/src/lib/stores/__tests__/walletStore.spec.js index 5a7e21aa42..e802d591bb 100644 --- a/web-wallet/src/lib/stores/__tests__/walletStore.spec.js +++ b/web-wallet/src/lib/stores/__tests__/walletStore.spec.js @@ -323,7 +323,7 @@ describe("Wallet store", async () => { const setPendingNotesSpy = vi.spyOn(walletCache, "setPendingNoteInfo"); /** - * @typedef { "shield" | "stake" | "transfer" | "unshield" | "unstake" | "withdrawReward" } TransferMethod + * @typedef { "shield" | "stake" | "transfer" | "unshield" | "unstake" | "claimRewards" } TransferMethod */ /** @@ -524,8 +524,8 @@ describe("Wallet store", async () => { await walletStoreTransferCheck("unshield", [amount, gas]); }); - it("should expose a method to withdraw the rewards", async () => { - await walletStoreTransferCheck("withdrawReward", [amount, gas]); + it("should expose a method to claim the rewards", async () => { + await walletStoreTransferCheck("claimRewards", [amount, gas]); }); }); diff --git a/web-wallet/src/lib/stores/stores.d.ts b/web-wallet/src/lib/stores/stores.d.ts index 03139dc36a..d8275654ae 100644 --- a/web-wallet/src/lib/stores/stores.d.ts +++ b/web-wallet/src/lib/stores/stores.d.ts @@ -144,7 +144,7 @@ type WalletStoreServices = { gas: import("$lib/vendor/w3sper.js/src/mod").Gas ) => Promise; - withdrawReward: ( + claimRewards: ( amount: bigint, gas: import("$lib/vendor/w3sper.js/src/mod").Gas ) => Promise; diff --git a/web-wallet/src/lib/stores/walletStore.js b/web-wallet/src/lib/stores/walletStore.js index 69f9dcfa77..04917fc517 100644 --- a/web-wallet/src/lib/stores/walletStore.js +++ b/web-wallet/src/lib/stores/walletStore.js @@ -403,8 +403,8 @@ const unstake = async (gas) => .then(updateCacheAfterTransaction) .then(passThruWithEffects(observeTxRemoval)); -/** @type {WalletStoreServices["withdrawReward"]} */ -const withdrawReward = async (amount, gas) => +/** @type {WalletStoreServices["claimRewards"]} */ +const claimRewards = async (amount, gas) => sync() .then(networkStore.connect) .then((network) => @@ -418,6 +418,7 @@ const withdrawReward = async (amount, gas) => /** @type {WalletStore} */ export default { abortSync, + claimRewards, clearLocalData, clearLocalDataAndInit, getTransactionsHistory, @@ -431,5 +432,4 @@ export default { transfer, unshield, unstake, - withdrawReward, }; diff --git a/web-wallet/src/routes/(app)/dashboard/staking/__tests__/__snapshots__/page.spec.js.snap b/web-wallet/src/routes/(app)/dashboard/staking/__tests__/__snapshots__/page.spec.js.snap index 620f005af3..c524735903 100644 --- a/web-wallet/src/routes/(app)/dashboard/staking/__tests__/__snapshots__/page.spec.js.snap +++ b/web-wallet/src/routes/(app)/dashboard/staking/__tests__/__snapshots__/page.spec.js.snap @@ -177,7 +177,7 @@ exports[`Staking > should render the staking page 1`] = ` viewBox="0 0 24 24" > @@ -185,7 +185,7 @@ exports[`Staking > should render the staking page 1`] = ` - withdraw rewards + claim rewards