Skip to content

Commit

Permalink
Merge branch 'refs/heads/koni/dev/issue-2751' into web-runner-cron
Browse files Browse the repository at this point in the history
  • Loading branch information
bluezdot committed Nov 4, 2024
2 parents d389d86 + 9b1e794 commit b14c0ac
Show file tree
Hide file tree
Showing 90 changed files with 7,090 additions and 323 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@
"@polkadot/types-support": "^12.0.2",
"@polkadot/util": "^12.6.2",
"@polkadot/util-crypto": "^12.6.2",
"@subwallet/chain-list": "0.2.90",
"@subwallet/chain-list": "0.2.91",
"@subwallet/keyring": "^0.1.8-beta.0",
"@subwallet/react-ui": "5.1.2-b79",
"@subwallet/ui-keyring": "0.1.8-beta.0 ",
"@subwallet/ui-keyring": "0.1.8-beta.0",
"@zondax/ledger-substrate": "0.44.2",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^29.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@reduxjs/toolkit": "^1.9.1",
"@sora-substrate/type-definitions": "^1.17.7",
"@substrate/connect": "^0.8.9",
"@subwallet/chain-list": "0.2.90",
"@subwallet/chain-list": "0.2.91",
"@subwallet/extension-base": "^1.3.2-0",
"@subwallet/extension-chains": "^1.3.2-0",
"@subwallet/extension-dapp": "^1.3.2-0",
Expand Down
22 changes: 21 additions & 1 deletion packages/extension-base/src/background/KoniTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import { RequestOptimalTransferProcess } from '@subwallet/extension-base/service
import { TonTransactionConfig } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
import { _ChainState, _EvmApi, _NetworkUpsertParams, _SubstrateApi, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse, EnableChainParams, EnableMultiChainParams } from '@subwallet/extension-base/services/chain-service/types';
import { _NotificationInfo, NotificationSetup } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
import { AppBannerData, AppConfirmationData, AppPopupData } from '@subwallet/extension-base/services/mkt-campaign-service/types';
import { AuthUrls } from '@subwallet/extension-base/services/request-service/types';
import { CrowdloanContributionsResponse } from '@subwallet/extension-base/services/subscan-service/types';
import { SWTransactionResponse, SWTransactionResult } from '@subwallet/extension-base/services/transaction-service/types';
import { WalletConnectNotSupportRequest, WalletConnectSessionRequest } from '@subwallet/extension-base/services/wallet-connect-service/types';
import { AccountJson, AccountsWithCurrentAddress, AddressJson, BalanceJson, BaseRequestSign, BuyServiceInfo, BuyTokenInfo, CommonOptimalPath, CurrentAccountInfo, EarningRewardHistoryItem, EarningRewardJson, EarningStatus, HandleYieldStepParams, InternalRequestSign, LeavePoolAdditionalData, NominationPoolInfo, OptimalYieldPath, OptimalYieldPathParams, RequestAccountBatchExportV2, RequestAccountCreateSuriV2, RequestAccountNameValidate, RequestAccountProxyEdit, RequestAccountProxyForget, RequestBatchJsonGetAccountInfo, RequestBatchRestoreV2, RequestBounceableValidate, RequestChangeTonWalletContractVersion, RequestCheckCrossChainTransfer, RequestCheckPublicAndSecretKey, RequestCheckTransfer, RequestCrossChainTransfer, RequestDeriveCreateMultiple, RequestDeriveCreateV3, RequestDeriveValidateV2, RequestEarlyValidateYield, RequestExportAccountProxyMnemonic, RequestGetAllTonWalletContractVersion, RequestGetDeriveAccounts, RequestGetDeriveSuggestion, RequestGetYieldPoolTargets, RequestInputAccountSubscribe, RequestJsonGetAccountInfo, RequestJsonRestoreV2, RequestMetadataHash, RequestMnemonicCreateV2, RequestMnemonicValidateV2, RequestPrivateKeyValidateV2, RequestShortenMetadata, RequestStakeCancelWithdrawal, RequestStakeClaimReward, RequestTransfer, RequestUnlockDotCheckCanMint, RequestUnlockDotSubscribeMintedData, RequestYieldLeave, RequestYieldStepSubmit, RequestYieldWithdrawal, ResponseAccountBatchExportV2, ResponseAccountCreateSuriV2, ResponseAccountNameValidate, ResponseBatchJsonGetAccountInfo, ResponseCheckPublicAndSecretKey, ResponseDeriveValidateV2, ResponseEarlyValidateYield, ResponseExportAccountProxyMnemonic, ResponseGetAllTonWalletContractVersion, ResponseGetDeriveAccounts, ResponseGetDeriveSuggestion, ResponseGetYieldPoolTargets, ResponseInputAccountSubscribe, ResponseJsonGetAccountInfo, ResponseMetadataHash, ResponseMnemonicCreateV2, ResponseMnemonicValidateV2, ResponsePrivateKeyValidateV2, ResponseShortenMetadata, StorageDataInterface, SubmitYieldStepData, SwapPair, SwapQuoteResponse, SwapRequest, SwapRequestResult, SwapSubmitParams, SwapTxData, TokenSpendingApprovalParams, UnlockDotTransactionNft, UnstakingStatus, ValidateSwapProcessParams, ValidateYieldProcessParams, YieldPoolInfo, YieldPositionInfo } from '@subwallet/extension-base/types';
import { RequestClaimAvailBridge } from '@subwallet/extension-base/types/avail-bridge';
import { GetNotificationParams, RequestSwitchStatusParams } from '@subwallet/extension-base/types/notification';
import { InjectedAccount, InjectedAccountWithMeta, MetadataDefBase } from '@subwallet/extension-inject/types';
import { KeyringPair$Meta } from '@subwallet/keyring/types';
import { KeyringOptions } from '@subwallet/ui-keyring/options/types';
Expand Down Expand Up @@ -419,6 +422,7 @@ export interface UiSettings {
timeAutoLock: number;
unlockType: WalletUnlockType;
enableChainPatrol: boolean;
notificationSetup: NotificationSetup;
// On-ramp service account reference
walletReference: string;
}
Expand Down Expand Up @@ -505,6 +509,8 @@ export enum ExtrinsicType {

SWAP = 'swap',

CLAIM_AVAIL_BRIDGE = 'claim.claim_avail_bridge',

// SET_FEE_TOKEN = 'set_fee-token',

EVM_EXECUTE = 'evm.execute',
Expand Down Expand Up @@ -558,6 +564,8 @@ export interface ExtrinsicDataTypeMap {

[ExtrinsicType.TOKEN_SPENDING_APPROVAL]: TokenSpendingApprovalParams,

[ExtrinsicType.CLAIM_AVAIL_BRIDGE]: RequestClaimAvailBridge

[ExtrinsicType.EVM_EXECUTE]: TransactionConfig,
[ExtrinsicType.CROWDLOAN]: any,
[ExtrinsicType.SWAP]: SwapTxData
Expand Down Expand Up @@ -2049,6 +2057,7 @@ export interface KoniRequestSignatures {
'pri(settings.saveAutoLockTime)': [RequestChangeTimeAutoLock, boolean];
'pri(settings.saveUnlockType)': [RequestUnlockType, boolean];
'pri(settings.saveEnableChainPatrol)': [RequestChangeEnableChainPatrol, boolean];
'pri(settings.saveNotificationSetup)': [NotificationSetup, boolean]
'pri(settings.saveLanguage)': [RequestChangeLanguage, boolean];
'pri(settings.savePriceCurrency)': [RequestChangePriceCurrency, boolean];
'pri(settings.saveShowZeroBalance)': [RequestChangeShowZeroBalance, boolean];
Expand Down Expand Up @@ -2249,8 +2258,19 @@ export interface KoniRequestSignatures {
'pri(swapService.validateSwapProcess)': [ValidateSwapProcessParams, TransactionError[]];
/* Swap */

/* Ledger */
/* Notification Service */
'pri(inappNotification.subscribeUnreadNotificationCountMap)': [null, Record<string, number>, Record<string, number>];
'pri(inappNotification.markAllReadNotification)': [string, null];
'pri(inappNotification.switchReadNotificationStatus)': [RequestSwitchStatusParams, null];
'pri(inappNotification.fetch)': [GetNotificationParams, _NotificationInfo[]];
'pri(inappNotification.get)': [string, _NotificationInfo];
/* Notification Service */

/* Avail Bridge */
'pri(availBridge.submitClaimAvailBridgeOnAvail)': [RequestClaimAvailBridge, SWTransactionResponse]
/* Avail Bridge */

/* Ledger */
'pri(ledger.generic.allow)': [null, string[], string[]];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ interface BlockedActionsFeaturesMap {
blockedFeaturesList: string[],
}

const BLOCKED_ACTIONS_AND_FEATURES_PROMISE = fetchStaticData<BlockedActionsFeaturesMap>('blocked-actions-features');

export const fetchLastestBlockedActionsAndFeatures = async () => {
return await BLOCKED_ACTIONS_AND_FEATURES_PROMISE;
return await fetchStaticData<BlockedActionsFeaturesMap>('blocked-actions-features');
};
2 changes: 2 additions & 0 deletions packages/extension-base/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const MANTA_PAY_BALANCE_INTERVAL = 30000;
export const BITTENSOR_REFRESH_STAKE_INFO = 30000;
export const BITTENSOR_REFRESH_STAKE_APY = 300000;
export const CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL = 15 * BASE_MINUTE_INTERVAL;
export const CRON_LISTEN_AVAIL_BRIDGE_CLAIM = 1800000;

export const ALL_ACCOUNT_KEY = 'ALL';
export const ALL_NETWORK_KEY = 'all';
Expand Down Expand Up @@ -52,3 +53,4 @@ export * from './environment';
export * from './signing';
export * from './staking';
export * from './storage';
export * from './remind-notification-time';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { NotificationActionType } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
import { fetchStaticData } from '@subwallet/extension-base/utils';

export const fetchLastestRemindNotificationTime = async () => {
return await fetchStaticData<Record<NotificationActionType, number>>('config/remind-notification-time');
};
18 changes: 12 additions & 6 deletions packages/extension-base/src/core/logic-validation/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,22 @@ export async function estimateFeeForTransaction (validationResponse: SWTransacti
} else if (isTonTransaction(transaction)) {
estimateFee.value = transaction.estimateFee; // todo: might need to update logic estimate fee inside for future actions excluding normal transfer Ton and Jetton
} else {
const gasLimit = await evmApi.api.eth.estimateGas(transaction);
const gasLimit = transaction.gas || await evmApi.api.eth.estimateGas(transaction);

const priority = await calculateGasFeeParams(evmApi, chainInfo.slug);

if (priority.baseGasFee) {
const maxFee = priority.maxFeePerGas; // TODO: Need review

estimateFee.value = maxFee.multipliedBy(gasLimit).toFixed(0);
if (transaction.maxFeePerGas) {
estimateFee.value = new BigN(transaction.maxFeePerGas.toString()).multipliedBy(gasLimit).toFixed(0);
} else if (transaction.gasPrice) {
estimateFee.value = new BigN((transaction.gasPrice || 0).toString()).multipliedBy(gasLimit).toFixed(0);
} else {
estimateFee.value = new BigN(priority.gasPrice).multipliedBy(gasLimit).toFixed(0);
if (priority.baseGasFee) {
const maxFee = priority.maxFeePerGas; // TODO: Need review

estimateFee.value = maxFee.multipliedBy(gasLimit).toFixed(0);
} else {
estimateFee.value = new BigN(priority.gasPrice).multipliedBy(gasLimit).toFixed(0);
}
}

estimateFee.tooHigh = priority.busyNetwork;
Expand Down
16 changes: 15 additions & 1 deletion packages/extension-base/src/core/substrate/xcm-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
import { _Address } from '@subwallet/extension-base/background/KoniTypes';
import { isAvailChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
import { _getChainSubstrateAddressPrefix, _getEvmChainId, _getSubstrateParaId, _getSubstrateRelayParent, _getXcmAssetMultilocation, _isChainEvmCompatible, _isPureEvmChain, _isSubstrateParaChain } from '@subwallet/extension-base/services/chain-service/utils';

import { decodeAddress, evmToAddress } from '@polkadot/util-crypto';
Expand Down Expand Up @@ -90,8 +91,14 @@ function getMythosFromHydrationToMythosWarning (): string {
return 'Cross-chain transfer of this token requires a high transaction fee. Do you want to continue?';
}

function getAvailBridgeWarning (): string {
return 'Cross-chain transfer of this token may take up to 90 minutes, and you’ll need to manually claim the funds on the destination network to complete the transfer. Do you still want to continue?';
}

export function _getXcmUnstableWarning (originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, assetSlug: string): string {
if (_isSnowBridgeXcm(originChainInfo, destChainInfo)) {
if (_isAvailBridgeXcm(originChainInfo, destChainInfo)) {
return getAvailBridgeWarning();
} else if (_isSnowBridgeXcm(originChainInfo, destChainInfo)) {
return getSnowBridgeUnstableWarning(originChainInfo);
} else if (_isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug)) {
return getMythosFromHydrationToMythosWarning();
Expand All @@ -108,6 +115,13 @@ export function _isSnowBridgeXcm (originChainInfo: _ChainInfo, destChainInfo: _C
return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo) && (_isPureEvmChain(originChainInfo) || _isPureEvmChain(destChainInfo));
}

export function _isAvailBridgeXcm (originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean {
const isAvailBridgeFromEvm = _isPureEvmChain(originChainInfo) && isAvailChainBridge(destChainInfo.slug);
const isAvailBridgeFromAvail = isAvailChainBridge(originChainInfo.slug) && _isPureEvmChain(destChainInfo);

return isAvailBridgeFromEvm || isAvailBridgeFromAvail;
}

export function _isMythosFromHydrationToMythos (originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, assetSlug: string): boolean {
return originChainInfo.slug === 'hydradx_main' && destChainInfo.slug === 'mythos' && assetSlug === 'hydradx_main-LOCAL-MYTH';
}
Expand Down
Loading

0 comments on commit b14c0ac

Please sign in to comment.