-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web-wallet: Integration with latest wallet-js and Sync improvements
Resolves #1561, Resolves #1567, Resolves #1568, Resolves #1570, Resolves #1595 Changelog: - Integration with the latest wallet-js library (v.0.5.3) - Display of the current network block height during wallet creation - Prevention of full sync for newly created wallets - Option for users to restore a wallet from either genesis or a specific block height - Relocation of the initial sync to the wallet restore flow - A sync indicator that displays progress for both initial and subsequent syncs
- Loading branch information
1 parent
73be96e
commit 1187d36
Showing
48 changed files
with
1,591 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.copy-field { | ||
display: flex; | ||
align-items: center; | ||
gap: var(--default-gap); | ||
} | ||
|
||
.copy-field__content { | ||
flex: 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<svelte:options immutable={true} /> | ||
|
||
<script> | ||
import "./CopyField.css"; | ||
import { mdiAlertOutline, mdiContentCopy } from "@mdi/js"; | ||
import { Button, Textbox } from "$lib/dusk/components"; | ||
import { toast } from "$lib/dusk/components/Toast/store"; | ||
/** @type {string} */ | ||
export let name; | ||
/** @type {string} */ | ||
export let displayValue; | ||
/** @type {string} */ | ||
export let rawValue; | ||
/** @type {boolean} */ | ||
export let disabled = false; | ||
function copyToClipboard() { | ||
navigator.clipboard | ||
.writeText(rawValue) | ||
.then(() => { | ||
toast("success", `${name} copied`, mdiContentCopy); | ||
}) | ||
.catch((err) => { | ||
toast( | ||
"error", | ||
err.name === "NotAllowedError" | ||
? "Clipboard access denied" | ||
: err.message, | ||
mdiAlertOutline | ||
); | ||
}); | ||
} | ||
</script> | ||
|
||
<div class="copy-field"> | ||
<Textbox | ||
className="copy-field__content" | ||
value={displayValue} | ||
type="text" | ||
readOnly | ||
/> | ||
<Button | ||
aria-label="Copy Address" | ||
className="copy-field__button" | ||
icon={{ path: mdiContentCopy }} | ||
on:click={copyToClipboard} | ||
variant="primary" | ||
{disabled} | ||
/> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { afterEach, describe, expect, it, vi } from "vitest"; | ||
import { cleanup, fireEvent, render } from "@testing-library/svelte"; | ||
import { CopyField } from ".."; | ||
|
||
Object.assign(navigator, { | ||
clipboard: { | ||
writeText: vi.fn().mockResolvedValue(""), | ||
}, | ||
}); | ||
|
||
describe("CopyField", () => { | ||
const baseProps = { | ||
disabled: false, | ||
displayValue: "1,234,567", | ||
name: "Sample Information", | ||
rawValue: "1234567", | ||
}; | ||
|
||
const baseOptions = { | ||
props: baseProps, | ||
target: document.body, | ||
}; | ||
|
||
afterEach(cleanup); | ||
|
||
it("renders the CopyField component", () => { | ||
const { container } = render(CopyField, baseOptions); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("renders the CopyField component with the copy button disabled", () => { | ||
const { container, getByRole } = render(CopyField, { | ||
...baseOptions, | ||
props: { ...baseProps, disabled: true }, | ||
}); | ||
|
||
const copyButton = getByRole("button"); | ||
|
||
expect(copyButton).toBeDisabled(); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("copies the raw value on pressing the copy button", async () => { | ||
const { getByRole } = render(CopyField, baseOptions); | ||
|
||
const copyButton = getByRole("button"); | ||
|
||
await fireEvent.click(copyButton); | ||
|
||
expect(navigator.clipboard.writeText).toHaveBeenCalledWith("1234567"); | ||
}); | ||
}); |
66 changes: 66 additions & 0 deletions
66
web-wallet/src/lib/components/__tests__/__snapshots__/CopyField.spec.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`CopyField > renders the CopyField component 1`] = ` | ||
<div | ||
class="copy-field" | ||
> | ||
<input | ||
class="dusk-textbox dusk-textbox-text copy-field__content" | ||
readonly="" | ||
type="text" | ||
/> | ||
<button | ||
aria-label="Copy Address" | ||
class="dusk-button dusk-button--type--button dusk-button--variant--primary dusk-button--size--default dusk-icon-button copy-field__button" | ||
type="button" | ||
> | ||
<svg | ||
class="dusk-icon dusk-icon--size--default dusk-button__icon" | ||
role="graphics-symbol" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" | ||
/> | ||
</svg> | ||
</button> | ||
</div> | ||
`; | ||
|
||
exports[`CopyField > renders the CopyField component with the copy button disabled 1`] = ` | ||
<div | ||
class="copy-field" | ||
> | ||
<input | ||
class="dusk-textbox dusk-textbox-text copy-field__content" | ||
readonly="" | ||
type="text" | ||
/> | ||
<button | ||
aria-label="Copy Address" | ||
class="dusk-button dusk-button--type--button dusk-button--variant--primary dusk-button--size--default dusk-icon-button copy-field__button" | ||
disabled="" | ||
type="button" | ||
> | ||
<svg | ||
class="dusk-icon dusk-icon--size--default dusk-button__icon" | ||
role="graphics-symbol" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" | ||
/> | ||
</svg> | ||
</button> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.