Skip to content

Commit

Permalink
[Issue-3920] Rename interface & variables
Browse files Browse the repository at this point in the history
  • Loading branch information
PDTnhah committed Jan 6, 2025
1 parent 3a9322e commit 29edf3e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions packages/extension-base/src/background/KoniTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1711,9 +1711,9 @@ export interface RequestAddPspToken {

// Popular tokens

export interface PopularGroup {
export interface PrioritizedTokenList {
tokens: Record<string, number>,
piority: number
priority: number
}

/// WalletConnect
Expand Down Expand Up @@ -2307,7 +2307,7 @@ export interface KoniRequestSignatures {
/* Ledger */

/* Popular tokens */
'pri(popular.tokens)': [null, Record<string, PopularGroup>, Record<string, PopularGroup>];
'pri(popular.tokens)': [null, Record<string, PrioritizedTokenList>, Record<string, PrioritizedTokenList>];
/* Popular tokens */
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
import { createSubscription } from '@subwallet/extension-base/background/handlers/subscriptions';
import { AccountExternalError, AddressBookInfo, AmountData, AmountDataWithId, AssetSetting, AssetSettingUpdateReq, BondingOptionParams, BrowserConfirmationType, CampaignBanner, CampaignData, CampaignDataType, ChainType, CronReloadRequest, CrowdloanJson, ExternalRequestPromiseStatus, ExtrinsicType, KeyringState, MantaPayEnableMessage, MantaPayEnableParams, MantaPayEnableResponse, MantaPaySyncState, MetadataItem, NftCollection, NftJson, NftTransactionRequest, NftTransactionResponse, PopularGroup, PriceJson, RequestAccountCreateExternalV2, RequestAccountCreateHardwareMultiple, RequestAccountCreateHardwareV2, RequestAccountCreateWithSecretKey, RequestAccountExportPrivateKey, RequestAddInjectedAccounts, RequestApproveConnectWalletSession, RequestApproveWalletConnectNotSupport, RequestAuthorization, RequestAuthorizationBlock, RequestAuthorizationPerAccount, RequestAuthorizationPerSite, RequestAuthorizeApproveV2, RequestBondingSubmit, RequestCameraSettings, RequestCampaignBannerComplete, RequestChangeEnableChainPatrol, RequestChangeLanguage, RequestChangeMasterPassword, RequestChangePriceCurrency, RequestChangeShowBalance, RequestChangeShowZeroBalance, RequestChangeTimeAutoLock, RequestConfirmationComplete, RequestConfirmationCompleteTon, RequestConnectWalletConnect, RequestCrowdloanContributions, RequestDeleteContactAccount, RequestDisconnectWalletConnectSession, RequestEditContactAccount, RequestFindRawMetadata, RequestForgetSite, RequestFreeBalance, RequestGetTransaction, RequestKeyringExportMnemonic, RequestMaxTransferable, RequestMigratePassword, RequestParseEvmContractInput, RequestParseTransactionSubstrate, RequestPassPhishingPage, RequestQrParseRLP, RequestQrSignEvm, RequestQrSignSubstrate, RequestRejectConnectWalletSession, RequestRejectExternalRequest, RequestRejectWalletConnectNotSupport, RequestRemoveInjectedAccounts, RequestResetWallet, RequestResolveExternalRequest, RequestSaveAppConfig, RequestSaveBrowserConfig, RequestSaveOSConfig, RequestSaveRecentAccount, RequestSettingsType, RequestSigningApprovePasswordV2, RequestStakePoolingBonding, RequestStakePoolingUnbonding, RequestSubscribeHistory, RequestSubstrateNftSubmitTransaction, RequestTuringCancelStakeCompound, RequestTuringStakeCompound, RequestUnbondingSubmit, RequestUnlockKeyring, RequestUnlockType, ResolveAddressToDomainRequest, ResolveDomainRequest, ResponseAccountCreateWithSecretKey, ResponseAccountExportPrivateKey, ResponseChangeMasterPassword, ResponseFindRawMetadata, ResponseKeyringExportMnemonic, ResponseMigratePassword, ResponseNftImport, ResponseParseEvmContractInput, ResponseParseTransactionSubstrate, ResponseQrParseRLP, ResponseQrSignEvm, ResponseQrSignSubstrate, ResponseRejectExternalRequest, ResponseResetWallet, ResponseResolveExternalRequest, ResponseSubscribeHistory, ResponseUnlockKeyring, ShowCampaignPopupRequest, StakingJson, StakingRewardJson, StakingType, SufficientMetadata, ThemeNames, TransactionHistoryItem, TransactionResponse, ValidateNetworkRequest, ValidateNetworkResponse, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
import { AccountExternalError, AddressBookInfo, AmountData, AmountDataWithId, AssetSetting, AssetSettingUpdateReq, BondingOptionParams, BrowserConfirmationType, CampaignBanner, CampaignData, CampaignDataType, ChainType, CronReloadRequest, CrowdloanJson, ExternalRequestPromiseStatus, ExtrinsicType, KeyringState, MantaPayEnableMessage, MantaPayEnableParams, MantaPayEnableResponse, MantaPaySyncState, MetadataItem, NftCollection, NftJson, NftTransactionRequest, NftTransactionResponse, PrioritizedTokenList, PriceJson, RequestAccountCreateExternalV2, RequestAccountCreateHardwareMultiple, RequestAccountCreateHardwareV2, RequestAccountCreateWithSecretKey, RequestAccountExportPrivateKey, RequestAddInjectedAccounts, RequestApproveConnectWalletSession, RequestApproveWalletConnectNotSupport, RequestAuthorization, RequestAuthorizationBlock, RequestAuthorizationPerAccount, RequestAuthorizationPerSite, RequestAuthorizeApproveV2, RequestBondingSubmit, RequestCameraSettings, RequestCampaignBannerComplete, RequestChangeEnableChainPatrol, RequestChangeLanguage, RequestChangeMasterPassword, RequestChangePriceCurrency, RequestChangeShowBalance, RequestChangeShowZeroBalance, RequestChangeTimeAutoLock, RequestConfirmationComplete, RequestConfirmationCompleteTon, RequestConnectWalletConnect, RequestCrowdloanContributions, RequestDeleteContactAccount, RequestDisconnectWalletConnectSession, RequestEditContactAccount, RequestFindRawMetadata, RequestForgetSite, RequestFreeBalance, RequestGetTransaction, RequestKeyringExportMnemonic, RequestMaxTransferable, RequestMigratePassword, RequestParseEvmContractInput, RequestParseTransactionSubstrate, RequestPassPhishingPage, RequestQrParseRLP, RequestQrSignEvm, RequestQrSignSubstrate, RequestRejectConnectWalletSession, RequestRejectExternalRequest, RequestRejectWalletConnectNotSupport, RequestRemoveInjectedAccounts, RequestResetWallet, RequestResolveExternalRequest, RequestSaveAppConfig, RequestSaveBrowserConfig, RequestSaveOSConfig, RequestSaveRecentAccount, RequestSettingsType, RequestSigningApprovePasswordV2, RequestStakePoolingBonding, RequestStakePoolingUnbonding, RequestSubscribeHistory, RequestSubstrateNftSubmitTransaction, RequestTuringCancelStakeCompound, RequestTuringStakeCompound, RequestUnbondingSubmit, RequestUnlockKeyring, RequestUnlockType, ResolveAddressToDomainRequest, ResolveDomainRequest, ResponseAccountCreateWithSecretKey, ResponseAccountExportPrivateKey, ResponseChangeMasterPassword, ResponseFindRawMetadata, ResponseKeyringExportMnemonic, ResponseMigratePassword, ResponseNftImport, ResponseParseEvmContractInput, ResponseParseTransactionSubstrate, ResponseQrParseRLP, ResponseQrSignEvm, ResponseQrSignSubstrate, ResponseRejectExternalRequest, ResponseResetWallet, ResponseResolveExternalRequest, ResponseSubscribeHistory, ResponseUnlockKeyring, ShowCampaignPopupRequest, StakingJson, StakingRewardJson, StakingType, SufficientMetadata, ThemeNames, TransactionHistoryItem, TransactionResponse, ValidateNetworkRequest, ValidateNetworkResponse, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
import { AccountAuthType, AuthorizeRequest, MessageTypes, MetadataRequest, RequestAccountExport, RequestAuthorizeCancel, RequestAuthorizeReject, RequestCurrentAccountAddress, RequestMetadataApprove, RequestMetadataReject, RequestSigningApproveSignature, RequestSigningCancel, RequestTypes, ResponseAccountExport, ResponseAuthorizeList, ResponseType, SigningRequest, WindowOpenParams } from '@subwallet/extension-base/background/types';
import { TransactionWarning } from '@subwallet/extension-base/background/warnings/TransactionWarning';
import { ALL_ACCOUNT_KEY, LATEST_SESSION, XCM_FEE_RATIO } from '@subwallet/extension-base/constants';
Expand Down Expand Up @@ -3948,7 +3948,7 @@ export default class KoniExtension {

/* Popular tokens */

private subscribePopularTokens (id: string, port: chrome.runtime.Port): Record<string, PopularGroup> {
private subscribePopularTokens (id: string, port: chrome.runtime.Port): Record<string, PrioritizedTokenList> {
const cb = createSubscription<'pri(popular.tokens)'>(id, port);

const subscription = this.#koniState.chainService.observable.popularTokens.subscribe(cb);
Expand Down
8 changes: 4 additions & 4 deletions packages/extension-base/src/services/chain-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { AssetLogoMap, AssetRefMap, ChainAssetMap, ChainInfoMap, ChainLogoMap, MultiChainAssetMap } from '@subwallet/chain-list';
import { _AssetRef, _AssetRefPath, _AssetType, _ChainAsset, _ChainInfo, _ChainStatus, _EvmInfo, _MultiChainAsset, _SubstrateChainType, _SubstrateInfo, _TonInfo } from '@subwallet/chain-list/types';
import { AssetSetting, PopularGroup, ValidateNetworkResponse } from '@subwallet/extension-base/background/KoniTypes';
import { AssetSetting, PrioritizedTokenList, ValidateNetworkResponse } from '@subwallet/extension-base/background/KoniTypes';
import { _DEFAULT_ACTIVE_CHAINS, _ZK_ASSET_PREFIX, LATEST_CHAIN_DATA_FETCHING_INTERVAL } from '@subwallet/extension-base/services/chain-service/constants';
import { EvmChainHandler } from '@subwallet/extension-base/services/chain-service/handler/EvmChainHandler';
import { MantaPrivateHandler } from '@subwallet/extension-base/services/chain-service/handler/manta/MantaPrivateHandler';
Expand Down Expand Up @@ -92,7 +92,7 @@ export class ChainService {
private assetLogoMapSubject = new BehaviorSubject<Record<string, string>>(AssetLogoMap);
private chainLogoMapSubject = new BehaviorSubject<Record<string, string>>(ChainLogoMap);
private ledgerGenericAllowChainsSubject = new BehaviorSubject<string[]>([]);
private popularTokensSubject = new BehaviorSubject<Record<string, PopularGroup>>({});
private popularTokensSubject = new BehaviorSubject<Record<string, PrioritizedTokenList>>({});

// Todo: Update to new store indexed DB
private store: AssetSettingStore = new AssetSettingStore();
Expand Down Expand Up @@ -776,7 +776,7 @@ export class ChainService {
this.logger.log('Finished updating latest ledger generic allow chains');
}

handleLatestPopularTokens (latestPopularTokens: Record<string, PopularGroup>) {
handleLatestPopularTokens (latestPopularTokens: Record<string, PrioritizedTokenList>) {
this.popularTokensSubject.next(latestPopularTokens);
this.logger.log('Finished updating latest popular tokens');
}
Expand Down Expand Up @@ -1109,7 +1109,7 @@ export class ChainService {
}

private async fetchLatestPopularTokens () {
return await fetchStaticData<Record<string, PopularGroup>>('chain-assets/popular-tokens') || [];
return await fetchStaticData<Record<string, PrioritizedTokenList>>('chain-assets/popular-tokens') || [];
}

private async initChains () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { _ChainInfo } from '@subwallet/chain-list/types';
import { PopularGroup } from '@subwallet/extension-base/background/KoniTypes';
import { PrioritizedTokenList } from '@subwallet/extension-base/background/KoniTypes';
import { _ChainApiStatus, _ChainState } from '@subwallet/extension-base/services/chain-service/types';
import { ChainStore, ReduxStatus } from '@subwallet/extension-koni-ui/stores/types';

Expand Down Expand Up @@ -56,7 +56,7 @@ const chainStoreSlice = createSlice({
reduxStatus: ReduxStatus.READY
};
},
updatePopularTokens (state, action: PayloadAction<Record<string, PopularGroup>>) {
updatePopularTokens (state, action: PayloadAction<Record<string, PrioritizedTokenList>>) {
const { payload } = action;

return {
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-koni-ui/src/stores/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { _AssetRef, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';

Check failure on line 4 in packages/extension-koni-ui/src/stores/types.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Run autofix to sort these imports!
import { AddressBookState, AllLogoMap, AssetSetting, CampaignBanner, ChainStakingMetadata, ConfirmationDefinitions, ConfirmationsQueue, ConfirmationsQueueTon, ConfirmationType, CrowdloanItem, KeyringState, LanguageType, MantaPayConfig, NftCollection, NftItem, NominatorMetadata, PopularGroup, PriceJson, StakingItem, StakingRewardItem, TransactionHistoryItem, UiSettings, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
import { AddressBookState, AllLogoMap, AssetSetting, CampaignBanner, ChainStakingMetadata, ConfirmationDefinitions, ConfirmationsQueue, ConfirmationsQueueTon, ConfirmationType, CrowdloanItem, KeyringState, LanguageType, MantaPayConfig, NftCollection, NftItem, NominatorMetadata, PrioritizedTokenList, PriceJson, StakingItem, StakingRewardItem, TransactionHistoryItem, UiSettings, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
import { AccountsContext, AuthorizeRequest, MetadataRequest, SigningRequest } from '@subwallet/extension-base/background/types';
import { _ChainApiStatus, _ChainState } from '@subwallet/extension-base/services/chain-service/types';
import { AppBannerData, AppConfirmationData, AppPopupData } from '@subwallet/extension-base/services/mkt-campaign-service/types';
Expand Down Expand Up @@ -126,7 +126,7 @@ export interface ChainStore extends BaseReduxStore {
chainStateMap: Record<string, _ChainState>
chainStatusMap: Record<string, _ChainApiStatus>
ledgerGenericAllowNetworks: string[];
popularTokens: Record<string, PopularGroup>;
popularTokens: Record<string, PrioritizedTokenList>;
}

export interface BalanceStore extends BaseReduxStore {
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-koni-ui/src/stores/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { _AssetRef, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';

Check failure on line 4 in packages/extension-koni-ui/src/stores/utils/index.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Run autofix to sort these imports!
import { AddressBookInfo, AssetSetting, CampaignBanner, ChainStakingMetadata, ConfirmationsQueue, ConfirmationsQueueTon, CrowdloanJson, KeyringState, MantaPayConfig, MantaPaySyncState, NftCollection, NftJson, NominatorMetadata, PopularGroup, PriceJson, ShowCampaignPopupRequest, StakingJson, StakingRewardJson, TransactionHistoryItem, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
import { AddressBookInfo, AssetSetting, CampaignBanner, ChainStakingMetadata, ConfirmationsQueue, ConfirmationsQueueTon, CrowdloanJson, KeyringState, MantaPayConfig, MantaPaySyncState, NftCollection, NftJson, NominatorMetadata, PrioritizedTokenList, PriceJson, ShowCampaignPopupRequest, StakingJson, StakingRewardJson, TransactionHistoryItem, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
import { AccountsContext, AuthorizeRequest, ConfirmationRequestBase, MetadataRequest, SigningRequest } from '@subwallet/extension-base/background/types';
import { _ChainApiStatus, _ChainState } from '@subwallet/extension-base/services/chain-service/types';
import { AppBannerData, AppConfirmationData, AppPopupData } from '@subwallet/extension-base/services/mkt-campaign-service/types';
Expand Down Expand Up @@ -510,7 +510,7 @@ export const subscribeUnreadNotificationCount = lazySubscribeMessage('pri(inappN
/* Notification service */

/* Popular tokens */
export const updatePopularTokens = (data: Record<string, PopularGroup>) => {
export const updatePopularTokens = (data: Record<string, PrioritizedTokenList>) => {
store.dispatch({ type: 'chainStore/updatePopularTokens', payload: data });
};

Expand Down
34 changes: 17 additions & 17 deletions packages/extension-koni-ui/src/utils/sort/token.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright 2019-2022 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { PopularGroup } from '@subwallet/extension-base/background/KoniTypes';
import { PrioritizedTokenList } from '@subwallet/extension-base/background/KoniTypes';
import { BalanceValueInfo } from '@subwallet/extension-koni-ui/types';

export interface TokenSort {
export interface TokenAttributes {
slug: string,
symbol: string,
total?: BalanceValueInfo,
multiChainAsset?: string | null
}

export const sortTokenByValue = (a: TokenSort, b: TokenSort): number => {
export const sortTokenByValue = (a: TokenAttributes, b: TokenAttributes): number => {
if (a.total && b.total) {
const convertValue = b.total.convertedValue.minus(a.total.convertedValue).toNumber();

Expand All @@ -38,37 +38,37 @@ export const sortTokenAlphabetically = (a: string, b: string): number => {
}
};

export const sortByTokenPopularity = (a: string, b: string, aIsPiorityToken: boolean, bIsPiorityToken: boolean, aPiority: number, bPiority: number): number => {
if (aIsPiorityToken && !bIsPiorityToken) {
export const sortByTokenPopularity = (a: string, b: string, aIsPrioritizedToken: boolean, bIsPrioritizedToken: boolean, aPriority: number, bPriority: number): number => {
if (aIsPrioritizedToken && !bIsPrioritizedToken) {
return -1;
} else if (!aIsPiorityToken && bIsPiorityToken) {
} else if (!aIsPrioritizedToken && bIsPrioritizedToken) {
return 1;
} else if (!aIsPiorityToken && !bIsPiorityToken) {
} else if (!aIsPrioritizedToken && !bIsPrioritizedToken) {
return sortTokenAlphabetically(a, b);
} else {
if (aPiority < bPiority) {
if (aPriority < bPriority) {
return -1;
} else if (aPiority > bPiority) {
} else if (aPriority > bPriority) {
return 1;
} else {
return 0;
}
}
};

export function sortToken (tokenGroupSlug: TokenSort[], popularTokens: Record<string, PopularGroup>) {
export function sortToken (tokenGroupSlug: TokenAttributes[], popularTokens: Record<string, PrioritizedTokenList>) {
return tokenGroupSlug.sort((a, b) => {
const aBelongtoPiorityGroup = a.multiChainAsset ? Object.keys(popularTokens).includes(a.multiChainAsset) : false;
const bBelongtoPiorityGroup = b.multiChainAsset ? Object.keys(popularTokens).includes(b.multiChainAsset) : false;
const aBelongtoPrioritizedGroup = a.multiChainAsset ? Object.keys(popularTokens).includes(a.multiChainAsset) : false;
const bBelongtoPrioritizedGroup = b.multiChainAsset ? Object.keys(popularTokens).includes(b.multiChainAsset) : false;

const aIsPiorityToken = (aBelongtoPiorityGroup && a.multiChainAsset && Object.keys(popularTokens[a.multiChainAsset].tokens).includes(a.slug)) || Object.keys(popularTokens).includes(a.slug);
const bIsPiorityToken = (bBelongtoPiorityGroup && b.multiChainAsset && Object.keys(popularTokens[b.multiChainAsset].tokens).includes(b.slug)) || Object.keys(popularTokens).includes(b.slug);
const aIsPrioritizedToken = (aBelongtoPrioritizedGroup && a.multiChainAsset && Object.keys(popularTokens[a.multiChainAsset].tokens).includes(a.slug)) || Object.keys(popularTokens).includes(a.slug);
const bIsPrioritizedToken = (bBelongtoPrioritizedGroup && b.multiChainAsset && Object.keys(popularTokens[b.multiChainAsset].tokens).includes(b.slug)) || Object.keys(popularTokens).includes(b.slug);

const aHasBalance = (a.total && a.total.convertedValue.toNumber() !== 0) || (a.total && a.total.value.toNumber() !== 0);
const bHasBalance = (b.total && b.total.convertedValue.toNumber() !== 0) || (b.total && b.total.value.toNumber() !== 0);

const aPiority = a.multiChainAsset ? aIsPiorityToken ? (popularTokens[a.multiChainAsset].tokens)[a.slug] : 0 : aIsPiorityToken ? popularTokens[a.slug].piority : 0;
const bPiority = b.multiChainAsset ? bIsPiorityToken ? (popularTokens[b.multiChainAsset].tokens)[b.slug] : 0 : bIsPiorityToken ? popularTokens[b.slug].piority : 0;
const aPriority = a.multiChainAsset ? aIsPrioritizedToken ? (popularTokens[a.multiChainAsset].tokens)[a.slug] : 0 : aIsPrioritizedToken ? popularTokens[a.slug].priority : 0;
const bPriority = b.multiChainAsset ? bIsPrioritizedToken ? (popularTokens[b.multiChainAsset].tokens)[b.slug] : 0 : bIsPrioritizedToken ? popularTokens[b.slug].priority : 0;

if (aHasBalance && bHasBalance) {
return sortTokenByValue(a, b);
Expand All @@ -77,7 +77,7 @@ export function sortToken (tokenGroupSlug: TokenSort[], popularTokens: Record<st
} else if (!aHasBalance && bHasBalance) {
return 1;
} else {
return sortByTokenPopularity(a.symbol, b.symbol, aIsPiorityToken, bIsPiorityToken, aPiority, bPiority);
return sortByTokenPopularity(a.symbol, b.symbol, aIsPrioritizedToken, bIsPrioritizedToken, aPriority, bPriority);
}
});
}

0 comments on commit 29edf3e

Please sign in to comment.