From d1373c4ad1464570daff9d6c7142389ae00dca41 Mon Sep 17 00:00:00 2001 From: nhphuc <101378686+nhphuc2411@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:45:50 +0700 Subject: [PATCH 1/2] Merge pull request #3204 from aura-nw/feature/update-chainid Merge pull request #3203 from aura-nw/baseline/main_20240327 (cherry picked from commit fa02ffbc801e723a9a795d7d6bd3bd9a40a20c55) --- .../statistics/chart-detail/chart-detail.component.ts | 7 +++---- .../pages/statistics/chart-stats/chart-stats.component.ts | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/app/pages/statistics/chart-detail/chart-detail.component.ts b/src/app/pages/statistics/chart-detail/chart-detail.component.ts index 350b766b0..63880f4df 100644 --- a/src/app/pages/statistics/chart-detail/chart-detail.component.ts +++ b/src/app/pages/statistics/chart-detail/chart-detail.component.ts @@ -29,7 +29,6 @@ export class ChartDetailComponent implements OnInit, OnDestroy { logicalRangeChange$ = new Subject<{ from; to }>(); endData = false; destroy$ = new Subject(); - prevYearNumber = 1; originalData = []; isLoading = true; errTxt: string; @@ -159,9 +158,9 @@ export class ChartDetailComponent implements OnInit, OnDestroy { subscribeVisibleLogicalRangeChange() { this.logicalRangeChange$.pipe(debounceTime(500), takeUntil(this.destroy$)).subscribe(({ from, to }) => { if (from <= 0 && !this.endData) { - this.prevYearNumber++; const currTime = new Date(); - const prevTime = new Date(currTime.getFullYear() - this.prevYearNumber, 0, 1); + const prevTime = new Date(Date.now() - 365 * 24 * 60 * 60 * 1000); + this.statisticService.getDataStatistic(prevTime, currTime).subscribe((res) => { if (res?.daily_statistics.length > 0) { let dataY = []; @@ -218,7 +217,7 @@ export class ChartDetailComponent implements OnInit, OnDestroy { this.endData = false; this.chartRange = type; const currTime = new Date(); - const prevTime = new Date(currTime.getFullYear() - 1, 0, 1); + const prevTime = new Date(Date.now() - 365 * 24 * 60 * 60 * 1000); this.statisticService.getDataStatistic(prevTime, currTime).subscribe({ next: (res) => { diff --git a/src/app/pages/statistics/chart-stats/chart-stats.component.ts b/src/app/pages/statistics/chart-stats/chart-stats.component.ts index 7dbc27c86..68962ef83 100644 --- a/src/app/pages/statistics/chart-stats/chart-stats.component.ts +++ b/src/app/pages/statistics/chart-stats/chart-stats.component.ts @@ -37,7 +37,6 @@ export class ChartStatsComponent implements OnInit { minValueDailyAddress = 0; maxValueDailyTx = 0; minValueDailyTx = 0; - chainName = this.env.chainName; constructor( @@ -144,7 +143,7 @@ export class ChartStatsComponent implements OnInit { visible: true, borderColor: '#494C58', scaleMargins: { - top: 0.3, + top: 0.55, bottom: 0.05, }, mode: 1, From 7c773789773431abd62259507f0c8ff3bc1277a1 Mon Sep 17 00:00:00 2001 From: nhphuc2411 Date: Fri, 19 Apr 2024 14:01:44 +0700 Subject: [PATCH 2/2] Merge remote-tracking branch 'origin/develop' into baseline/serenity_20240419 (cherry picked from commit 8114bfc30bc3cffaa3db21666e996cecef9e5d19) # Conflicts: # src/app/core/services/wallet.service.ts --- src/app/core/services/wallet.service.ts | 74 +++++++++++++++---- src/app/core/utils/cosmoskit/wallets/index.ts | 8 +- .../popup-add-grant.component.ts | 4 +- .../popup-revoke/popup-revoke.component.ts | 2 +- .../proposal-vote/proposal-vote.component.ts | 2 +- .../pages/validators/validators.component.ts | 3 +- 6 files changed, 71 insertions(+), 22 deletions(-) diff --git a/src/app/core/services/wallet.service.ts b/src/app/core/services/wallet.service.ts index 70b52cb3e..42af83bb5 100644 --- a/src/app/core/services/wallet.service.ts +++ b/src/app/core/services/wallet.service.ts @@ -1,6 +1,6 @@ import { Injectable, OnDestroy } from '@angular/core'; import { Chain } from '@chain-registry/types'; -import { JsonObject } from '@cosmjs/cosmwasm-stargate'; +import { JsonObject, SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'; import { EncodeObject } from '@cosmjs/proto-signing'; import { Coin, StdFee } from '@cosmjs/stargate'; import { @@ -19,7 +19,10 @@ import { WalletName, } from '@cosmos-kit/core'; import { BehaviorSubject, Observable } from 'rxjs'; +import { EnvironmentService } from '../data-services/environment.service'; import { allAssets, STORAGE_KEY } from '../utils/cosmoskit'; +import { getGasPriceByChain } from '../utils/cosmoskit/helpers/gas'; +import { ExtendsWalletClient } from '../utils/cosmoskit/wallets'; @Injectable({ providedIn: 'root', @@ -52,7 +55,7 @@ export class WalletService implements OnDestroy { return this._chain; } - constructor() { + constructor(private env: EnvironmentService) { this._walletAccountSubject$ = new BehaviorSubject(null); this.walletAccount$ = this._walletAccountSubject$.asObservable(); } @@ -203,6 +206,24 @@ export class WalletService implements OnDestroy { }); } + private async _getSigningCosmWasmClientAuto() { + let _walletName = localStorage.getItem(STORAGE_KEY.CURRENT_WALLET); + const chainWallet = this._walletManager.getMainWallet(_walletName); + + try { + const client = chainWallet?.clientMutable?.data as ExtendsWalletClient; + const signer = await client?.client?.getOfflineSignerAuto(this._chain.chain_id); + + return SigningCosmWasmClient.connectWithSigner(this.env.chainInfo.rpc, signer, { + gasPrice: getGasPriceByChain(this._chain), + }); + } catch (error) { + console.log(`Error: ${error}`); + + return undefined; + } + } + getChainWallet(walletName?: WalletName): ChainWalletBase { let _walletName = walletName ?? localStorage.getItem(STORAGE_KEY.CURRENT_WALLET); if (!_walletName) { @@ -223,10 +244,17 @@ export class WalletService implements OnDestroy { memo?: string, timeoutHeight?: bigint, ) { - return (await this._getSigningCosmWasmClient()).signAndBroadcast(signerAddress, messages, fee, memo, timeoutHeight); + let client; + try { + client = await this._getSigningCosmWasmClientAuto(); + } catch (error) { + client = await this._getSigningCosmWasmClient(); + } + + return client.signAndBroadcast(signerAddress, messages, fee, memo); } - executeContract( + async executeContract( senderAddress: string, contractAddress: string, msg: JsonObject, @@ -234,9 +262,13 @@ export class WalletService implements OnDestroy { memo?: string, funds?: readonly Coin[], ) { - return this._getSigningCosmWasmClient().then( - (client) => client?.execute(senderAddress, contractAddress, msg, fee, memo, funds), - ); + let client; + try { + client = await this._getSigningCosmWasmClientAuto(); + } catch (error) { + client = await this._getSigningCosmWasmClient(); + } + return client?.execute(senderAddress, contractAddress, msg, fee, memo, funds); } signArbitrary(signer: string, data: string | Uint8Array) { @@ -263,9 +295,17 @@ export class WalletService implements OnDestroy { fee: StdFee | 'auto' | number = 'auto', memo?: string, ) { - return this._getSigningCosmWasmClient().then((client) => - client.delegateTokens(delegatorAddress, validatorAddress, amount, fee, memo), - ); + let client; + try { + client = await this._getSigningCosmWasmClientAuto(); + } catch (error) { + client = await this._getSigningCosmWasmClient(); + } + + return client.delegateTokens(delegatorAddress, validatorAddress, amount, fee, memo); + // return this._getSigningCosmWasmClient().then((client) => + // client.delegateTokens(delegatorAddress, validatorAddress, amount, fee, memo), + // ); } async undelegateTokens( @@ -275,9 +315,17 @@ export class WalletService implements OnDestroy { fee: StdFee | 'auto' | number = 'auto', memo?: string, ) { - return this._getSigningCosmWasmClient().then((client) => - client.undelegateTokens(delegatorAddress, validatorAddress, amount, fee, memo), - ); + let client; + try { + client = await this._getSigningCosmWasmClientAuto(); + } catch (error) { + client = await this._getSigningCosmWasmClient(); + } + + return client.undelegateTokens(delegatorAddress, validatorAddress, amount, fee, memo); + // return this._getSigningCosmWasmClient().then((client) => + // client.undelegateTokens(delegatorAddress, validatorAddress, amount, fee, memo), + // ); } estimateFee(messages: EncodeObject[], type?: CosmosClientType, memo?: string, multiplier?: number) { diff --git a/src/app/core/utils/cosmoskit/wallets/index.ts b/src/app/core/utils/cosmoskit/wallets/index.ts index 5a2991e38..f3c10ba9e 100644 --- a/src/app/core/utils/cosmoskit/wallets/index.ts +++ b/src/app/core/utils/cosmoskit/wallets/index.ts @@ -1,6 +1,6 @@ import { MainWalletBase } from '@cosmos-kit/core'; import { WalletName } from '@cosmos-kit/core/cjs/types'; -import { wallets as keplrWallets } from '@cosmos-kit/keplr-extension'; +import { wallets as keplrWallets, KeplrClient } from '@cosmos-kit/keplr-extension'; import { wallets as keplrMobileWallets } from '@cosmos-kit/keplr-mobile'; import { wallets as leapWallets } from '@cosmos-kit/leap-extension'; import { wallets as leapMobileWallets } from '@cosmos-kit/leap-mobile'; @@ -16,7 +16,7 @@ import { isLeapExtention, isMetamaskExtention, } from '../helpers/browser'; -import { wallets as coin98Wallets } from './coin98-extension'; +import { Coin98Client, wallets as coin98Wallets } from './coin98-extension'; import { wallets as coin98MobileWallets } from './coin98-mobile'; import { wallets as leapSnapMetaMaskWallets } from './leap-metamask-cosmos-snap'; import { wallets as wcWallets } from './wallet-connect/wc'; @@ -71,4 +71,6 @@ function checkDesktopWallets(walletName: WalletName) { } } -export { desktopWallets, mobileWallets, wcWallets, checkDesktopWallets }; +type ExtendsWalletClient = KeplrClient | Coin98Client; + +export { desktopWallets, mobileWallets, wcWallets, checkDesktopWallets, ExtendsWalletClient }; diff --git a/src/app/pages/fee-grant/popup-add-grant/popup-add-grant.component.ts b/src/app/pages/fee-grant/popup-add-grant/popup-add-grant.component.ts index 384e55267..0e2e73760 100644 --- a/src/app/pages/fee-grant/popup-add-grant/popup-add-grant.component.ts +++ b/src/app/pages/fee-grant/popup-add-grant/popup-add-grant.component.ts @@ -199,10 +199,10 @@ export class PopupAddGrantComponent implements OnInit { async executeGrant(granter: string, msg) { const multiplier = 1.7; // Grant multiplier - const fee = await this.walletService.estimateFee([msg], 'stargate', '', multiplier).catch(() => undefined); + const fee = await this.walletService.estimateFee([msg], 'cosmwasm', '', multiplier).catch(() => undefined); this.walletService - .signAndBroadcastStargate(granter, [msg], fee, '') + .signAndBroadcast(granter, [msg], fee, '') .then((result) => { this.closeDialog(result?.transactionHash); }) diff --git a/src/app/pages/fee-grant/popup-revoke/popup-revoke.component.ts b/src/app/pages/fee-grant/popup-revoke/popup-revoke.component.ts index 1b35c40af..447cfc63e 100644 --- a/src/app/pages/fee-grant/popup-revoke/popup-revoke.component.ts +++ b/src/app/pages/fee-grant/popup-revoke/popup-revoke.component.ts @@ -45,7 +45,7 @@ export class PopupRevokeComponent implements OnInit { }; const revokeMultiplier = 1.7; // revoke multiplier - NOT FOR ALL - const fee = await this.walletService.estimateFee([msg], 'stargate', '', revokeMultiplier).catch(() => undefined); + const fee = await this.walletService.estimateFee([msg], 'cosmwasm', '', revokeMultiplier).catch(() => undefined); this.walletService .signAndBroadcastStargate(account.address, [msg], fee, '') diff --git a/src/app/pages/proposal/proposal-vote/proposal-vote.component.ts b/src/app/pages/proposal/proposal-vote/proposal-vote.component.ts index 2e9691efa..81b444a13 100644 --- a/src/app/pages/proposal/proposal-vote/proposal-vote.component.ts +++ b/src/app/pages/proposal/proposal-vote/proposal-vote.component.ts @@ -61,7 +61,7 @@ export class ProposalVoteComponent { this.isLoading = true; const multiplier = 1.7; // multiplier - const fee = await this.walletService.estimateFee([msg], 'stargate', '', multiplier).catch(() => undefined); + const fee = await this.walletService.estimateFee([msg], 'cosmwasm', '', multiplier).catch(() => undefined); this.walletService .signAndBroadcast(account.address, [msg], fee) diff --git a/src/app/pages/validators/validators.component.ts b/src/app/pages/validators/validators.component.ts index 370785e52..35e6b4583 100644 --- a/src/app/pages/validators/validators.component.ts +++ b/src/app/pages/validators/validators.component.ts @@ -507,7 +507,6 @@ export class ValidatorsComponent implements OnInit, OnDestroy { this.walletService .delegateTokens(msg.delegatorAddress, msg.validatorAddress, msg.amount, 'auto') .then((broadcastResult) => { - console.log('🐛 broadcastResult: ', broadcastResult); let error = undefined; if (broadcastResult?.code != 0) { error = broadcastResult; @@ -537,7 +536,7 @@ export class ValidatorsComponent implements OnInit, OnDestroy { })); const revokeMultiplier = 1.7; // revoke multiplier - NOT FOR ALL - const fee = await this.walletService.estimateFee(msg, 'stargate', '', revokeMultiplier); + const fee = await this.walletService.estimateFee(msg, 'cosmwasm', '', revokeMultiplier); this.walletService .signAndBroadcast(this.userAddress, msg, fee || 'auto')