@subwallet/extension-base 1.3.8-0 → 1.3.10-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +4 -0
- package/cjs/core/logic-validation/transfer.js +35 -24
- package/cjs/core/substrate/system-pallet.js +1 -1
- package/cjs/core/utils.js +2 -2
- package/cjs/koni/background/handlers/Extension.js +116 -83
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/index.js +24 -2
- package/cjs/services/balance-service/transfer/smart-contract.js +16 -5
- package/cjs/services/chain-service/constants.js +5 -3
- package/cjs/services/chain-service/health-check/utils/new-utils/asset-asset-validate.js +1 -1
- package/cjs/services/swap-service/handler/asset-hub/utils.js +1 -0
- package/cjs/types/transaction/error.js +1 -0
- package/core/logic-validation/transfer.d.ts +2 -1
- package/core/logic-validation/transfer.js +36 -25
- package/core/substrate/system-pallet.js +1 -1
- package/core/types.d.ts +1 -0
- package/core/utils.js +2 -2
- package/koni/api/staking/bonding/utils.d.ts +1 -0
- package/koni/background/handlers/Extension.d.ts +2 -0
- package/koni/background/handlers/Extension.js +50 -18
- package/package.json +17 -17
- package/packageInfo.js +1 -1
- package/services/balance-service/index.d.ts +3 -0
- package/services/balance-service/index.js +21 -2
- package/services/balance-service/transfer/smart-contract.js +16 -5
- package/services/chain-service/constants.d.ts +1 -0
- package/services/chain-service/constants.js +3 -2
- package/services/chain-service/health-check/utils/new-utils/asset-asset-validate.js +1 -1
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +1 -0
- package/services/earning-service/handlers/special.d.ts +1 -0
- package/services/earning-service/utils/index.d.ts +1 -0
- package/services/swap-service/handler/asset-hub/utils.js +1 -0
- package/types/balance/index.d.ts +1 -0
- package/types/transaction/error.d.ts +2 -1
- package/types/transaction/error.js +1 -0
- package/types/yield/info/pallet.d.ts +1 -0
- package/utils/index.d.ts +1 -0
|
@@ -13,6 +13,7 @@ import { addLazy, createPromiseHandler, isAccountAll, waitTimeout } from '@subwa
|
|
|
13
13
|
import { getKeypairTypeByAddress } from '@subwallet/keyring';
|
|
14
14
|
import { EthereumKeypairTypes, SubstrateKeypairTypes } from '@subwallet/keyring/types';
|
|
15
15
|
import keyring from '@subwallet/ui-keyring';
|
|
16
|
+
import BigN from 'bignumber.js';
|
|
16
17
|
import { t } from 'i18next';
|
|
17
18
|
import { BehaviorSubject } from 'rxjs';
|
|
18
19
|
import { noop } from '@polkadot/util';
|
|
@@ -164,7 +165,7 @@ export class BalanceService {
|
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
/** Subscribe token free balance of an address on chain */
|
|
167
|
-
async
|
|
168
|
+
async subscribeBalance(address, chain, tokenSlug, balanceType = 'transferable', extrinsicType, callback) {
|
|
168
169
|
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
169
170
|
const chainState = this.state.chainService.getChainStateByKey(chain);
|
|
170
171
|
if (!chainInfo || !chainState || !chainState.active) {
|
|
@@ -193,10 +194,18 @@ export class BalanceService {
|
|
|
193
194
|
let unsub = noop;
|
|
194
195
|
unsub = subscribeBalance([address], [chain], [tSlug], assetMap, chainInfoMap, substrateApiMap, evmApiMap, tonApiMap, result => {
|
|
195
196
|
const rs = result[0];
|
|
197
|
+
let value;
|
|
198
|
+
switch (balanceType) {
|
|
199
|
+
case 'total':
|
|
200
|
+
value = new BigN(rs.free).plus(new BigN(rs.locked)).toFixed();
|
|
201
|
+
break;
|
|
202
|
+
default:
|
|
203
|
+
value = rs.free;
|
|
204
|
+
}
|
|
196
205
|
if (rs.tokenSlug === tSlug && rs.state !== APIItemState.PENDING) {
|
|
197
206
|
hasError = false;
|
|
198
207
|
const balance = {
|
|
199
|
-
value
|
|
208
|
+
value,
|
|
200
209
|
decimals: tokenInfo.decimals || 0,
|
|
201
210
|
symbol: tokenInfo.symbol,
|
|
202
211
|
metadata: rs.metadata
|
|
@@ -220,6 +229,12 @@ export class BalanceService {
|
|
|
220
229
|
}, 9999);
|
|
221
230
|
});
|
|
222
231
|
}
|
|
232
|
+
async subscribeTransferableBalance(address, chain, tokenSlug, extrinsicType, callback) {
|
|
233
|
+
return this.subscribeBalance(address, chain, tokenSlug, 'transferable', extrinsicType, callback);
|
|
234
|
+
}
|
|
235
|
+
async subscribeTotalBalance(address, chain, tokenSlug, extrinsicType, callback) {
|
|
236
|
+
return this.subscribeBalance(address, chain, tokenSlug, 'total', extrinsicType, callback);
|
|
237
|
+
}
|
|
223
238
|
|
|
224
239
|
/**
|
|
225
240
|
* @public
|
|
@@ -236,6 +251,10 @@ export class BalanceService {
|
|
|
236
251
|
const [, balance] = await this.subscribeTransferableBalance(address, chain, tokenSlug, extrinsicType);
|
|
237
252
|
return balance;
|
|
238
253
|
}
|
|
254
|
+
async getTotalBalance(address, chain, tokenSlug, extrinsicType) {
|
|
255
|
+
const [, balance] = await this.subscribeTotalBalance(address, chain, tokenSlug, extrinsicType);
|
|
256
|
+
return balance;
|
|
257
|
+
}
|
|
239
258
|
|
|
240
259
|
/** Remove balance from the subject object by addresses */
|
|
241
260
|
removeBalanceByAddresses(addresses) {
|
|
@@ -8,6 +8,7 @@ import { getWasmContractGasLimit } from '@subwallet/extension-base/koni/api/cont
|
|
|
8
8
|
import { EVM_REFORMAT_DECIMALS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
9
9
|
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
|
|
10
10
|
import BigN from 'bignumber.js';
|
|
11
|
+
import { t } from 'i18next';
|
|
11
12
|
export async function getEVMTransactionObject(chainInfo, from, to, value, transferAll, web3Api) {
|
|
12
13
|
var _priority$maxFeePerGa, _priority$maxPriority;
|
|
13
14
|
const networkKey = chainInfo.slug;
|
|
@@ -78,11 +79,21 @@ export async function getERC721Transaction(web3Api, chain, contractAddress, send
|
|
|
78
79
|
var _priority$maxFeePerGa3, _priority$maxPriority3;
|
|
79
80
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
80
81
|
const contract = new web3Api.api.eth.Contract(_ERC721_ABI, contractAddress);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
let gasLimit;
|
|
83
|
+
let priority;
|
|
84
|
+
try {
|
|
85
|
+
[gasLimit, priority] = await Promise.all([
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
87
|
+
contract.methods.safeTransferFrom(senderAddress, recipientAddress, tokenId).estimateGas({
|
|
88
|
+
from: senderAddress
|
|
89
|
+
}), calculateGasFeeParams(web3Api, chain)]);
|
|
90
|
+
} catch (e) {
|
|
91
|
+
const error = e;
|
|
92
|
+
if (error.message.includes('transfer to non ERC721Receiver implementer')) {
|
|
93
|
+
error.message = t('Unable to send. NFT not supported on recipient address');
|
|
94
|
+
}
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
86
97
|
return {
|
|
87
98
|
from: senderAddress,
|
|
88
99
|
gasPrice: priority.gasPrice,
|
|
@@ -245,12 +245,12 @@ export const _TRANSFER_CHAIN_GROUP = {
|
|
|
245
245
|
kintsugi: ['kintsugi', 'kintsugi_test', 'interlay', 'mangatax_para'],
|
|
246
246
|
genshiro: ['genshiro_testnet', 'genshiro', 'equilibrium_parachain'],
|
|
247
247
|
// crab: ['crab', 'pangolin'],
|
|
248
|
-
bitcountry: ['pioneer', 'bitcountry'
|
|
248
|
+
bitcountry: ['pioneer', 'bitcountry'],
|
|
249
249
|
statemine: ['statemint', 'statemine', 'darwinia2', 'astar', 'shiden', 'shibuya', 'parallel', 'liberland', 'liberlandTest', 'dentnet', 'dbcchain'],
|
|
250
250
|
riochain: ['riochain'],
|
|
251
251
|
sora_substrate: ['sora_substrate'],
|
|
252
252
|
avail: ['kate', 'goldberg_testnet'],
|
|
253
|
-
pendulum: ['pendulum', 'amplitude', 'amplitude_test', 'hydradx_main'],
|
|
253
|
+
pendulum: ['pendulum', 'amplitude', 'amplitude_test', 'hydradx_main', 'bifrost', 'bifrost_dot'],
|
|
254
254
|
centrifuge: ['centrifuge'],
|
|
255
255
|
disable_transfer: ['invarch', 'crab', 'pangolin']
|
|
256
256
|
};
|
|
@@ -270,6 +270,7 @@ export const _XCM_CHAIN_GROUP = {
|
|
|
270
270
|
// default is xTokens pallet
|
|
271
271
|
};
|
|
272
272
|
|
|
273
|
+
export const SUFFICIENT_CHAIN = ['astar', 'calamari', 'parallel', 'darwinia2', 'crabParachain', 'pangolin', 'statemint', 'moonriver', 'shiden', 'moonbeam', 'statemine', 'liberland', 'dentnet', 'phala', 'crust', 'dbcchain', 'rococo_assethub'];
|
|
273
274
|
export const _XCM_TYPE = {
|
|
274
275
|
RP: `${_SubstrateChainType.RELAYCHAIN}-${_SubstrateChainType.PARACHAIN}`,
|
|
275
276
|
// DMP
|
|
@@ -66,7 +66,7 @@ export function validateNativeLocalTransferMetadata(chainAsset) {
|
|
|
66
66
|
throw new Error(`Asset ${chainAsset.slug} is lack of metadata`);
|
|
67
67
|
}
|
|
68
68
|
const moonbeamGroup = ['moonbeam, moonbase, moonriver'];
|
|
69
|
-
const onChainInfoLocalGroup = [_TRANSFER_CHAIN_GROUP.centrifuge, ..._TRANSFER_CHAIN_GROUP.bitcountry, ..._TRANSFER_CHAIN_GROUP.acala, ..._TRANSFER_CHAIN_GROUP.kintsugi, 'pendulum', 'amplitude'];
|
|
69
|
+
const onChainInfoLocalGroup = [_TRANSFER_CHAIN_GROUP.centrifuge, ..._TRANSFER_CHAIN_GROUP.bitcountry, ..._TRANSFER_CHAIN_GROUP.acala, ..._TRANSFER_CHAIN_GROUP.kintsugi, 'pendulum', 'amplitude', 'bifrost', 'bifrost_dot'];
|
|
70
70
|
const onChainInfoNativeGroup = [_TRANSFER_CHAIN_GROUP.centrifuge, ..._TRANSFER_CHAIN_GROUP.acala, ..._TRANSFER_CHAIN_GROUP.kintsugi];
|
|
71
71
|
const assetIdLocalGroup = [..._TRANSFER_CHAIN_GROUP.statemine, ..._TRANSFER_CHAIN_GROUP.genshiro, ...moonbeamGroup, 'hydradx'];
|
|
72
72
|
const assetIdNativeGroup = [..._TRANSFER_CHAIN_GROUP.sora_substrate, 'hydradx'];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
3
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
3
4
|
import { ExtrinsicType, NominationInfo, UnstakingInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
2
3
|
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
4
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
2
3
|
import { LendingYieldPoolInfo, LiquidYieldPoolInfo, NativeYieldPoolInfo, NominationYieldPoolInfo, YieldAssetExpectedEarning, YieldCompoundingPeriod, YieldPoolInfo, YieldPoolType } from '@subwallet/extension-base/types';
|
|
3
4
|
import { BN } from '@polkadot/util';
|
|
@@ -7,6 +7,7 @@ import BigN from 'bignumber.js';
|
|
|
7
7
|
export const _getPoolInfo = async (api, asset1, asset2) => {
|
|
8
8
|
const assetLocation1 = _getXcmAssetMultilocation(asset1);
|
|
9
9
|
const assetLocation2 = _getXcmAssetMultilocation(asset2);
|
|
10
|
+
// @ts-ignore - Type auto detect incorrect
|
|
10
11
|
const rs = await api.call.assetConversionApi.getReserves(assetLocation1, assetLocation2);
|
|
11
12
|
if (!rs) {
|
|
12
13
|
return ['0', '0'];
|
package/types/balance/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
3
|
import { _BalanceMetadata, APIItemState, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
4
|
import { _EvmApi, _SubstrateApi, _TonApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
@@ -34,6 +34,7 @@ export declare enum TransferTxErrorType {
|
|
|
34
34
|
NOT_ENOUGH_FEE = "NOT_ENOUGH_FEE",
|
|
35
35
|
INVALID_TOKEN = "INVALID_TOKEN",
|
|
36
36
|
TRANSFER_ERROR = "TRANSFER_ERROR",
|
|
37
|
-
RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT = "RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT"
|
|
37
|
+
RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT = "RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT",
|
|
38
|
+
RECEIVER_ACCOUNT_INACTIVE = "RECEIVER_ACCOUNT_INACTIVE"
|
|
38
39
|
}
|
|
39
40
|
export declare type TransactionErrorType = BasicTxErrorType | TransferTxErrorType | StakingTxErrorType | YieldValidationStatus | SwapErrorType;
|
|
@@ -41,4 +41,5 @@ export let TransferTxErrorType;
|
|
|
41
41
|
TransferTxErrorType["INVALID_TOKEN"] = "INVALID_TOKEN";
|
|
42
42
|
TransferTxErrorType["TRANSFER_ERROR"] = "TRANSFER_ERROR";
|
|
43
43
|
TransferTxErrorType["RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT"] = "RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT";
|
|
44
|
+
TransferTxErrorType["RECEIVER_ACCOUNT_INACTIVE"] = "RECEIVER_ACCOUNT_INACTIVE";
|
|
44
45
|
})(TransferTxErrorType || (TransferTxErrorType = {}));
|
package/utils/index.d.ts
CHANGED