From e7e9d52acec6dc347ad198718defd283e4da3d0f Mon Sep 17 00:00:00 2001 From: Benoit Lavenier <benoit.lavenier@e-is.pro> Date: Fri, 7 Feb 2025 23:00:56 +0100 Subject: [PATCH] fix(transfert) Set the from address, when given to the transfert modal --- src/app/transfer/send/transfer.page.html | 1 + src/app/transfer/send/transfer.page.ts | 37 ++++++++++++++++-------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/app/transfer/send/transfer.page.html b/src/app/transfer/send/transfer.page.html index 6cf58fa..18f614c 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 899e20b..7a5711a 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) => { -- GitLab