From 4d5ffdbf18a4d2ac443af46b5156827b8eb27348 Mon Sep 17 00:00:00 2001 From: keeri Date: Tue, 28 Mar 2023 17:45:34 +0000 Subject: [PATCH] send page: add support for nano uri fix 'route' variable being incorrectly named 'router' --- src/app/components/send/send.component.html | 2 +- src/app/components/send/send.component.ts | 45 +++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/app/components/send/send.component.html b/src/app/components/send/send.component.html index 584a1d5..e60f6b0 100644 --- a/src/app/components/send/send.component.html +++ b/src/app/components/send/send.component.html @@ -32,7 +32,7 @@
- +
    diff --git a/src/app/components/send/send.component.ts b/src/app/components/send/send.component.ts index a6d5e7b..c3ed326 100644 --- a/src/app/components/send/send.component.ts +++ b/src/app/components/send/send.component.ts @@ -14,6 +14,7 @@ import {NanoBlockService} from '../../services/nano-block.service'; import { QrModalService } from '../../services/qr-modal.service'; import { environment } from 'environments/environment'; import { TranslocoService } from '@ngneat/transloco'; +import * as nanocurrency from 'nanocurrency'; const nacl = window['nacl']; @@ -58,7 +59,7 @@ export class SendComponent implements OnInit { selAccountInit = false; constructor( - private router: ActivatedRoute, + private route: ActivatedRoute, private walletService: WalletService, private addressBookService: AddressBookService, private notificationService: NotificationService, @@ -72,7 +73,7 @@ export class SendComponent implements OnInit { private translocoService: TranslocoService) { } async ngOnInit() { - const params = this.router.snapshot.queryParams; + const params = this.route.snapshot.queryParams; this.updateQueries(params); @@ -99,7 +100,7 @@ export class SendComponent implements OnInit { }); // Update the account if query params changes. For example donation button while active on this page - this.router.queryParams.subscribe(queries => { + this.route.queryParams.subscribe(queries => { this.updateQueries(queries); }); @@ -192,6 +193,44 @@ export class SendComponent implements OnInit { this.amount = nanoAmount.toNumber(); } + onDestinationAddressInput() { + this.searchAddressBook(); + + const destinationAddress = this.toAccountID || ''; + + const nanoURIScheme = /^nano:.+$/g; + const isNanoURI = nanoURIScheme.test(destinationAddress); + + if (isNanoURI === true) { + const url = new URL(destinationAddress); + + if (this.util.account.isValidAccount(url.pathname)) { + const amountAsRaw = url.searchParams.get('amount'); + + const amountAsXNO = ( + amountAsRaw + ? nanocurrency.convert( + amountAsRaw, { + from: nanocurrency.Unit.raw, + to: nanocurrency.Unit.NANO + } + ).toString() + : null + ); + + setTimeout( + () => { + this.updateQueries({ + to: url.pathname, + amount: amountAsXNO, + }); + }, + 10 + ); + } + } + } + searchAddressBook() { this.showAddressBook = true; const search = this.toAccountID || '';