Skip to content

Commit

Permalink
web-wallet: Split transfer contract UI
Browse files Browse the repository at this point in the history
Resolves #2175
  • Loading branch information
kieranhall committed Aug 31, 2024
1 parent d889a9c commit bdab0c6
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 31 deletions.
2 changes: 1 addition & 1 deletion web-wallet/src/lib/components/Allocate/Allocate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
flex-direction: column;
justify-content: center;
align-items: flex-start;
gap: var(--gap-medium);
gap: var(--medium-gap);
align-self: stretch;
border-radius: var(--fieldset-border-radius);
Expand Down
4 changes: 3 additions & 1 deletion web-wallet/src/lib/components/Receive/Receive.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { createEventDispatcher } from "svelte";
import { mdiArrowLeft, mdiContentCopy } from "@mdi/js";
import { AppAnchorButton } from "$lib/components";
import { Button, QrCode } from "$lib/dusk/components";
import { toast } from "$lib/dusk/components/Toast/store";
Expand Down Expand Up @@ -37,9 +38,10 @@

<div class="receive__buttons" bind:offsetHeight={buttonHeight}>
{#if !hideBackButton}
<Button
<AppAnchorButton
className="receive__button"
icon={{ path: mdiArrowLeft }}
href="/dashboard"
on:click={() => {
dispatch("operationChange", "");
}}
Expand Down
3 changes: 2 additions & 1 deletion web-wallet/src/lib/components/Send/Send.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@
step={0}
{key}
backButton={{
action: resetOperation,
disabled: false,
href: "/dashboard",
isAnchor: true,
}}
nextButton={{ disabled: isNextButtonDisabled }}
>
Expand Down
27 changes: 11 additions & 16 deletions web-wallet/src/lib/contracts/contract-descriptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,17 @@ export default [
disabled:
import.meta.env.VITE_CONTRACT_TRANSFER_DISABLED &&
import.meta.env.VITE_CONTRACT_TRANSFER_DISABLED === "true",
id: "transfer",
label: "Transact",
operations: [
{
disabled: false,
id: "send",
label: "Send",
primary: true,
},
{
disabled: false,
id: "receive",
label: "Receive",
primary: false,
},
],
id: "send",
label: "Send",
operations: [],
},
{
disabled:
import.meta.env.VITE_CONTRACT_TRANSFER_DISABLED &&
import.meta.env.VITE_CONTRACT_TRANSFER_DISABLED === "true",
id: "receive",
label: "Receive",
operations: [],
},
{
disabled:
Expand Down
8 changes: 8 additions & 0 deletions web-wallet/src/routes/(app)/dashboard/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<script>
import { filterWith, hasKeyValue } from "lamb";
import {
mdiArrowBottomLeft,
mdiArrowTopRight,
mdiContain,
mdiDatabaseOutline,
mdiSwapVertical,
Expand All @@ -26,6 +28,12 @@
case "allocate":
icons = [{ path: mdiSync }];
break;
case "receive":
icons = [{ path: mdiArrowBottomLeft }];
break;
case "send":
icons = [{ path: mdiArrowTopRight }];
break;
case "staking":
icons = [{ path: mdiDatabaseOutline }];
break;
Expand Down
30 changes: 30 additions & 0 deletions web-wallet/src/routes/(app)/dashboard/receive/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<svelte:options immutable={true} />

<script>
import { onDestroy, onMount } from "svelte";
import { TransferContract } from "$lib/containers";
import { IconHeadingCard } from "$lib/containers/Cards";
import { contractDescriptors, updateOperation } from "$lib/contracts";
import { operationsStore } from "$lib/stores";
import { mdiSwapVertical } from "@mdi/js";
onMount(() => {
updateOperation("receive");
})
onDestroy(() => {
updateOperation("receive");
});
</script>

<IconHeadingCard
gap="medium"
heading="Transfer"
iconPath={mdiSwapVertical}
reverse
>
<TransferContract
descriptor={contractDescriptors[1]}
on:operationChange={({ detail }) => updateOperation(detail)}
/>
</IconHeadingCard>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { cleanup, render } from "@testing-library/svelte";
import Receive from "../+page.svelte";

vi.useFakeTimers();

describe("Receive", () => {
afterEach(cleanup);

// const currentPrice = Promise.resolve({ usd: 0.5 });

it("should render the receive page", async () => {
const { container } = render(Receive);

await vi.advanceTimersToNextTimerAsync();

expect(container.firstChild).toMatchSnapshot();
});
});
30 changes: 30 additions & 0 deletions web-wallet/src/routes/(app)/dashboard/send/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<svelte:options immutable={true} />

<script>
import { onDestroy, onMount } from "svelte";
import { TransferContract } from "$lib/containers";
import { IconHeadingCard } from "$lib/containers/Cards";
import { contractDescriptors, updateOperation } from "$lib/contracts";
import { operationsStore } from "$lib/stores";
import { mdiSwapVertical } from "@mdi/js";
onMount(() => {
updateOperation("send");
})
onDestroy(() => {
updateOperation("send");
});
</script>

<IconHeadingCard
gap="medium"
heading="Send"
iconPath={mdiSwapVertical}
reverse
>
<TransferContract
descriptor={contractDescriptors[0]}
on:operationChange={({ detail }) => updateOperation(detail)}
/>
</IconHeadingCard>
19 changes: 19 additions & 0 deletions web-wallet/src/routes/(app)/dashboard/send/__tests__/page.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { cleanup, render } from "@testing-library/svelte";
import Send from "../+page.svelte";

vi.useFakeTimers();

describe("Send", () => {
afterEach(cleanup);

// const currentPrice = Promise.resolve({ usd: 0.5 });

it("should render the send page", async () => {
const { container } = render(Send);

await vi.advanceTimersToNextTimerAsync();

expect(container.firstChild).toMatchSnapshot();
});
});
13 changes: 1 addition & 12 deletions web-wallet/src/routes/(app)/dashboard/staking/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@
import { contractDescriptors, updateOperation } from "$lib/contracts";
import { settingsStore } from "$lib/stores";
/**
* @param {keyof SettingsStoreContent} property
* @param {any} value
*/
function updateSetting(property, value) {
settingsStore.update((store) => ({
...store,
[property]: value,
}));
}
onDestroy(() => {
updateOperation("");
});
Expand All @@ -32,7 +21,7 @@
reverse
>
<StakeContract
descriptor={contractDescriptors[1]}
descriptor={contractDescriptors[2]}
on:operationChange={({ detail }) => updateOperation(detail)}
on:suppressStakingNotice={() => updateSetting("hideStakingNotice", true)}
/>
Expand Down

0 comments on commit bdab0c6

Please sign in to comment.