Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Senna46 committed Oct 23, 2023
2 parents c14d2f5 + 23c4c4d commit 4b3733a
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<view-yieldaggregator
[depositors]="depositors$ | async"
[addressTVLs]="addressTVLs$ | async"
(appDownloadCSV)="downloadTVLsCSV()"
[msgs]="msgs$ | async"
(appDownloadTVLs)="downloadTVLsCSV()"
(appDownloadMsgs)="downloadMsgsCSV()"
></view-yieldaggregator>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CosmosSDKService } from '../../../models/cosmos-sdk.service';
import { Component, OnInit } from '@angular/core';
import cosmosclient from '@cosmos-client/core';
import { BandProtocolService } from 'projects/portal/src/app/models/band-protocols/band-protocol.service';
import { getDenomExponent } from 'projects/portal/src/app/models/cosmos/bank.model';
import { BankQueryService } from 'projects/portal/src/app/models/cosmos/bank.query.service';
import { YieldAggregatorQueryService } from 'projects/portal/src/app/models/yield-aggregators/yield-aggregator.query.service';
import { LoadingDialogService } from 'projects/shared/src/lib/components/loading-dialog';
Expand All @@ -18,6 +19,19 @@ import ununificlient from 'ununifi-client';
export class YieldaggregatorComponent implements OnInit {
pollingInterval = 30;
depositors$?: Observable<string[]>;
msgs$?: Observable<
{
type: string;
txHash: string;
height: string;
timestamp: string;
sender: string;
vaultId: string;
amount: string;
microAmount: string;
denom?: string;
}[]
>;
addressBalances$?: Observable<
{
address: string;
Expand Down Expand Up @@ -109,6 +123,62 @@ export class YieldaggregatorComponent implements OnInit {
return msgs;
}),
);
const denomMetadataMap$ = this.bankQuery.getDenomMetadataMap$();
this.msgs$ = combineLatest([txsResponse$, denomMetadataMap$]).pipe(
map(([txs, denomMetadataMap]) => {
const msgs: {
type: string;
txHash: string;
height: string;
timestamp: string;
sender: string;
vaultId: string;
amount: string;
microAmount: string;
denom?: string;
}[] = [];
txs?.txs?.map((tx, index) =>
tx.body?.messages?.map((message) => {
const instance = cosmosclient.codec.protoJSONToInstance(
cosmosclient.codec.castProtoJSONOfProtoAny(message),
);
if (instance instanceof ununificlient.proto.ununifi.yieldaggregator.MsgDepositToVault) {
const denom = instance.amount?.denom || '';
const exponent = getDenomExponent(denom);
const amount = Number(instance.amount?.amount) / Math.pow(10, exponent);
msgs.push({
type: 'deposit',
txHash: txs.tx_responses?.[index].txhash || '',
height: txs.tx_responses?.[index].height || '',
timestamp: txs.tx_responses?.[index].timestamp || '',
sender: instance.sender,
vaultId: instance.vault_id.toString(),
amount: amount + ' ' + (denomMetadataMap?.[denom].display || ''),
microAmount: instance.amount?.amount || '',
denom: denom,
});
}
if (
instance instanceof ununificlient.proto.ununifi.yieldaggregator.MsgWithdrawFromVault
) {
const amount = Number(instance.lp_token_amount) / Math.pow(10, 6);
msgs.push({
type: 'withdraw',
txHash: txs.tx_responses?.[index].txhash || '',
height: txs.tx_responses?.[index].height || '',
timestamp: txs.tx_responses?.[index].timestamp || '',
sender: instance.sender,
vaultId: instance.vault_id.toString(),
amount: amount + ' YA-Vault-' + instance.vault_id.toString(),
microAmount: instance.lp_token_amount,
denom: 'yieldaggregator/vaults/' + instance.vault_id.toString(),
});
}
}),
);
return msgs;
}),
);
this.depositors$ = depositMsgs$.pipe(
map((msgs) => {
const addressArray = msgs?.map((msg) => msg.sender);
Expand All @@ -127,7 +197,6 @@ export class YieldaggregatorComponent implements OnInit {
),
),
);
const denomMetadataMap$ = this.bankQuery.getDenomMetadataMap$();
this.addressTVLs$ = combineLatest([this.addressBalances$, denomMetadataMap$]).pipe(
mergeMap(([addressBalances, denomMetadataMap]) =>
Promise.all(
Expand Down Expand Up @@ -183,4 +252,18 @@ export class YieldaggregatorComponent implements OnInit {
dialogRef.close();
this.csvCommonService.downloadCsv(csvString, 'UYA-TVLs-' + now.toISOString());
}

async downloadMsgsCSV() {
const dialogRef = this.loadingDialog.open('Downloading...');
const msgs = await this.msgs$?.pipe(take(1)).toPromise();
const data = msgs;
if (!data) {
alert('No data');
return;
}
const csvString = this.csvCommonService.jsonToCsv(data, ',');
const now = new Date();
dialogRef.close();
this.csvCommonService.downloadCsv(csvString, 'UYA-Msgs-' + now.toISOString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<div class="overflow-x-auto">
<table class="table w-full">
<thead>
<th>Vault#</th>
<th>Vault ID</th>
<td>YA Token Amount</td>
<td>$ Value</td>
</thead>
Expand Down Expand Up @@ -62,7 +62,7 @@
(click)="downloadDeposits()"
>
<span class="material-symbols-outlined">download</span>
<span class="hidden md:inline">Download</span>
<span class="hidden md:inline">Download CSV</span>
</button>
</div>
</div>
Expand Down Expand Up @@ -112,7 +112,7 @@ <h3 class="card-title">Deposit History</h3>
(click)="downloadDepositMsgs()"
>
<span class="material-symbols-outlined">download</span>
<span class="hidden md:inline">Download</span>
<span class="hidden md:inline">Download CSV</span>
</button>
</div>
</div>
Expand Down Expand Up @@ -164,7 +164,7 @@ <h3 class="card-title">Withdrawal History</h3>
(click)="downloadWithdrawalMsgs()"
>
<span class="material-symbols-outlined">download</span>
<span class="hidden md:inline">Download</span>
<span class="hidden md:inline">Download CSV</span>
</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,63 @@ <h3>Leader Board</h3>
<div class="card-actions justify-end">
<button
class="btn btn-outline btn-primary w-full gap-1 md:w-auto md:px-8"
(click)="downloadCSV()"
(click)="downloadTVLs()"
>
<span class="material-symbols-outlined">download</span>
<span class="hidden md:inline">Download CSV</span>
</button>
</div>
</div>
</div>
</div>

<div class="card bg-base-100 text-base-content shadow-xl mb-4">
<div class="card-body">
<h3>Tx History</h3>
<div class="overflow-x-auto">
<ng-container *ngIf="msgs === null; then loading; else loadedMsg"></ng-container>
<ng-template #loadedMsg>
<ng-container *ngIf="!msgs?.length; then emptyMsg; else filledMsg"></ng-container>
<ng-template #emptyMsg>
<p class="ml-4">There is no depositor.</p>
</ng-template>
<ng-template #filledMsg>
<table class="table w-full">
<thead>
<td>Type</td>
<td>Vault ID</td>
<td>Address</td>
<td>Amount</td>
<td>Timestamp</td>
</thead>
<tbody>
<tr
*ngFor="let msg of msgs; let i = index"
class="hover cursor-pointer"
routerLink="/txs/{{ msg.txHash }}"
>
<td>{{ msg.type }}</td>
<th>{{ msg.vaultId }}</th>
<th class="font-mono">{{ msg.sender }}</th>
<td>{{ msg.amount }}</td>
<td>{{ msg.timestamp | date : 'yy/MM/dd HH:mm' }}</td>
</tr>
</tbody>
</table>
</ng-template>
</ng-template>

<ng-template #emptyMsg>
<tr>
<td colspan="5">There is no tx.</td>
</tr>
</ng-template>
</div>
<div>
<div class="card-actions justify-end">
<button
class="btn btn-outline btn-primary w-full gap-1 md:w-auto md:px-8"
(click)="downloadMsgs()"
>
<span class="material-symbols-outlined">download</span>
<span class="hidden md:inline">Download CSV</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,31 @@ export class YieldaggregatorComponent implements OnInit {
tvl: number;
}[]
| null;
@Input()
msgs?:
| {
type: string;
txHash: string;
height: string;
timestamp: string;
sender: string;
vaultId: string;
amount: string;
}[]
| null;
@Output()
appDownloadTVLs: EventEmitter<{}> = new EventEmitter();
@Output()
appDownloadCSV: EventEmitter<{}> = new EventEmitter();
appDownloadMsgs: EventEmitter<{}> = new EventEmitter();

constructor() {}

ngOnInit(): void {}

downloadCSV() {
this.appDownloadCSV.emit();
downloadTVLs() {
this.appDownloadTVLs.emit();
}
downloadMsgs() {
this.appDownloadMsgs.emit();
}
}

0 comments on commit 4b3733a

Please sign in to comment.