diff --git a/src/app/transfer/send/transfer.page.html b/src/app/transfer/send/transfer.page.html index 6cf58fa7318f6000b7d3ed4979824ab4b25024d3..18f614c83cf015bd5b659aebc1ac201093c2336e 100644 --- a/src/app/transfer/send/transfer.page.html +++ b/src/app/transfer/send/transfer.page.html @@ -47,6 +47,7 @@ labelPlacement="floating" readonly required + tappable ></ion-input> <ion-icon slot="end" name="chevron-forward-outline"></ion-icon> diff --git a/src/app/transfer/send/transfer.page.ts b/src/app/transfer/send/transfer.page.ts index 899e20b287462f6f750cd88753b002961d2ca341..7a5711a3ab127562aba2d58bd54ddf670ea68ec3 100644 --- a/src/app/transfer/send/transfer.page.ts +++ b/src/app/transfer/send/transfer.page.ts @@ -2,9 +2,9 @@ import { ChangeDetectionStrategy, Component, Input, OnDestroy, OnInit, ViewChild import { AppPage, AppPageState } from '@app/shared/pages/base-page.class'; import { Account, AccountUtils } from '@app/account/account.model'; import { ActionSheetOptions, IonModal, ModalController, Platform, PopoverOptions } from '@ionic/angular'; -import { firstValueFrom, mergeMap, Observable, skip, tap } from 'rxjs'; +import { firstValueFrom, merge, mergeMap, Observable, skip, switchMap, tap } from 'rxjs'; import { isNotEmptyArray, isNotNilOrBlank } from '@app/shared/functions'; -import { filter } from 'rxjs/operators'; +import { filter, map } from 'rxjs/operators'; import { NetworkService } from '@app/network/network.service'; import { Currency } from '@app/currency/currency.model'; import { NavigationEnd, Router } from '@angular/router'; @@ -59,7 +59,7 @@ export class TransferPage extends AppPage<TransferPageState> implements Transfer @Input() @RxStateProperty() currency: Currency; @Input() @RxStateProperty() fee: number; - @Input() @RxStateProperty() account: Account = null; + @Input() @RxStateProperty() account: Account; @Input() @RxStateProperty() recipient: Partial<Account>; @Input() @RxStateProperty() amount: number; @@ -115,15 +115,7 @@ export class TransferPage extends AppPage<TransferPageState> implements Transfer .pipe( tap((accounts) => console.debug(this._logPrefix + 'Accounts loaded:', accounts)), mergeMap(async (accounts) => { - // Load account - const fromAddress = this.account?.address || this.activatedRoute.snapshot.paramMap.get('from'); - if (isNotNilOrBlank(fromAddress)) { - this.account = await this.accountService.getByAddress(fromAddress); - } - // Get default - else if (isNotEmptyArray(accounts)) { - this.account = await this.accountService.getDefault(); - } + // Load recipient const toAddress = this.recipient?.address || this.activatedRoute.snapshot.paramMap.get('to'); @@ -135,6 +127,27 @@ export class TransferPage extends AppPage<TransferPageState> implements Transfer ) ); + this._state.connect('account', this.accounts$.pipe( + switchMap(accounts => merge( + this.account$.pipe(map(account => ({accounts, fromAddress: account?.address}))), + this.activatedRoute.paramMap.pipe( + map(paramMap => ({accounts, fromAddress: paramMap.get('from')})), + filter(({fromAddress}) => isNotNilOrBlank(fromAddress)) + ) + )), + mergeMap(async ({accounts, fromAddress}) => { + // Load account + if (isNotNilOrBlank(fromAddress)) { + return this.accountService.getByAddress(fromAddress); + } + // Get default + else if (isNotEmptyArray(accounts)) { + return this.accountService.getDefault(); + } + return undefined; + }) + )); + this._state.connect('currency', this.networkService.currency$); this._state.connect('fee', this.currency$, (_, currency) => {