@subwallet/extension-base 1.0.5-2 → 1.0.6-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 +7 -1
- package/cjs/constants/index.js +1 -1
- package/cjs/koni/api/staking/bonding/relayChain.js +2 -7
- package/cjs/koni/api/staking/bonding/utils.js +9 -0
- package/cjs/koni/api/staking/index.js +6 -3
- package/cjs/koni/api/staking/relayChain.js +16 -14
- package/cjs/koni/background/handlers/Extension.js +60 -46
- package/cjs/koni/background/handlers/State.js +16 -0
- package/cjs/koni/background/handlers/Tabs.js +47 -28
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +3 -3
- package/cjs/services/chain-service/index.js +5 -0
- package/cjs/services/chain-service/utils.js +15 -10
- package/cjs/services/history-service/subsquid-multi-chain-history.js +2 -2
- package/cjs/services/request-service/index.js +3 -0
- package/cjs/services/setting-service/SettingService.js +14 -0
- package/cjs/services/storage-service/DatabaseService.js +1 -1
- package/cjs/services/storage-service/db-stores/Nft.js +3 -3
- package/cjs/services/transaction-service/index.js +11 -5
- package/cjs/services/transaction-service/utils.js +3 -0
- package/cjs/stores/PassPhishingStore.js +18 -0
- package/constants/index.d.ts +1 -1
- package/constants/index.js +1 -1
- package/koni/api/staking/bonding/relayChain.js +3 -8
- package/koni/api/staking/bonding/utils.d.ts +1 -0
- package/koni/api/staking/bonding/utils.js +8 -0
- package/koni/api/staking/index.js +6 -4
- package/koni/api/staking/relayChain.js +16 -14
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +61 -48
- package/koni/background/handlers/State.d.ts +1 -0
- package/koni/background/handlers/State.js +16 -0
- package/koni/background/handlers/Tabs.d.ts +2 -0
- package/koni/background/handlers/Tabs.js +47 -28
- package/package.json +11 -6
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.js +3 -3
- package/services/chain-service/index.js +5 -0
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +14 -10
- package/services/history-service/subsquid-multi-chain-history.js +2 -2
- package/services/request-service/handler/AuthRequestHandler.d.ts +1 -1
- package/services/request-service/index.d.ts +1 -0
- package/services/request-service/index.js +3 -0
- package/services/setting-service/SettingService.d.ts +5 -1
- package/services/setting-service/SettingService.js +14 -0
- package/services/storage-service/DatabaseService.js +1 -1
- package/services/storage-service/db-stores/Nft.d.ts +1 -1
- package/services/storage-service/db-stores/Nft.js +3 -3
- package/services/transaction-service/index.js +11 -5
- package/services/transaction-service/types.d.ts +3 -3
- package/services/transaction-service/utils.js +3 -0
- package/stores/PassPhishingStore.d.ts +5 -0
- package/stores/PassPhishingStore.js +10 -0
|
@@ -1075,7 +1075,6 @@ export interface ChainStakingMetadata {
|
|
|
1075
1075
|
minJoinNominationPool?: string;
|
|
1076
1076
|
minStake: string;
|
|
1077
1077
|
nominatorCount?: number;
|
|
1078
|
-
minPoolBonding?: string;
|
|
1079
1078
|
maxValidatorPerNominator: number;
|
|
1080
1079
|
maxWithdrawalRequestPerValidator: number;
|
|
1081
1080
|
allowCancelUnstaking: boolean;
|
|
@@ -1384,6 +1383,12 @@ export interface AllLogoMap {
|
|
|
1384
1383
|
chainLogoMap: Record<string, string>;
|
|
1385
1384
|
assetLogoMap: Record<string, string>;
|
|
1386
1385
|
}
|
|
1386
|
+
export interface PassPhishing {
|
|
1387
|
+
pass: boolean;
|
|
1388
|
+
}
|
|
1389
|
+
export interface RequestPassPhishingPage {
|
|
1390
|
+
url: string;
|
|
1391
|
+
}
|
|
1387
1392
|
export interface KoniRequestSignatures {
|
|
1388
1393
|
'pri(staking.submitTuringCancelCompound)': [RequestTuringCancelStakeCompound, SWTransactionResponse];
|
|
1389
1394
|
'pri(staking.submitTuringCompound)': [RequestTuringStakeCompound, SWTransactionResponse];
|
|
@@ -1437,6 +1442,7 @@ export interface KoniRequestSignatures {
|
|
|
1437
1442
|
'pri(balance.getSubscription)': [RequestSubscribeBalance, BalanceJson, BalanceJson];
|
|
1438
1443
|
'pri(crowdloan.getCrowdloan)': [RequestCrowdloan, CrowdloanJson];
|
|
1439
1444
|
'pri(crowdloan.getSubscription)': [RequestSubscribeCrowdloan, CrowdloanJson, CrowdloanJson];
|
|
1445
|
+
'pri(phishing.pass)': [RequestPassPhishingPage, boolean];
|
|
1440
1446
|
'pri(authorize.listV2)': [null, ResponseAuthorizeList];
|
|
1441
1447
|
'pri(authorize.requestsV2)': [RequestAuthorizeSubscribe, boolean, AuthorizeRequest[]];
|
|
1442
1448
|
'pri(authorize.approveV2)': [RequestAuthorizeApproveV2, boolean];
|
package/cjs/constants/index.js
CHANGED
|
@@ -56,7 +56,7 @@ const CRON_REFRESH_NFT_INTERVAL = 7200000;
|
|
|
56
56
|
exports.CRON_REFRESH_NFT_INTERVAL = CRON_REFRESH_NFT_INTERVAL;
|
|
57
57
|
const CRON_REFRESH_STAKING_REWARD_INTERVAL = 900000;
|
|
58
58
|
exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = CRON_REFRESH_STAKING_REWARD_INTERVAL;
|
|
59
|
-
const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL =
|
|
59
|
+
const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = 45000;
|
|
60
60
|
exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL;
|
|
61
61
|
const CRON_REFRESH_HISTORY_INTERVAL = 900000;
|
|
62
62
|
exports.CRON_REFRESH_HISTORY_INTERVAL = CRON_REFRESH_HISTORY_INTERVAL;
|
|
@@ -34,7 +34,7 @@ function validateRelayUnbondingCondition(amount, chainStakingMetadata, nominator
|
|
|
34
34
|
const errors = [];
|
|
35
35
|
const bnActiveStake = new _util.BN(nominatorMetadata.activeStake);
|
|
36
36
|
const bnRemainingStake = bnActiveStake.sub(new _util.BN(amount));
|
|
37
|
-
const minStake = new _util.BN(chainStakingMetadata.
|
|
37
|
+
const minStake = new _util.BN(chainStakingMetadata.minJoinNominationPool || '0');
|
|
38
38
|
if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(minStake))) {
|
|
39
39
|
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.INVALID_ACTIVE_STAKE));
|
|
40
40
|
}
|
|
@@ -48,7 +48,7 @@ function validatePoolBondingCondition(chainInfo, amount, selectedPool, address,
|
|
|
48
48
|
// amount >= min stake
|
|
49
49
|
const errors = [];
|
|
50
50
|
let bnTotalStake = new _util.BN(amount);
|
|
51
|
-
const bnMinStake = new _util.BN(chainStakingMetadata.
|
|
51
|
+
const bnMinStake = new _util.BN(chainStakingMetadata.minJoinNominationPool || '0');
|
|
52
52
|
if (selectedPool.state !== 'Open') {
|
|
53
53
|
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.INACTIVE_NOMINATION_POOL));
|
|
54
54
|
}
|
|
@@ -90,9 +90,6 @@ function validateRelayBondingCondition(chainInfo, amount, selectedValidators, ad
|
|
|
90
90
|
async function getRelayChainStakingMetadata(chainInfo, substrateApi) {
|
|
91
91
|
var _chainApi$api$query$a, _chainApi$api$query, _chainApi$api$query$s, _chainApi$api$query2, _chainApi$api$query2$, _chainApi$api$query3, _chainApi$api$query3$;
|
|
92
92
|
const chain = chainInfo.slug;
|
|
93
|
-
const {
|
|
94
|
-
decimals
|
|
95
|
-
} = (0, _utils2._getChainNativeTokenBasicInfo)(chainInfo);
|
|
96
93
|
const chainApi = await substrateApi.isReady;
|
|
97
94
|
const _era = await chainApi.api.query.staking.currentEra();
|
|
98
95
|
const currentEra = _era.toString();
|
|
@@ -136,8 +133,6 @@ async function getRelayChainStakingMetadata(chainInfo, substrateApi) {
|
|
|
136
133
|
// in %, annually
|
|
137
134
|
inflation,
|
|
138
135
|
minStake: minStake.toString(),
|
|
139
|
-
minPoolBonding: (10 ** decimals).toString(),
|
|
140
|
-
// default is 1
|
|
141
136
|
maxValidatorPerNominator: parseInt(maxNominations),
|
|
142
137
|
maxWithdrawalRequestPerValidator: parseInt(maxUnlockingChunks),
|
|
143
138
|
allowCancelUnstaking: true,
|
|
@@ -17,6 +17,7 @@ exports.getParaCurrentInflation = getParaCurrentInflation;
|
|
|
17
17
|
exports.getStakingAvailableActionsByChain = getStakingAvailableActionsByChain;
|
|
18
18
|
exports.getStakingAvailableActionsByNominator = getStakingAvailableActionsByNominator;
|
|
19
19
|
exports.getStakingStatusByNominations = getStakingStatusByNominations;
|
|
20
|
+
exports.getValidatorLabel = getValidatorLabel;
|
|
20
21
|
exports.getWithdrawalInfo = getWithdrawalInfo;
|
|
21
22
|
exports.isActionFromValidator = isActionFromValidator;
|
|
22
23
|
exports.isShowNominationByValidator = isShowNominationByValidator;
|
|
@@ -268,4 +269,12 @@ function getStakingStatusByNominations(bnTotalActiveStake, nominationList) {
|
|
|
268
269
|
}
|
|
269
270
|
}
|
|
270
271
|
return stakingStatus;
|
|
272
|
+
}
|
|
273
|
+
function getValidatorLabel(chain) {
|
|
274
|
+
if (_constants._STAKING_CHAIN_GROUP.astar.includes(chain)) {
|
|
275
|
+
return 'dApp';
|
|
276
|
+
} else if (_constants._STAKING_CHAIN_GROUP.relay.includes(chain)) {
|
|
277
|
+
return 'Validator';
|
|
278
|
+
}
|
|
279
|
+
return 'Collator';
|
|
271
280
|
}
|
|
@@ -67,11 +67,14 @@ async function getNominationStakingRewardData(addresses, chainInfoMap) {
|
|
|
67
67
|
}
|
|
68
68
|
async function getPoolingStakingRewardData(addresses, networkMap, dotSamaApiMap) {
|
|
69
69
|
const activeNetworks = [];
|
|
70
|
-
Object.
|
|
71
|
-
|
|
70
|
+
Object.entries(networkMap).forEach(_ref3 => {
|
|
71
|
+
let [key, chainInfo] = _ref3;
|
|
72
|
+
if ((0, _utils._isChainSupportSubstrateStaking)(chainInfo) && (0, _utils._isSubstrateRelayChain)(chainInfo)) {
|
|
73
|
+
activeNetworks.push(key);
|
|
74
|
+
}
|
|
72
75
|
});
|
|
73
76
|
if (activeNetworks.length === 0) {
|
|
74
77
|
return [];
|
|
75
78
|
}
|
|
76
|
-
return
|
|
79
|
+
return (0, _relayChain.getNominationPoolReward)(addresses, networkMap, dotSamaApiMap);
|
|
77
80
|
}
|
|
@@ -148,20 +148,22 @@ async function getNominationPoolReward(addresses, chainInfoMap, substrateApiMap)
|
|
|
148
148
|
try {
|
|
149
149
|
await Promise.all(targetNetworks.map(async networkKey => {
|
|
150
150
|
const substrateApi = await substrateApiMap[networkKey].isReady;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
151
|
+
if (substrateApi.api.call.nominationPoolsApi) {
|
|
152
|
+
await Promise.all(validAddresses.map(async address => {
|
|
153
|
+
var _substrateApi$api$cal, _substrateApi$api$cal2;
|
|
154
|
+
const _unclaimedReward = await ((_substrateApi$api$cal = substrateApi.api.call) === null || _substrateApi$api$cal === void 0 ? void 0 : (_substrateApi$api$cal2 = _substrateApi$api$cal.nominationPoolsApi) === null || _substrateApi$api$cal2 === void 0 ? void 0 : _substrateApi$api$cal2.pendingRewards(address));
|
|
155
|
+
if (_unclaimedReward) {
|
|
156
|
+
rewardList.push({
|
|
157
|
+
address: address,
|
|
158
|
+
chain: networkKey,
|
|
159
|
+
unclaimedReward: _unclaimedReward.toString(),
|
|
160
|
+
name: chainInfoMap[networkKey].name,
|
|
161
|
+
state: _KoniTypes.APIItemState.READY,
|
|
162
|
+
type: _KoniTypes.StakingType.POOLED
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
165
167
|
}));
|
|
166
168
|
} catch (e) {
|
|
167
169
|
return rewardList;
|
|
@@ -1446,7 +1446,8 @@ class KoniExtension {
|
|
|
1446
1446
|
|
|
1447
1447
|
// Get native token amount
|
|
1448
1448
|
const freeBalance = await this.#koniState.balanceService.getTokenFreeBalance(from, networkKey, tokenSlug);
|
|
1449
|
-
if ((0, _utilCrypto.isEthereumAddress)(from) && (0, _utilCrypto.isEthereumAddress)(to)) {
|
|
1449
|
+
if ((0, _utilCrypto.isEthereumAddress)(from) && (0, _utilCrypto.isEthereumAddress)(to) && (0, _utils._isTokenTransferredByEvm)(tokenInfo)) {
|
|
1450
|
+
// TODO: review this
|
|
1450
1451
|
chainType = _KoniTypes.ChainType.EVM;
|
|
1451
1452
|
const txVal = transferAll ? freeBalance.value : value || '0';
|
|
1452
1453
|
|
|
@@ -1640,61 +1641,60 @@ class KoniExtension {
|
|
|
1640
1641
|
const substrateApi = this.#koniState.chainService.getSubstrateApi(networkKey);
|
|
1641
1642
|
let estimatedFee;
|
|
1642
1643
|
let maxTransferable = new _util.BN(freeBalance.value);
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
const mockTx = await (0, _xcm.createXcmExtrinsic)({
|
|
1651
|
-
chainInfoMap,
|
|
1652
|
-
destinationTokenInfo,
|
|
1653
|
-
originTokenInfo: tokenInfo,
|
|
1654
|
-
recipient: address,
|
|
1655
|
-
sendingValue: '0',
|
|
1656
|
-
substrateApi
|
|
1657
|
-
});
|
|
1658
|
-
try {
|
|
1644
|
+
try {
|
|
1645
|
+
if (isXcmTransfer) {
|
|
1646
|
+
const chainInfoMap = this.#koniState.chainService.getChainInfoMap();
|
|
1647
|
+
const destinationTokenInfo = this.#koniState.getXcmEqualAssetByChain(destChain, tokenInfo.slug);
|
|
1648
|
+
if (!destinationTokenInfo) {
|
|
1649
|
+
estimatedFee = '0';
|
|
1650
|
+
} else {
|
|
1659
1651
|
var _paymentInfo$partialF;
|
|
1652
|
+
maxTransferable = maxTransferable.sub(new _util.BN(tokenInfo.minAmount || '0'));
|
|
1653
|
+
const desChainInfo = chainInfoMap[destChain];
|
|
1654
|
+
const orgChainInfo = chainInfoMap[networkKey];
|
|
1655
|
+
const recipient = !(0, _utilCrypto.isEthereumAddress)(address) && (0, _utils._isChainEvmCompatible)(desChainInfo) && !(0, _utils._isChainEvmCompatible)(orgChainInfo) ? (0, _util.u8aToHex)((0, _utilCrypto.addressToEvm)(address)) : address;
|
|
1656
|
+
const mockTx = await (0, _xcm.createXcmExtrinsic)({
|
|
1657
|
+
chainInfoMap,
|
|
1658
|
+
destinationTokenInfo,
|
|
1659
|
+
originTokenInfo: tokenInfo,
|
|
1660
|
+
recipient: recipient,
|
|
1661
|
+
sendingValue: '0',
|
|
1662
|
+
substrateApi
|
|
1663
|
+
});
|
|
1660
1664
|
const paymentInfo = await mockTx.paymentInfo(address);
|
|
1661
1665
|
estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF = paymentInfo.partialFee) === null || _paymentInfo$partialF === void 0 ? void 0 : _paymentInfo$partialF.toString()) || '0';
|
|
1662
|
-
} catch (e) {
|
|
1663
|
-
estimatedFee = '0';
|
|
1664
|
-
console.warn(e);
|
|
1665
1666
|
}
|
|
1666
|
-
}
|
|
1667
|
-
} else {
|
|
1668
|
-
const chainInfo = this.#koniState.chainService.getChainInfoByKey(networkKey);
|
|
1669
|
-
if ((0, _utils._isChainEvmCompatible)(chainInfo)) {
|
|
1670
|
-
const web3 = this.#koniState.chainService.getEvmApi(networkKey);
|
|
1671
|
-
const transaction = {
|
|
1672
|
-
value: 1,
|
|
1673
|
-
to: address,
|
|
1674
|
-
from: address
|
|
1675
|
-
};
|
|
1676
|
-
const gasPrice = await web3.api.eth.getGasPrice();
|
|
1677
|
-
const gasLimit = await web3.api.eth.estimateGas(transaction);
|
|
1678
|
-
estimatedFee = (gasLimit * parseInt(gasPrice)).toString();
|
|
1679
1667
|
} else {
|
|
1680
|
-
const
|
|
1681
|
-
|
|
1682
|
-
networkKey
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1668
|
+
const chainInfo = this.#koniState.chainService.getChainInfoByKey(networkKey);
|
|
1669
|
+
if ((0, _utils._isChainEvmCompatible)(chainInfo)) {
|
|
1670
|
+
const web3 = this.#koniState.chainService.getEvmApi(networkKey);
|
|
1671
|
+
const transaction = {
|
|
1672
|
+
value: 0,
|
|
1673
|
+
to: '0x0000000000000000000000000000000000000000',
|
|
1674
|
+
// null address
|
|
1675
|
+
from: address
|
|
1676
|
+
};
|
|
1677
|
+
const gasPrice = await web3.api.eth.getGasPrice();
|
|
1678
|
+
const gasLimit = await web3.api.eth.estimateGas(transaction);
|
|
1679
|
+
estimatedFee = (gasLimit * parseInt(gasPrice)).toString();
|
|
1680
|
+
} else {
|
|
1690
1681
|
var _paymentInfo$partialF2;
|
|
1682
|
+
const [mockTx] = await (0, _transfer.createTransferExtrinsic)({
|
|
1683
|
+
from: address,
|
|
1684
|
+
networkKey,
|
|
1685
|
+
substrateApi,
|
|
1686
|
+
to: address,
|
|
1687
|
+
tokenInfo,
|
|
1688
|
+
transferAll: true,
|
|
1689
|
+
value: '0'
|
|
1690
|
+
});
|
|
1691
1691
|
const paymentInfo = await (mockTx === null || mockTx === void 0 ? void 0 : mockTx.paymentInfo(address));
|
|
1692
1692
|
estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF2 = paymentInfo.partialFee) === null || _paymentInfo$partialF2 === void 0 ? void 0 : _paymentInfo$partialF2.toString()) || '0';
|
|
1693
|
-
} catch (e) {
|
|
1694
|
-
estimatedFee = '0';
|
|
1695
|
-
console.warn('Error estimating fee', e);
|
|
1696
1693
|
}
|
|
1697
1694
|
}
|
|
1695
|
+
} catch (e) {
|
|
1696
|
+
estimatedFee = '0';
|
|
1697
|
+
console.warn('Error estimating fee', e);
|
|
1698
1698
|
}
|
|
1699
1699
|
maxTransferable = maxTransferable.sub(new _util.BN(estimatedFee));
|
|
1700
1700
|
return {
|
|
@@ -2917,6 +2917,7 @@ class KoniExtension {
|
|
|
2917
2917
|
return Object.fromEntries(Object.entries(rs).map(_ref70 => {
|
|
2918
2918
|
let [key, value] = _ref70;
|
|
2919
2919
|
const {
|
|
2920
|
+
additionalValidator,
|
|
2920
2921
|
transaction,
|
|
2921
2922
|
...transactionResult
|
|
2922
2923
|
} = value;
|
|
@@ -2964,6 +2965,15 @@ class KoniExtension {
|
|
|
2964
2965
|
};
|
|
2965
2966
|
}
|
|
2966
2967
|
|
|
2968
|
+
// Phishing detect
|
|
2969
|
+
|
|
2970
|
+
async passPhishingPage(_ref72) {
|
|
2971
|
+
let {
|
|
2972
|
+
url
|
|
2973
|
+
} = _ref72;
|
|
2974
|
+
return await this.#koniState.approvePassPhishingPage(url);
|
|
2975
|
+
}
|
|
2976
|
+
|
|
2967
2977
|
// --------------------------------------------------------------
|
|
2968
2978
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2969
2979
|
async handle(id, type, request, port) {
|
|
@@ -3289,6 +3299,10 @@ class KoniExtension {
|
|
|
3289
3299
|
case 'pri(authorize.subscribe)':
|
|
3290
3300
|
return await this.subscribeAuthUrls(id, port);
|
|
3291
3301
|
|
|
3302
|
+
// Phishing page
|
|
3303
|
+
case 'pri(phishing.pass)':
|
|
3304
|
+
return await this.passPhishingPage(request);
|
|
3305
|
+
|
|
3292
3306
|
/// Keyring state
|
|
3293
3307
|
case 'pri(keyring.subscribe)':
|
|
3294
3308
|
return this.keyringStateSubscribe(id, port);
|
|
@@ -1469,6 +1469,22 @@ class KoniState {
|
|
|
1469
1469
|
async reloadStaking() {
|
|
1470
1470
|
return await this.cron.reloadStaking();
|
|
1471
1471
|
}
|
|
1472
|
+
async approvePassPhishingPage(_url) {
|
|
1473
|
+
return new Promise(resolve => {
|
|
1474
|
+
this.settingService.getPassPhishingList(value => {
|
|
1475
|
+
const result = {
|
|
1476
|
+
...value
|
|
1477
|
+
};
|
|
1478
|
+
const url = this.requestService.stripUrl(_url);
|
|
1479
|
+
result[url] = {
|
|
1480
|
+
pass: true
|
|
1481
|
+
};
|
|
1482
|
+
this.settingService.setPassPhishing(result, () => {
|
|
1483
|
+
resolve(true);
|
|
1484
|
+
});
|
|
1485
|
+
});
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1472
1488
|
async resetWallet(resetAll) {
|
|
1473
1489
|
this.keyringService.resetWallet(resetAll);
|
|
1474
1490
|
this.requestService.resetWallet();
|
|
@@ -116,6 +116,7 @@ class KoniTabs {
|
|
|
116
116
|
#koniState;
|
|
117
117
|
evmEventEmitterMap = {};
|
|
118
118
|
#chainPatrolService = _constants2.DEFAULT_CHAIN_PATROL_ENABLE;
|
|
119
|
+
#passPhishing = {};
|
|
119
120
|
constructor(koniState) {
|
|
120
121
|
this.#koniState = koniState;
|
|
121
122
|
const updateChainPatrolService = rs => {
|
|
@@ -125,6 +126,13 @@ class KoniTabs {
|
|
|
125
126
|
this.#koniState.settingService.getSubject().subscribe({
|
|
126
127
|
next: updateChainPatrolService
|
|
127
128
|
});
|
|
129
|
+
const updatePassPhishing = rs => {
|
|
130
|
+
this.#passPhishing = rs;
|
|
131
|
+
};
|
|
132
|
+
this.#koniState.settingService.getPassPhishingList(updatePassPhishing);
|
|
133
|
+
this.#koniState.settingService.passPhishingSubject().subscribe({
|
|
134
|
+
next: updatePassPhishing
|
|
135
|
+
});
|
|
128
136
|
}
|
|
129
137
|
|
|
130
138
|
/// Clone from Polkadot.js
|
|
@@ -217,21 +225,31 @@ class KoniTabs {
|
|
|
217
225
|
})));
|
|
218
226
|
});
|
|
219
227
|
}
|
|
220
|
-
|
|
228
|
+
checkPassList(_url) {
|
|
229
|
+
const url = stripUrl(_url);
|
|
230
|
+
const result = this.#passPhishing[url];
|
|
231
|
+
return result ? !result.pass : true;
|
|
232
|
+
}
|
|
233
|
+
async checkPhishing(url) {
|
|
221
234
|
const isInDenyList = await (0, _phishing.checkIfDenied)(url);
|
|
222
235
|
if (isInDenyList) {
|
|
223
|
-
this.
|
|
224
|
-
return true;
|
|
236
|
+
return this.checkPassList(url);
|
|
225
237
|
}
|
|
226
238
|
if (this.#chainPatrolService) {
|
|
227
239
|
const isInChainPatrolDenyList = await chainPatrolCheckUrl(url);
|
|
228
240
|
if (isInChainPatrolDenyList) {
|
|
229
|
-
this.
|
|
230
|
-
return true;
|
|
241
|
+
return this.checkPassList(url);
|
|
231
242
|
}
|
|
232
243
|
}
|
|
233
244
|
return false;
|
|
234
245
|
}
|
|
246
|
+
async redirectIfPhishing(url) {
|
|
247
|
+
const result = await this.checkPhishing(url);
|
|
248
|
+
if (result) {
|
|
249
|
+
this.redirectPhishingLanding(url);
|
|
250
|
+
}
|
|
251
|
+
return result;
|
|
252
|
+
}
|
|
235
253
|
|
|
236
254
|
///
|
|
237
255
|
|
|
@@ -445,35 +463,36 @@ class KoniTabs {
|
|
|
445
463
|
const chainIdNum = parseInt(chainId, 16);
|
|
446
464
|
const [existedNetworkSlug, existedChainInfo] = this.#koniState.findNetworkKeyByChainId(chainIdNum);
|
|
447
465
|
if (existedNetworkSlug && existedChainInfo && existedChainInfo !== null && existedChainInfo !== void 0 && existedChainInfo.evmInfo) {
|
|
448
|
-
const evmInfo = existedChainInfo.evmInfo;
|
|
449
|
-
const substrateInfo = existedChainInfo.substrateInfo;
|
|
450
|
-
const chainState = this.#koniState.getChainStateByKey(existedNetworkSlug);
|
|
451
|
-
await this.#koniState.addNetworkConfirm(id, url, {
|
|
452
|
-
mode: 'update',
|
|
453
|
-
chainSpec: {
|
|
454
|
-
evmChainId: evmInfo.evmChainId,
|
|
455
|
-
decimals: evmInfo.decimals,
|
|
456
|
-
existentialDeposit: evmInfo.existentialDeposit,
|
|
457
|
-
genesisHash: (substrateInfo === null || substrateInfo === void 0 ? void 0 : substrateInfo.genesisHash) || '',
|
|
458
|
-
paraId: (substrateInfo === null || substrateInfo === void 0 ? void 0 : substrateInfo.paraId) || null,
|
|
459
|
-
addressPrefix: (substrateInfo === null || substrateInfo === void 0 ? void 0 : substrateInfo.addressPrefix) || 0
|
|
460
|
-
},
|
|
461
|
-
chainEditInfo: {
|
|
462
|
-
blockExplorer: blockExplorerUrls === null || blockExplorerUrls === void 0 ? void 0 : blockExplorerUrls[0],
|
|
463
|
-
slug: existedNetworkSlug,
|
|
464
|
-
currentProvider: chainState.currentProvider,
|
|
465
|
-
providers: existedChainInfo.providers,
|
|
466
|
-
symbol: evmInfo.symbol,
|
|
467
|
-
chainType: 'EVM',
|
|
468
|
-
name: existedChainInfo.name
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
466
|
return await this.switchEvmChain(id, url, {
|
|
472
467
|
method: 'wallet_switchEthereumChain',
|
|
473
468
|
params: [{
|
|
474
469
|
chainId
|
|
475
470
|
}]
|
|
476
471
|
});
|
|
472
|
+
// const evmInfo = existedChainInfo.evmInfo;
|
|
473
|
+
// const substrateInfo = existedChainInfo.substrateInfo;
|
|
474
|
+
// const chainState = this.#koniState.getChainStateByKey(existedNetworkSlug);
|
|
475
|
+
//
|
|
476
|
+
// return await this.#koniState.addNetworkConfirm(id, url, {
|
|
477
|
+
// mode: 'update',
|
|
478
|
+
// chainSpec: {
|
|
479
|
+
// evmChainId: evmInfo.evmChainId,
|
|
480
|
+
// decimals: evmInfo.decimals,
|
|
481
|
+
// existentialDeposit: evmInfo.existentialDeposit,
|
|
482
|
+
// genesisHash: substrateInfo?.genesisHash || '',
|
|
483
|
+
// paraId: substrateInfo?.paraId || null,
|
|
484
|
+
// addressPrefix: substrateInfo?.addressPrefix || 0
|
|
485
|
+
// },
|
|
486
|
+
// chainEditInfo: {
|
|
487
|
+
// blockExplorer: blockExplorerUrls?.[0],
|
|
488
|
+
// slug: existedNetworkSlug,
|
|
489
|
+
// currentProvider: chainState.currentProvider,
|
|
490
|
+
// providers: existedChainInfo.providers,
|
|
491
|
+
// symbol: evmInfo.symbol,
|
|
492
|
+
// chainType: 'EVM',
|
|
493
|
+
// name: existedChainInfo.name
|
|
494
|
+
// }
|
|
495
|
+
// });
|
|
477
496
|
} else if (rpcUrls && chainName) {
|
|
478
497
|
const filteredUrls = rpcUrls.filter(targetString => {
|
|
479
498
|
let url;
|
package/cjs/packageInfo.js
CHANGED
|
@@ -36,7 +36,7 @@ const _BALANCE_CHAIN_GROUP = {
|
|
|
36
36
|
genshiro: ['genshiro_testnet', 'genshiro'],
|
|
37
37
|
equilibrium_parachain: ['equilibrium_parachain'],
|
|
38
38
|
bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry'],
|
|
39
|
-
statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain'],
|
|
39
|
+
statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2'],
|
|
40
40
|
kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'] // perhaps there are some runtime updates
|
|
41
41
|
};
|
|
42
42
|
exports._BALANCE_CHAIN_GROUP = _BALANCE_CHAIN_GROUP;
|
|
@@ -66,7 +66,7 @@ const _STAKING_CHAIN_GROUP = {
|
|
|
66
66
|
kilt: ['kilt', 'kilt_peregrine'],
|
|
67
67
|
nominationPool: ['polkadot', 'kusama', 'westend', 'alephTest', 'aleph'],
|
|
68
68
|
bifrost: ['bifrost', 'bifrost_testnet'],
|
|
69
|
-
aleph: ['aleph, alephTest'] // A0 has distinct tokenomics
|
|
69
|
+
aleph: ['aleph', 'alephTest'] // A0 has distinct tokenomics
|
|
70
70
|
};
|
|
71
71
|
exports._STAKING_CHAIN_GROUP = _STAKING_CHAIN_GROUP;
|
|
72
72
|
const _STAKING_ERA_LENGTH_MAP = {
|
|
@@ -194,7 +194,7 @@ const _TRANSFER_CHAIN_GROUP = {
|
|
|
194
194
|
genshiro: ['genshiro_testnet', 'genshiro', 'equilibrium_parachain'],
|
|
195
195
|
crab: ['crab', 'pangolin'],
|
|
196
196
|
bitcountry: ['pioneer', 'bitcountry'],
|
|
197
|
-
statemine: ['statemint', 'statemine']
|
|
197
|
+
statemine: ['statemint', 'statemine', 'darwinia2']
|
|
198
198
|
};
|
|
199
199
|
exports._TRANSFER_CHAIN_GROUP = _TRANSFER_CHAIN_GROUP;
|
|
200
200
|
const _BALANCE_PARSING_CHAIN_GROUP = {
|
|
@@ -720,6 +720,11 @@ class ChainService {
|
|
|
720
720
|
targetChainInfo.substrateInfo.crowdloanUrl = params.chainEditInfo.crowdloanUrl;
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
|
+
if (targetChainInfo.evmInfo) {
|
|
724
|
+
if (params.chainEditInfo.blockExplorer !== undefined) {
|
|
725
|
+
targetChainInfo.evmInfo.blockExplorer = params.chainEditInfo.blockExplorer;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
723
728
|
this.updateChainInfoMapSubscription();
|
|
724
729
|
this.dbService.updateChainStore({
|
|
725
730
|
...targetChainInfo,
|
|
@@ -61,6 +61,7 @@ exports._isSubstrateParaChain = _isSubstrateParaChain;
|
|
|
61
61
|
exports._isSubstrateParachain = _isSubstrateParachain;
|
|
62
62
|
exports._isSubstrateRelayChain = _isSubstrateRelayChain;
|
|
63
63
|
exports._isTokenEvmSmartContract = _isTokenEvmSmartContract;
|
|
64
|
+
exports._isTokenTransferredByEvm = _isTokenTransferredByEvm;
|
|
64
65
|
exports._isTokenWasmSmartContract = _isTokenWasmSmartContract;
|
|
65
66
|
exports._isXcmPathSupported = _isXcmPathSupported;
|
|
66
67
|
exports._parseAssetRefKey = _parseAssetRefKey;
|
|
@@ -128,6 +129,10 @@ function _getContractAddressOfToken(tokenInfo) {
|
|
|
128
129
|
var _tokenInfo$metadata;
|
|
129
130
|
return ((_tokenInfo$metadata = tokenInfo.metadata) === null || _tokenInfo$metadata === void 0 ? void 0 : _tokenInfo$metadata.contractAddress) || '';
|
|
130
131
|
}
|
|
132
|
+
function _isTokenTransferredByEvm(tokenInfo) {
|
|
133
|
+
var _tokenInfo$metadata2;
|
|
134
|
+
return !!((_tokenInfo$metadata2 = tokenInfo.metadata) !== null && _tokenInfo$metadata2 !== void 0 && _tokenInfo$metadata2.contractAddress) || _isNativeToken(tokenInfo);
|
|
135
|
+
}
|
|
131
136
|
function _checkSmartContractSupportByChain(chainInfo, contractType) {
|
|
132
137
|
// EVM chains support smart contract by default so just checking Substrate chains
|
|
133
138
|
if (chainInfo.substrateInfo === null || chainInfo.substrateInfo && chainInfo.substrateInfo.supportSmartContract === null) {
|
|
@@ -138,12 +143,12 @@ function _checkSmartContractSupportByChain(chainInfo, contractType) {
|
|
|
138
143
|
|
|
139
144
|
// Utils for balance functions
|
|
140
145
|
function _getTokenOnChainAssetId(tokenInfo) {
|
|
141
|
-
var _tokenInfo$
|
|
142
|
-
return ((_tokenInfo$
|
|
146
|
+
var _tokenInfo$metadata3;
|
|
147
|
+
return ((_tokenInfo$metadata3 = tokenInfo.metadata) === null || _tokenInfo$metadata3 === void 0 ? void 0 : _tokenInfo$metadata3.assetId) || '-1';
|
|
143
148
|
}
|
|
144
149
|
function _getTokenOnChainInfo(tokenInfo) {
|
|
145
|
-
var _tokenInfo$
|
|
146
|
-
return (_tokenInfo$
|
|
150
|
+
var _tokenInfo$metadata4;
|
|
151
|
+
return (_tokenInfo$metadata4 = tokenInfo.metadata) === null || _tokenInfo$metadata4 === void 0 ? void 0 : _tokenInfo$metadata4.onChainInfo;
|
|
147
152
|
}
|
|
148
153
|
function _getTokenMinAmount(tokenInfo) {
|
|
149
154
|
return tokenInfo.minAmount || '0';
|
|
@@ -296,16 +301,16 @@ function _isXcmPathSupported(originTokenSlug, destinationTokenSlug, assetRefMap)
|
|
|
296
301
|
return assetRef.path === _types._AssetRefPath.XCM;
|
|
297
302
|
}
|
|
298
303
|
function _getXcmAssetType(tokenInfo) {
|
|
299
|
-
var _tokenInfo$
|
|
300
|
-
return ((_tokenInfo$
|
|
304
|
+
var _tokenInfo$metadata5;
|
|
305
|
+
return ((_tokenInfo$metadata5 = tokenInfo.metadata) === null || _tokenInfo$metadata5 === void 0 ? void 0 : _tokenInfo$metadata5.assetType) || '';
|
|
301
306
|
}
|
|
302
307
|
function _getXcmAssetId(tokenInfo) {
|
|
303
|
-
var _tokenInfo$
|
|
304
|
-
return ((_tokenInfo$
|
|
308
|
+
var _tokenInfo$metadata6;
|
|
309
|
+
return ((_tokenInfo$metadata6 = tokenInfo.metadata) === null || _tokenInfo$metadata6 === void 0 ? void 0 : _tokenInfo$metadata6.assetId) || '-1';
|
|
305
310
|
}
|
|
306
311
|
function _getXcmAssetMultilocation(tokenInfo) {
|
|
307
|
-
var _tokenInfo$
|
|
308
|
-
return (_tokenInfo$
|
|
312
|
+
var _tokenInfo$metadata7;
|
|
313
|
+
return (_tokenInfo$metadata7 = tokenInfo.metadata) === null || _tokenInfo$metadata7 === void 0 ? void 0 : _tokenInfo$metadata7.multilocation;
|
|
309
314
|
}
|
|
310
315
|
function _getXcmTransferType(originChainInfo, destinationChainInfo) {
|
|
311
316
|
var _originChainInfo$subs, _destinationChainInfo;
|
|
@@ -255,7 +255,7 @@ async function fetchMultiChainHistories(addresses, chainMap) {
|
|
|
255
255
|
const usedAddresses = relatedAddresses.filter(a => lowerAddresses.includes(a.toLowerCase()));
|
|
256
256
|
const chainInfo = chainMap[chainId];
|
|
257
257
|
if (chainInfo === undefined) {
|
|
258
|
-
console.
|
|
258
|
+
console.debug(`Not found chain info for chain id: ${chainId}`); // TODO: resolve conflicting chainId
|
|
259
259
|
|
|
260
260
|
return;
|
|
261
261
|
}
|
|
@@ -264,7 +264,7 @@ async function fetchMultiChainHistories(addresses, chainMap) {
|
|
|
264
264
|
const transactionData = parseSubsquidTransactionData(address, name, historyItem, chainInfo, parseData(args), parseData(_data));
|
|
265
265
|
histories.push(transactionData);
|
|
266
266
|
} catch (e) {
|
|
267
|
-
console.
|
|
267
|
+
console.debug('Parse transaction data failed', address, e);
|
|
268
268
|
}
|
|
269
269
|
});
|
|
270
270
|
});
|
|
@@ -42,6 +42,9 @@ class RequestService {
|
|
|
42
42
|
updateIconV2(shouldClose) {
|
|
43
43
|
this.#popupHandler.updateIconV2(shouldClose);
|
|
44
44
|
}
|
|
45
|
+
stripUrl(url) {
|
|
46
|
+
return this.#authRequestHandler.stripUrl(url);
|
|
47
|
+
}
|
|
45
48
|
getAddressList() {
|
|
46
49
|
let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
47
50
|
const addressList = Object.keys(this.keyringService.accounts);
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
+
var _PassPhishingStore = _interopRequireDefault(require("@subwallet/extension-base/stores/PassPhishingStore"));
|
|
8
9
|
var _Settings = _interopRequireDefault(require("@subwallet/extension-base/stores/Settings"));
|
|
9
10
|
var _constants = require("./constants");
|
|
10
11
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
@@ -12,6 +13,7 @@ var _constants = require("./constants");
|
|
|
12
13
|
|
|
13
14
|
class SettingService {
|
|
14
15
|
settingsStore = new _Settings.default();
|
|
16
|
+
passPhishingStore = new _PassPhishingStore.default();
|
|
15
17
|
getSubject() {
|
|
16
18
|
return this.settingsStore.getSubject();
|
|
17
19
|
}
|
|
@@ -27,8 +29,20 @@ class SettingService {
|
|
|
27
29
|
setSettings(data, callback) {
|
|
28
30
|
this.settingsStore.set('Settings', data, callback);
|
|
29
31
|
}
|
|
32
|
+
passPhishingSubject() {
|
|
33
|
+
return this.passPhishingStore.getSubject();
|
|
34
|
+
}
|
|
35
|
+
getPassPhishingList(update) {
|
|
36
|
+
this.passPhishingStore.get('PassPhishing', value => {
|
|
37
|
+
update(value || {});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
setPassPhishing(data, callback) {
|
|
41
|
+
this.passPhishingStore.set('PassPhishing', data, callback);
|
|
42
|
+
}
|
|
30
43
|
resetWallet() {
|
|
31
44
|
this.settingsStore.set('Settings', _constants.DEFAULT_SETTING);
|
|
45
|
+
this.passPhishingStore.set('PassPhishing', {});
|
|
32
46
|
}
|
|
33
47
|
}
|
|
34
48
|
exports.default = SettingService;
|
|
@@ -152,7 +152,7 @@ class DatabaseService {
|
|
|
152
152
|
}
|
|
153
153
|
async cleanUpNft(chain, owner, collectionIds, nftIds, ownNothing) {
|
|
154
154
|
if (ownNothing) {
|
|
155
|
-
return this.stores.nft.deleteNftsByChainAndOwner(chain, (0, _utils.reformatAddress)(owner, 42));
|
|
155
|
+
return this.stores.nft.deleteNftsByChainAndOwner(chain, (0, _utils.reformatAddress)(owner, 42), collectionIds);
|
|
156
156
|
}
|
|
157
157
|
return this.stores.nft.cleanUpNfts(chain, (0, _utils.reformatAddress)(owner, 42), collectionIds, nftIds);
|
|
158
158
|
}
|
|
@@ -28,13 +28,13 @@ class NftStore extends _BaseStoreWithAddressAndChain.default {
|
|
|
28
28
|
return this.table.where({
|
|
29
29
|
address,
|
|
30
30
|
chain
|
|
31
|
-
}).and(nft =>
|
|
31
|
+
}).and(nft => collectionIds.includes(nft.collectionId) && !nftIds.includes(nft.id)).delete();
|
|
32
32
|
}
|
|
33
|
-
deleteNftsByChainAndOwner(chain, address) {
|
|
33
|
+
deleteNftsByChainAndOwner(chain, address, collectionIds) {
|
|
34
34
|
return this.table.where({
|
|
35
35
|
address,
|
|
36
36
|
chain
|
|
37
|
-
}).delete();
|
|
37
|
+
}).and(nft => collectionIds.includes(nft.collectionId)).delete();
|
|
38
38
|
}
|
|
39
39
|
deleteNftByAddress(addresses) {
|
|
40
40
|
return this.table.where('address').anyOfIgnoreCase(addresses).delete();
|