Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions packages/extension-base/src/background/KoniTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
import { Resolver } from '@subwallet/extension-base/background/handlers/State';
import { AccountAuthType, AuthorizeRequest, ConfirmationRequestBase, RequestAccountList, RequestAccountSubscribe, RequestAccountUnsubscribe, RequestAuthorizeCancel, RequestAuthorizeReject, RequestAuthorizeSubscribe, RequestAuthorizeTab, RequestCurrentAccountAddress, ResponseAuthorizeList } from '@subwallet/extension-base/background/types';
import { AppConfig, BrowserConfig, OSConfig } from '@subwallet/extension-base/constants';
import { RequestOptimalTransferProcess } from '@subwallet/extension-base/services/balance-service/helpers';
import { CardanoBalanceItem } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/types';
import { CardanoTransactionConfig } from '@subwallet/extension-base/services/balance-service/transfer/cardano-transfer';
Expand All @@ -27,6 +26,7 @@
import { BitcoinAddressType, KeyringPair$Meta } from '@subwallet/keyring/types';
import { KeyringOptions } from '@subwallet/ui-keyring/options/types';
import { KeyringAddress } from '@subwallet/ui-keyring/types';
import { _SufficientChainsDetails, _TokenPriorityDetails, AppConfig, BrowserConfig, OSConfig } from '@subwallet-monorepos/subwallet-services-sdk/services';
import { SessionTypes } from '@walletconnect/types/dist/types/sign-client/session';
import BN from 'bn.js';
import { DexieExportJsonStructure } from 'dexie-export-import';
Expand Down Expand Up @@ -263,13 +263,13 @@
externalUrl?: string;
rarity?: string;
description?: string;
properties?: Record<any, any> | null;

Check warning on line 266 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type

Check warning on line 266 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
}

interface NftItemExtraInfo {
type?: _AssetType.ERC721 | _AssetType.PSP34 | RMRK_VER; // for sending
rmrk_ver?: RMRK_VER;
onChainOption?: any; // for sending PSP-34 tokens, should be done better

Check warning on line 272 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
assetHubType?: AssetHubNftType // for sending assetHub nft. There're 2 types nft
}

Expand Down Expand Up @@ -603,7 +603,7 @@
[ExtrinsicType.STAKING_COMPOUNDING]: RequestTuringStakeCompound,
[ExtrinsicType.STAKING_CANCEL_COMPOUNDING]: RequestTuringCancelStakeCompound,
[ExtrinsicType.STAKING_CANCEL_UNSTAKE]: RequestStakeCancelWithdrawal,
[ExtrinsicType.STAKING_POOL_WITHDRAW]: any,

Check warning on line 606 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type

// Yield
[ExtrinsicType.JOIN_YIELD_POOL]: RequestYieldStepSubmit,
Expand Down Expand Up @@ -634,9 +634,9 @@
[ExtrinsicType.CLAIM_BRIDGE]: RequestClaimBridge

[ExtrinsicType.EVM_EXECUTE]: TransactionConfig,
[ExtrinsicType.CROWDLOAN]: any,

Check warning on line 637 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
[ExtrinsicType.SWAP]: SwapTxData
[ExtrinsicType.UNKNOWN]: any

Check warning on line 639 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
}

export enum ExtrinsicStatus {
Expand Down Expand Up @@ -735,7 +735,7 @@
// : T extends ExtrinsicType.MINT_VDOT
// ? Pick<SubmitBifrostLiquidStaking, 'rewardTokenSlug' | 'estimatedAmountReceived'>
// : undefined;
export interface TransactionHistoryItem<ET extends ExtrinsicType = ExtrinsicType.TRANSFER_BALANCE> {

Check warning on line 738 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

'ET' is defined but never used
origin?: 'app' | 'migration' | 'subsquid' | 'subscan' | 'blockstream', // 'app' or history source
callhash?: string,
signature?: string,
Expand All @@ -761,7 +761,7 @@
tip?: AmountData,
fee?: AmountData,
explorerUrl?: string,
additionalInfo?: any,

Check warning on line 764 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
startBlock?: number,
nonce?: number,
addressPrefix?: number,
Expand Down Expand Up @@ -996,12 +996,12 @@
recipientAddress: string,

nftItemName?: string, // Use for confirmation view only
params: Record<string, any>,

Check warning on line 999 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
nftItem: NftItem
}

export interface EvmNftTransaction extends ValidateTransactionResponse {
tx: Record<string, any> | null;

Check warning on line 1004 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
}

export interface ValidateNetworkResponse {
Expand Down Expand Up @@ -2041,19 +2041,11 @@

// Popular tokens

export interface TokenPriorityDetails {
tokenGroup: Record<string, number>;
token: Record<string, number>
}
export type TokenPriorityDetails = _TokenPriorityDetails;

// Sufficient chains

export interface SufficientChainsDetails {
assetHubPallet: string[],
assetsPallet: string[],
foreignAssetsPallet: string[],
assetRegistryPallet: string[]
}
export type SufficientChainsDetails = _SufficientChainsDetails;

/// WalletConnect

Expand Down
54 changes: 1 addition & 53 deletions packages/extension-base/src/constants/blocked-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,32 @@
// SPDX-License-Identifier: Apache-2.0

import { packageInfo } from '@subwallet/extension-base';
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
import { fetchStaticData } from '@subwallet/extension-base/utils';
import { staticData, StaticKey } from '@subwallet/extension-base/utils/staticData';

export interface BlockedActionsFeaturesMap {
blockedActionsMap: Record<ExtrinsicType, string[]>,
blockedFeaturesList: string[]
}
import { BlockedConfigObjects, EnvConfig } from '@subwallet-monorepos/subwallet-services-sdk/services';

export const APP_ENV = process.env.TARGET_ENV as string;
export const APP_VER = packageInfo.version;

const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
const branchName = process.env.BRANCH_NAME || 'koni-dev';
const targetFolder = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'list' : 'preview';

export interface EnvConfig {
appConfig?: AppConfig,
browserConfig?: BrowserConfig,
osConfig?: OSConfig
}

// todo: check if can check exactly App Environment, Browser Type, OS Type

export interface AppConfig {
environment: string,
version?: string,
}

export interface BrowserConfig {
type: string,
version?: string
}

export interface OSConfig {
type: string,
version?: string
}

type BlockedConfigObjects = Record<string, EnvConfig>

export async function fetchBlockedConfigObjects (): Promise<BlockedConfigObjects> {
const targetFile = `${targetFolder}/envConfig.json`;

return await fetchStaticData<BlockedConfigObjects>('blocked-actions', targetFile);
}

export function getPassConfigId (currentConfig: EnvConfig, blockedConfigObjects: BlockedConfigObjects) {
const passList: string[] = [];

Object.entries(blockedConfigObjects).forEach(([key, appliedConfig]) => {

Check failure on line 13 in packages/extension-base/src/constants/blocked-actions.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unsafe argument of type `BlockedConfigObjects` assigned to a parameter of type `{ [s: string]: unknown; } | ArrayLike<unknown>`
let passAppConfig = false;
let passBrowserConfig = false;
let passOSConfig = false;

if (!appliedConfig.appConfig || !currentConfig.appConfig) {

Check failure on line 18 in packages/extension-base/src/constants/blocked-actions.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unsafe member access .appConfig on an `any` value
passAppConfig = true;
} else {
const isPassEnv = currentConfig.appConfig.environment === appliedConfig.appConfig.environment;

Check failure on line 21 in packages/extension-base/src/constants/blocked-actions.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unsafe member access .environment on an `any` value

Check failure on line 21 in packages/extension-base/src/constants/blocked-actions.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unsafe member access .appConfig on an `any` value
const isPassVer = isPassVersion(currentConfig.appConfig.version as string, appliedConfig.appConfig.version);

Check failure on line 22 in packages/extension-base/src/constants/blocked-actions.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unsafe member access .version on an `any` value

Check failure on line 22 in packages/extension-base/src/constants/blocked-actions.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unsafe argument of type `any` assigned to a parameter of type `string | undefined`

Check failure on line 22 in packages/extension-base/src/constants/blocked-actions.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unsafe member access .appConfig on an `any` value

passAppConfig = isPassEnv && isPassVer;
}

if (!appliedConfig.browserConfig || !currentConfig.browserConfig) {

Check failure on line 27 in packages/extension-base/src/constants/blocked-actions.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unsafe member access .browserConfig on an `any` value
passBrowserConfig = true;
} else {
const isPassType = currentConfig.browserConfig.type === appliedConfig.browserConfig.type;

Check failure on line 30 in packages/extension-base/src/constants/blocked-actions.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unsafe member access .type on an `any` value

Check failure on line 30 in packages/extension-base/src/constants/blocked-actions.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unsafe member access .browserConfig on an `any` value
const isPassVer = isPassVersion(currentConfig.browserConfig.version as string, appliedConfig.browserConfig.version);

passBrowserConfig = isPassType && isPassVer;
Expand Down Expand Up @@ -142,13 +100,3 @@

return versionStr === versionConditionStr;
}

export async function fetchLatestBlockedActionsAndFeatures (ids: string[]) {
if (ids.length === 0) {
return [staticData[StaticKey.BLOCKED_ACTIONS_FEATURES]];
}

const targetFiles = ids.map((id) => `${targetFolder}/${id}.json`);

return await Promise.all(targetFiles.map((targetFile) => fetchStaticData<BlockedActionsFeaturesMap>('blocked-actions', targetFile)));
}
3 changes: 3 additions & 0 deletions packages/extension-base/src/constants/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ export const APP_VERSION = process.env.PKG_VERSION || '';
export const isProductionMode = PRODUCTION_BRANCHES.indexOf(branchName) > -1;
export const BACKEND_API_URL = process.env.SUBWALLET_API || (isProductionMode ? 'https://sw-services.subwallet.app/api' : 'https://be-dev.subwallet.app/api');
export const SW_EXTERNAL_SERVICES_API = process.env.SW_EXTERNAL_SERVICES_API || (isProductionMode ? 'https://external-services.subwallet.app' : 'https://external-services-dev.subwallet.app');
export const STATIC_DATA_CACHING_API_URL = isProductionMode ? 'https://static-cache.subwallet.app' : 'https://dev.sw-static-cache.pages.dev';
export const STATIC_CONTENT_API_URL = 'https://static-data.subwallet.app';
export const CACHED_API_URL = isProductionMode ? 'https://api-cache.subwallet.app' : 'https://api-cache-dev.subwallet.app';
14 changes: 13 additions & 1 deletion packages/extension-base/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { CurrencyJson } from '@subwallet/extension-base/background/KoniTypes';
import { AccountAuthType } from '@subwallet/extension-base/background/types';

export const BASE_SECOND_INTERVAL = 1000;
Expand Down Expand Up @@ -53,6 +54,18 @@ export const _SUPPORT_TOKEN_PAY_FEE_GROUP = {
hydration: ['hydradx_main', 'hydradx_rococo']
};

export const CURRENCY_SYMBOL_RECORD: Record<string, CurrencyJson> = {
USD: { label: 'United States Dollar', symbol: '$', isPrefix: true },
BRL: { label: 'Brazilian Real', symbol: 'R$', isPrefix: true },
CNY: { label: 'Chinese Yuan', symbol: 'C¥', isPrefix: true },
EUR: { label: 'Euro', symbol: '€', isPrefix: true },
GBP: { label: 'British Pound Sterling', symbol: '£', isPrefix: true },
HKD: { label: 'Hong Kong Dollar', symbol: 'H$', isPrefix: true },
JPY: { label: 'Japanese Yen', symbol: '¥', isPrefix: true },
RUB: { label: 'Russian Ruble', symbol: '₽', isPrefix: true },
VND: { label: 'Vietnamese Dong', symbol: '₫', isPrefix: true }
};

export const getSupportTokenPayFeeChain = () => {
return Object.values(_SUPPORT_TOKEN_PAY_FEE_GROUP).flat();
};
Expand All @@ -72,5 +85,4 @@ export * from './environment';
export * from './signing';
export * from './staking';
export * from './storage';
export * from './remind-notification-time';
export * from './bitcoin';
8 changes: 0 additions & 8 deletions packages/extension-base/src/constants/paraspell-chain-map.ts

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions packages/extension-base/src/constants/staking.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { fetchStaticData } from '@subwallet/extension-base/utils';

export const PREDEFINED_STAKING_POOL: Record<string, number> = {
kusama: 80,
polkadot: 39,
Expand All @@ -13,11 +11,4 @@ export const PREDEFINED_STAKING_POOL: Record<string, number> = {

export const MAX_NOMINATIONS = '16';

export const PREDEFINED_EARNING_POOL_PROMISE = fetchStaticData<Record<string, number[]>>('nomination-pool-recommendation');

export type ChainRecommendValidator = {
maxCount: number;
preSelectValidators: string;
};

export const CRON_REFRESH_EARNING_TARGETS = 10 * 60 * 1000; // 10 minutes depends on cron run time on server
115 changes: 0 additions & 115 deletions packages/extension-base/src/koni/api/coingecko.ts

This file was deleted.

17 changes: 7 additions & 10 deletions packages/extension-base/src/koni/api/dotsama/crowdloan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ACALA_REFRESH_CROWDLOAN_INTERVAL } from '@subwallet/extension-base/cons
import registry from '@subwallet/extension-base/koni/api/dotsama/typeRegistry';
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
import { fetchJson, getAddressesByChainType, reformatAddress } from '@subwallet/extension-base/utils';
import { fetchStaticData } from '@subwallet/extension-base/utils/fetchStaticData';
import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';

import { DeriveOwnContributions } from '@polkadot/api-derive/types';
import { BN } from '@polkadot/util';
Expand Down Expand Up @@ -36,13 +36,6 @@ function getChainInfoMap (chainInfoList: _ChainInfo[]): Record<string, _ChainInf
return result;
}

const getOnlineFundList = fetchStaticData<CrowdloanFundInfo[]>('crowdloan-funds');
const getOnlineChainInfoMap = (async () => {
const chainInfoList = await fetchStaticData<_ChainInfo[]>('chains');

return getChainInfoMap(chainInfoList);
})();

function getRPCCrowdloan (parentAPI: _SubstrateApi, fundInfo: _CrowdloanFund, hexAddresses: string[], callback: (rs: CrowdloanItem) => void) {
const { auctionIndex, endTime, firstPeriod, fundId, lastPeriod, paraId, startTime, status } = fundInfo;
const unsubPromise = parentAPI.api.derive.crowdloan.ownContributions(paraId, hexAddresses, (result: DeriveOwnContributions) => {
Expand Down Expand Up @@ -163,8 +156,12 @@ function isNeedToUpdateLatestFundInfoMap (latestMap: Record<string, CrowdloanFun
export async function subscribeCrowdloan (addresses: string[], substrateApiMap: Record<string, _SubstrateApi>, callback: (networkKey: string, rs: CrowdloanItem) => void) {
const unsubMap: Record<string, any> = {};
const latestMap: Record<string, CrowdloanFundInfo> = {};
const rawFundList = await getOnlineFundList;
const chainInfoMap = await getOnlineChainInfoMap;
const rawFundList = await subwalletApiSdk.staticContentApi.fetchCrowdloanFundList();
const chainInfoMap = await (async () => {
const chainInfoList = await subwalletApiSdk.staticContentApi.fetchLatestChainData();

return getChainInfoMap(chainInfoList);
})();

rawFundList.forEach((fundInfo) => {
const chainSlug = fundInfo.chain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { withErrorLog } from '@subwallet/extension-base/background/handlers/help
import { isSubscriptionRunning, unsubscribe } from '@subwallet/extension-base/background/handlers/subscriptions';
import { AddressCardanoTransactionBalance, AddTokenRequestExternal, AmountData, APIItemState, ApiMap, AuthRequestV2, BitcoinProviderErrorType, BitcoinSendTransactionParams, BitcoinSendTransactionRequest, BitcoinSignatureRequest, BitcoinSignMessageParams, BitcoinSignMessageResult, BitcoinSignPsbtParams, BitcoinSignPsbtRequest, BitcoinSignPsbtResult, CardanoKeyType, CardanoProviderErrorType, CardanoSignatureRequest, CardanoTransactionDappConfig, ChainStakingMetadata, ChainType, ConfirmationsQueue, ConfirmationsQueueBitcoin, ConfirmationsQueueCardano, ConfirmationsQueueTon, ConfirmationType, CrowdloanItem, CrowdloanJson, CurrencyType, EvmProviderErrorType, EvmSendTransactionParams, EvmSendTransactionRequest, EvmSignatureRequest, ExternalRequestPromise, ExternalRequestPromiseStatus, ExtrinsicType, MantaAuthorizationContext, MantaPayConfig, MantaPaySyncState, NftCollection, NftItem, NftJson, NominatorMetadata, PsbtTransactionArg, RequestAccountExportPrivateKey, RequestCardanoSignData, RequestCardanoSignTransaction, RequestConfirmationComplete, RequestConfirmationCompleteBitcoin, RequestConfirmationCompleteCardano, RequestConfirmationCompleteTon, RequestCrowdloanContributions, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCardanoSignData, ResponseCardanoSignTransaction, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
import { RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning } from '@subwallet/extension-base/background/types';
import { EnvConfig, MANTA_PAY_BALANCE_INTERVAL, REMIND_EXPORT_ACCOUNT } from '@subwallet/extension-base/constants';
import { MANTA_PAY_BALANCE_INTERVAL, REMIND_EXPORT_ACCOUNT } from '@subwallet/extension-base/constants';
import { convertErrorFormat, generateValidationProcess, PayloadValidated, ValidateStepFunction, validationAuthCardanoMiddleware, validationAuthMiddleware, validationAuthWCMiddleware, validationBitcoinConnectMiddleware, validationBitcoinSendTransactionMiddleware, validationBitcoinSignMessageMiddleware, validationBitcoinSignPsbtMiddleware, validationCardanoSignDataMiddleware, validationConnectMiddleware, validationEvmDataTransactionMiddleware, validationEvmSignMessageMiddleware } from '@subwallet/extension-base/core/logic-validation';
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
Expand Down Expand Up @@ -52,6 +52,7 @@ import { convertCardanoHexToBech32, validateAddressNetwork } from '@subwallet/ex
import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
import { MetadataDef, ProviderMeta } from '@subwallet/extension-inject/types';
import { keyring } from '@subwallet/ui-keyring';
import { EnvConfig } from '@subwallet-monorepos/subwallet-services-sdk/services';
import BigN from 'bignumber.js';
import * as bitcoin from 'bitcoinjs-lib';
import BN from 'bn.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-base/src/services/balance-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ export class BalanceService implements StoppableServiceInterface {
const typeValid = [...EthereumKeypairTypes].includes(type);

if (typeValid) {
return subwalletApiSdk.balanceDetectionApi.getSubWalletTokenBalance(address)
return subwalletApiSdk.balanceDetectionApi.getSwEvmTokenBalance(address)
.catch((e) => {
console.error(e);

Expand Down Expand Up @@ -726,7 +726,7 @@ export class BalanceService implements StoppableServiceInterface {
public async evmDetectBalanceToken (addresses: string[]) {
const assetMap = this.state.chainService.getAssetRegistry();
const evmPromiseList = addresses.map((address) => {
return subwalletApiSdk.balanceDetectionApi.getSubWalletTokenBalance(address)
return subwalletApiSdk.balanceDetectionApi.getSwEvmTokenBalance(address)
.catch((e) => {
console.error(e);

Expand Down
Loading