Skip to content

Commit

Permalink
Fix update price. Fix swap
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazar Usov authored and Nazar Usov committed Nov 24, 2023
1 parent e3ce933 commit 3492c19
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 32 deletions.
4 changes: 2 additions & 2 deletions html_source/src/app/api/models/swap.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ export interface ProposalDetails {
expiration_time: number;
fee_paid_by_a: number;
mixins: number;
to_alice: [
to_initiator: [
{
amount: number | string;
asset_id: string;
}
];
to_bob: [
to_finalizer: [
{
amount: number | string;
asset_id: string;
Expand Down
41 changes: 17 additions & 24 deletions html_source/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IntToMoneyPipe } from '@parts/pipes';
import { BigNumber } from 'bignumber.js';
import { ModalService } from '@parts/services/modal.service';
import { StateKeys, Store } from '@store/store';
import { Subject, take } from 'rxjs';
import { shareReplay, Subject, switchMap, take } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { paths, pathsChildrenAuth } from './pages/paths';
import { hasOwnProperty } from '@parts/functions/hasOwnProperty';
Expand Down Expand Up @@ -718,11 +718,12 @@ export class AppComponent implements OnInit, OnDestroy {

this.variablesService.disable_price_fetch$.pipe(takeUntil(this.destroy$)).subscribe({
next: disable_price_fetch => {
const updateTime = 10 * 60 * 1000;
if (!disable_price_fetch) {
this.updateMoneyEquivalent();
this.intervalUpdatePriceState = setInterval(() => {
this.updateMoneyEquivalent();
}, 30000);
}, updateTime);
} else {
if (this.intervalUpdatePriceState) {
clearInterval(this.intervalUpdatePriceState);
Expand All @@ -744,28 +745,20 @@ export class AppComponent implements OnInit, OnDestroy {
}

updateMoneyEquivalent(): void {
this.http
.get('https://api.coingecko.com/api/v3/ping')
.pipe(take(1))
.subscribe({
next: () => {
this.http
.get('https://api.coingecko.com/api/v3/simple/price?ids=zano&vs_currencies=usd&include_24hr_change=true')
.pipe(take(1))
.subscribe({
next: data => {
this.variablesService.moneyEquivalent = data['zano']['usd'];
this.variablesService.moneyEquivalentPercent = data['zano']['usd_24h_change'];
},
error: error => {
console.warn('api.coingecko.com price error: ', error);
},
});
},
error: error => {
console.warn('api.coingecko.com error: ', error);
},
});
const ping$ = this.http.get('https://api.coingecko.com/api/v3/ping').pipe(shareReplay(1));

ping$.pipe(
switchMap(() => this.http.get('https://api.coingecko.com/api/v3/simple/price?ids=zano&vs_currencies=usd&include_24hr_change=true')),
take(1)
).subscribe({
next: data => {
this.variablesService.moneyEquivalent = data['zano']['usd'];
this.variablesService.moneyEquivalentPercent = data['zano']['usd_24h_change'];
},
error: error => {
console.warn('api.coingecko.com price error: ', error);
},
});
}

getAliases(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h3 class="title mb-2" fxFlex="0 0 auto">
{{ 'CONFIRM_SWAP.FORM.TABLE.LABELS.LABEL1' | translate }}
</div>
<div class="text">
<ng-container *ngFor="let item of data.proposalDetails.to_alice">
<ng-container *ngFor="let item of data.proposalDetails.to_initiator">
{{ item.amount | intToMoney }}
{{ (item.asset_id | getAsset)?.asset_info.ticker || '???' }}
<br />
Expand All @@ -27,7 +27,7 @@ <h3 class="title mb-2" fxFlex="0 0 auto">
{{ 'CONFIRM_SWAP.FORM.TABLE.LABELS.LABEL2' | translate }}
</div>
<div class="text">
<ng-container *ngFor="let item of data.proposalDetails.to_bob">
<ng-container *ngFor="let item of data.proposalDetails.to_finalizer">
{{ item.amount | intToMoney }}
{{ (item.asset_id | getAsset)?.asset_info.ticker || '???' }}
<br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div class="label max-w-19-rem w-100">
{{ 'CONFIRM_SWAP.FORM.TABLE.LABELS.LABEL1' | translate }}
</div>
<div *ngFor="let item of proposalDetails.to_alice" class="text">
<div *ngFor="let item of proposalDetails.to_initiator" class="text">
{{ item.amount | intToMoney }}
{{ (item.asset_id | getAsset)?.asset_info.ticker || '???' }}
</div>
Expand All @@ -34,7 +34,7 @@
<div class="label max-w-19-rem w-100">
{{ 'CONFIRM_SWAP.FORM.TABLE.LABELS.LABEL2' | translate }}
</div>
<div *ngFor="let item of proposalDetails.to_bob" class="text">
<div *ngFor="let item of proposalDetails.to_finalizer" class="text">
{{ item.amount | intToMoney }}
{{ (item.asset_id | getAsset)?.asset_info.ticker || '???' }}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,13 @@ export class CreateSwapComponent implements OnInit, OnDestroy {
method: 'ionic_swap_generate_proposal',
params: {
proposal: {
to_bob: [
to_finalizer: [
{
asset_id: sending.asset_id,
amount: this.moneyToIntPipe.transform(sending.amount),
},
],
to_alice: [
to_initiator: [
{
asset_id: receiving.asset_id,
amount: this.moneyToIntPipe.transform(receiving.amount),
Expand Down

0 comments on commit 3492c19

Please sign in to comment.