-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Motivation Allow users to easily buy ICPs from the NNS Dapp. The purchase won't happen in the NNS Dapp though. Instead, the user will be redirected to an external provider with the destination account prefilled with their NNS Dapp main account. # Changes * New button in NnsAccountsFooter. * Adapt Footer to display three buttons. * New modal BuyIcpModal. * Add new modal in AccountsModal. * New mixing for a button with icon. # Tests * Add modals within the Accounts route TestIdWrapper. Otherwise, they are not accessible with the page object. * Test BuyIcpModal * Test in Accounts route that user can use the new modal. * Add PO and methods to perform all tests with POs. # Todos - [x] Add entry to changelog (if necessary).
- Loading branch information
Showing
20 changed files
with
317 additions
and
11 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,116 @@ | ||
<script lang="ts"> | ||
import { Html, Modal } from "@dfinity/gix-components"; | ||
import type { Account } from "$lib/types/account"; | ||
import { i18n } from "$lib/stores/i18n"; | ||
import IdentifierHash from "$lib/components/ui/IdentifierHash.svelte"; | ||
import BANXA_LOGO from "$lib/assets/banxa-logo.svg"; | ||
export let account: Account; | ||
// TODO: Move this to a util function? Or a service? | ||
// Wait until we have the final URL to do this. | ||
let queryParams: Record<string, string | number>; | ||
$: queryParams = { | ||
fiatAmount: 100, | ||
fiatType: "USD", | ||
coinAmount: 0.00244394, | ||
coinType: "ICP", | ||
lockFiat: "true", | ||
blockchain: "BTC", | ||
orderMode: "BUY", | ||
backgroundColor: "2a1a47", | ||
primaryColor: "9b6ef7", | ||
secondaryColor: "8b55f6", | ||
textColor: "ffffff", | ||
walletAddress: account?.identifier, | ||
}; | ||
let url: string; | ||
// TODO: Move base url to an env variable https://dfinity.atlassian.net/browse/GIX-2095 | ||
$: url = `https://checkout.banxa.com/?${Object.entries(queryParams) | ||
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`) | ||
.join("&")}`; | ||
</script> | ||
|
||
<Modal testId="buy-icp-modal-component" on:nnsClose> | ||
<span slot="title">{$i18n.accounts.buy_icp}</span> | ||
|
||
<div class="content"> | ||
<div> | ||
<h2>{$i18n.accounts.icp_token_utility}</h2> | ||
<p><Html text={$i18n.accounts.buy_icp_description} /></p> | ||
</div> | ||
|
||
<p class="highlight"><Html text={$i18n.accounts.buy_icp_note} /></p> | ||
|
||
<div> | ||
<h3>{$i18n.accounts.receiving_icp_address}</h3> | ||
<IdentifierHash identifier={account?.identifier} /> | ||
</div> | ||
</div> | ||
|
||
<div class="toolbar"> | ||
<a | ||
class="button primary full-width with-icon" | ||
href={url} | ||
target="_blank" | ||
data-tid="buy-icp-banxa-button" | ||
rel="noreferrer noopener" | ||
><img | ||
loading="lazy" | ||
src={BANXA_LOGO} | ||
alt={$i18n.accounts.banxa_logo_alt} | ||
draggable="false" | ||
/>{$i18n.accounts.buy_icp_banxa}</a | ||
> | ||
</div> | ||
</Modal> | ||
|
||
<style lang="scss"> | ||
@use "../../themes/mixins/button"; | ||
.content { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--padding-2x); | ||
} | ||
.highlight { | ||
background: var(--card-background-disabled); | ||
color: var(--text-description); | ||
padding: var(--padding-2x); | ||
border-radius: var(--border-radius); | ||
} | ||
a.button { | ||
box-sizing: border-box; | ||
padding: var(--padding) var(--padding-2x); | ||
border-radius: var(--border-radius); | ||
border-top: 1px solid transparent; | ||
border-bottom: 1px solid transparent; | ||
position: relative; | ||
min-height: var(--button-min-height); | ||
font-weight: var(--font-weight-bold); | ||
text-decoration: none; | ||
&.primary { | ||
background: var(--primary); | ||
color: var(--primary-contrast); | ||
&:hover, | ||
&:focus { | ||
background: var(--primary-shade); | ||
} | ||
} | ||
&.full-width { | ||
width: 100%; | ||
} | ||
&.with-icon { | ||
@include button.with-icon; | ||
} | ||
} | ||
</style> |
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,7 @@ | ||
// TODO: Move to gix-components https://dfinity.atlassian.net/browse/GIX-2108 | ||
@mixin with-icon { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
gap: var(--padding-0_5x); | ||
} |
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
Binary file modified
BIN
+1.6 KB
(110%)
...screenshots/design.spec.ts-Design-Signed-in-My-Tokens-1-Google-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.01 KB
(100%)
...s/e2e/screenshots/design.spec.ts-Design-Signed-in-My-Tokens-1-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.02 KB
(100%)
...design.spec.ts-Design-Signed-in-My-Tokens-wide-screen-1-Google-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.83 KB
(100%)
...shots/design.spec.ts-Design-Signed-in-My-Tokens-wide-screen-1-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions
39
frontend/src/tests/lib/modals/accounts/BuyIcpModal.spec.ts
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,39 @@ | ||
import BuyIcpModal from "$lib/modals/accounts/BuyIcpModal.svelte"; | ||
import type { Account } from "$lib/types/account"; | ||
import { mockMainAccount } from "$tests/mocks/icp-accounts.store.mock"; | ||
import { BuyICPModalPo } from "$tests/page-objects/BuyICPModal.page-object"; | ||
import { JestPageObjectElement } from "$tests/page-objects/jest.page-object"; | ||
import { render } from "@testing-library/svelte"; | ||
|
||
describe("BuyIcpModal", () => { | ||
const identifier = | ||
"d4685b31b51450508aff0331584df7692a84467b680326f5c5f7d30ae711682f"; | ||
const account = { | ||
...mockMainAccount, | ||
identifier, | ||
}; | ||
|
||
const renderModal = (account: Account = mockMainAccount) => { | ||
const { container } = render(BuyIcpModal, { props: { account } }); | ||
|
||
return BuyICPModalPo.under(new JestPageObjectElement(container)); | ||
}; | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it("renders the account's identifier", async () => { | ||
const po = renderModal(account); | ||
|
||
expect(await po.getAccountIdentifier()).toEqual(identifier); | ||
}); | ||
|
||
it("renders an anchor tag with URL to banxa with account identifier", async () => { | ||
const po = renderModal(); | ||
|
||
expect(await po.getBanxaUrl()).toEqual( | ||
`https://checkout.banxa.com/?fiatAmount=100&fiatType=USD&coinAmount=0.00244394&coinType=ICP&lockFiat=true&blockchain=BTC&orderMode=BUY&backgroundColor=2a1a47&primaryColor=9b6ef7&secondaryColor=8b55f6&textColor=ffffff&walletAddress=${identifier}` | ||
); | ||
}); | ||
}); |
Oops, something went wrong.