Skip to content
Snippets Groups Projects
Commit e7e9d52a authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

fix(transfert) Set the from address, when given to the transfert modal

parent 151e2106
No related branches found
No related tags found
No related merge requests found
Pipeline #39836 waiting for manual action
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
labelPlacement="floating" labelPlacement="floating"
readonly readonly
required required
tappable
></ion-input> ></ion-input>
<ion-icon slot="end" name="chevron-forward-outline"></ion-icon> <ion-icon slot="end" name="chevron-forward-outline"></ion-icon>
......
...@@ -2,9 +2,9 @@ import { ChangeDetectionStrategy, Component, Input, OnDestroy, OnInit, ViewChild ...@@ -2,9 +2,9 @@ import { ChangeDetectionStrategy, Component, Input, OnDestroy, OnInit, ViewChild
import { AppPage, AppPageState } from '@app/shared/pages/base-page.class'; import { AppPage, AppPageState } from '@app/shared/pages/base-page.class';
import { Account, AccountUtils } from '@app/account/account.model'; import { Account, AccountUtils } from '@app/account/account.model';
import { ActionSheetOptions, IonModal, ModalController, Platform, PopoverOptions } from '@ionic/angular'; 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 { 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 { NetworkService } from '@app/network/network.service';
import { Currency } from '@app/currency/currency.model'; import { Currency } from '@app/currency/currency.model';
import { NavigationEnd, Router } from '@angular/router'; import { NavigationEnd, Router } from '@angular/router';
...@@ -59,7 +59,7 @@ export class TransferPage extends AppPage<TransferPageState> implements Transfer ...@@ -59,7 +59,7 @@ export class TransferPage extends AppPage<TransferPageState> implements Transfer
@Input() @RxStateProperty() currency: Currency; @Input() @RxStateProperty() currency: Currency;
@Input() @RxStateProperty() fee: number; @Input() @RxStateProperty() fee: number;
@Input() @RxStateProperty() account: Account = null; @Input() @RxStateProperty() account: Account;
@Input() @RxStateProperty() recipient: Partial<Account>; @Input() @RxStateProperty() recipient: Partial<Account>;
@Input() @RxStateProperty() amount: number; @Input() @RxStateProperty() amount: number;
...@@ -115,15 +115,7 @@ export class TransferPage extends AppPage<TransferPageState> implements Transfer ...@@ -115,15 +115,7 @@ export class TransferPage extends AppPage<TransferPageState> implements Transfer
.pipe( .pipe(
tap((accounts) => console.debug(this._logPrefix + 'Accounts loaded:', accounts)), tap((accounts) => console.debug(this._logPrefix + 'Accounts loaded:', accounts)),
mergeMap(async (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 // Load recipient
const toAddress = this.recipient?.address || this.activatedRoute.snapshot.paramMap.get('to'); const toAddress = this.recipient?.address || this.activatedRoute.snapshot.paramMap.get('to');
...@@ -135,6 +127,27 @@ export class TransferPage extends AppPage<TransferPageState> implements Transfer ...@@ -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('currency', this.networkService.currency$);
this._state.connect('fee', this.currency$, (_, currency) => { this._state.connect('fee', this.currency$, (_, currency) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment