@subwallet/extension-base 1.0.1 → 1.0.2-1
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 +10 -3
- package/background/KoniTypes.js +6 -0
- package/cjs/background/KoniTypes.js +8 -1
- package/cjs/constants/index.js +6 -3
- package/cjs/koni/api/dotsama/balance.js +11 -0
- package/cjs/koni/api/staking/bonding/amplitude.js +6 -2
- package/cjs/koni/api/staking/bonding/astar.js +40 -243
- package/cjs/koni/api/staking/bonding/index.js +4 -4
- package/cjs/koni/api/staking/bonding/paraChain.js +16 -10
- package/cjs/koni/api/staking/bonding/relayChain.js +62 -7
- package/cjs/koni/api/staking/bonding/utils.js +29 -3
- package/cjs/koni/api/xcm/index.js +0 -111
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/xTokens.js +2 -4
- package/cjs/koni/background/cron.js +61 -62
- package/cjs/koni/background/handlers/Extension.js +143 -149
- package/cjs/koni/background/handlers/State.js +129 -91
- package/cjs/koni/background/handlers/Tabs.js +40 -38
- package/cjs/koni/background/subscription.js +48 -43
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/index.js +5 -0
- package/cjs/services/chain-service/constants.js +1 -11
- package/cjs/services/chain-service/index.js +39 -5
- package/cjs/services/chain-service/utils.js +4 -0
- package/cjs/services/event-service/index.js +71 -0
- package/cjs/services/event-service/types.js +1 -0
- package/cjs/services/history-service/index.js +36 -17
- package/cjs/services/history-service/subsquid-multi-chain-history.js +7 -2
- package/cjs/services/keyring-service/index.js +101 -0
- package/cjs/services/migration-service/index.js +13 -10
- package/cjs/{koni/migration/scripts/RemoveWrongCrowdloan.js → services/migration-service/scripts/AutoEnableChainsTokens.js} +11 -6
- package/cjs/services/migration-service/scripts/MigrateNetworkSettings.js +39 -19
- package/cjs/services/migration-service/scripts/MigrateSettings.js +31 -0
- package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +72 -0
- package/cjs/services/migration-service/scripts/index.js +13 -4
- package/cjs/services/price-service/coingecko.js +16 -3
- package/cjs/services/price-service/index.js +15 -17
- package/cjs/services/request-service/constants.js +8 -2
- package/cjs/services/request-service/handler/AuthRequestHandler.js +39 -12
- package/cjs/services/request-service/index.js +3 -0
- package/cjs/services/storage-service/DatabaseService.js +1 -1
- package/cjs/services/storage-service/databases/index.js +1 -1
- package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
- package/cjs/services/storage-service/db-stores/Nft.js +4 -1
- package/cjs/services/storage-service/db-stores/Transaction.js +10 -7
- package/cjs/services/subscan-service/index.js +107 -0
- package/cjs/services/subscan-service/subscan-chain-map.js +74 -0
- package/cjs/services/subscan-service/types.js +1 -0
- package/cjs/services/transaction-service/index.js +45 -10
- package/cjs/services/transaction-service/utils.js +4 -6
- package/cjs/utils/address.js +9 -1
- package/cjs/utils/index.js +24 -13
- package/constants/index.d.ts +1 -0
- package/constants/index.js +1 -0
- package/koni/api/dotsama/balance.js +11 -0
- package/koni/api/staking/bonding/amplitude.d.ts +1 -1
- package/koni/api/staking/bonding/amplitude.js +8 -4
- package/koni/api/staking/bonding/astar.d.ts +2 -11
- package/koni/api/staking/bonding/astar.js +35 -229
- package/koni/api/staking/bonding/index.d.ts +1 -1
- package/koni/api/staking/bonding/index.js +4 -4
- package/koni/api/staking/bonding/paraChain.d.ts +1 -1
- package/koni/api/staking/bonding/paraChain.js +17 -11
- package/koni/api/staking/bonding/relayChain.d.ts +1 -1
- package/koni/api/staking/bonding/relayChain.js +63 -8
- package/koni/api/staking/bonding/utils.d.ts +13 -1
- package/koni/api/staking/bonding/utils.js +27 -3
- package/koni/api/xcm/index.js +1 -112
- package/koni/api/xcm/polkadotXcm.js +1 -1
- package/koni/api/xcm/xTokens.js +3 -5
- package/koni/background/cron.js +60 -60
- package/koni/background/handlers/Extension.js +71 -76
- package/koni/background/handlers/State.d.ts +16 -14
- package/koni/background/handlers/State.js +126 -91
- package/koni/background/handlers/Tabs.js +22 -19
- package/koni/background/subscription.d.ts +1 -1
- package/koni/background/subscription.js +49 -44
- package/package.json +56 -16
- package/packageInfo.js +1 -1
- package/page/index.d.ts +2 -0
- package/page/index.js +4 -0
- package/services/chain-service/constants.d.ts +0 -1
- package/services/chain-service/constants.js +0 -9
- package/services/chain-service/index.d.ts +6 -4
- package/services/chain-service/index.js +39 -7
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +3 -0
- package/services/event-service/index.d.ts +22 -0
- package/services/event-service/index.js +59 -0
- package/services/event-service/types.d.ts +32 -0
- package/services/event-service/types.js +1 -0
- package/services/history-service/index.d.ts +5 -3
- package/services/history-service/index.js +36 -17
- package/services/history-service/subsquid-multi-chain-history.js +7 -2
- package/services/keyring-service/index.d.ts +19 -0
- package/services/keyring-service/index.js +93 -0
- package/services/migration-service/index.js +11 -9
- package/services/migration-service/scripts/AutoEnableChainsTokens.d.ts +4 -0
- package/services/migration-service/scripts/AutoEnableChainsTokens.js +13 -0
- package/services/migration-service/scripts/MigrateNetworkSettings.js +37 -18
- package/services/migration-service/scripts/MigrateSettings.d.ts +4 -0
- package/services/migration-service/scripts/MigrateSettings.js +23 -0
- package/services/migration-service/scripts/MigrateTransactionHistory.d.ts +4 -0
- package/services/migration-service/scripts/MigrateTransactionHistory.js +64 -0
- package/services/migration-service/scripts/index.d.ts +1 -0
- package/services/migration-service/scripts/index.js +10 -3
- package/services/price-service/coingecko.js +16 -3
- package/services/price-service/index.d.ts +5 -3
- package/services/price-service/index.js +15 -17
- package/services/request-service/constants.d.ts +1 -0
- package/services/request-service/constants.js +6 -1
- package/services/request-service/handler/AuthRequestHandler.d.ts +8 -1
- package/services/request-service/handler/AuthRequestHandler.js +40 -13
- package/services/request-service/index.d.ts +7 -1
- package/services/request-service/index.js +3 -0
- package/services/storage-service/DatabaseService.js +1 -1
- package/services/storage-service/databases/index.js +1 -1
- package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +1 -1
- package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
- package/services/storage-service/db-stores/Nft.d.ts +2 -1
- package/services/storage-service/db-stores/Nft.js +4 -1
- package/services/storage-service/db-stores/Transaction.js +10 -7
- package/services/subscan-service/index.d.ts +20 -0
- package/services/subscan-service/index.js +99 -0
- package/services/subscan-service/subscan-chain-map.d.ts +5 -0
- package/services/subscan-service/subscan-chain-map.js +63 -0
- package/services/subscan-service/types.d.ts +27 -0
- package/services/subscan-service/types.js +1 -0
- package/services/transaction-service/event-parser/index.d.ts +2 -2
- package/services/transaction-service/index.d.ts +4 -2
- package/services/transaction-service/index.js +45 -10
- package/services/transaction-service/utils.js +5 -6
- package/utils/address.d.ts +1 -0
- package/utils/address.js +9 -2
- package/utils/index.d.ts +1 -0
- package/utils/index.js +21 -12
- package/cjs/background/errors/EvmRpcError.js +0 -21
- package/cjs/background/errors/SubWalletProviderError.js +0 -17
- package/cjs/constants/ethereum.js +0 -19
- package/cjs/errors/SubWalletProviderError.js +0 -17
- package/cjs/koni/api/xcm/astar.js +0 -160
- package/cjs/koni/api/xcm/moonbeamXcm.js +0 -80
- package/cjs/koni/api/xcm/statemintXcm.js +0 -197
- package/cjs/koni/api/xcm/substrateXcm.js +0 -213
- package/cjs/koni/migration/Base.js +0 -20
- package/cjs/koni/migration/index.js +0 -45
- package/cjs/koni/migration/scripts/ChangeRouteToHome.js +0 -22
- package/cjs/koni/migration/scripts/ClearOldStorage.js +0 -24
- package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +0 -36
- package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +0 -21
- package/cjs/koni/migration/scripts/index.js +0 -22
- package/cjs/koni/page/index.js +0 -16
- package/cjs/services/asset-service/index.js +0 -91
- package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +0 -17
- package/cjs/stores/Balance.js +0 -18
- package/cjs/stores/Crowdloan.js +0 -18
- package/cjs/stores/CustomEvmToken.js +0 -18
- package/cjs/stores/NetworkMap.js +0 -18
- package/cjs/stores/Nft.js +0 -18
- package/cjs/stores/NftCollection.js +0 -18
- package/cjs/stores/Price.js +0 -18
- package/cjs/stores/Staking.js +0 -18
- package/cjs/stores/StakingReward.js +0 -18
- package/cjs/utils/eth/parseTransactionData.js +0 -284
- package/koni/page/index.d.ts +0 -2
- package/koni/page/index.js +0 -9
- /package/cjs/{koni/page → page}/SubWalleEvmProvider.js +0 -0
- /package/{koni/page → page}/SubWalleEvmProvider.d.ts +0 -0
- /package/{koni/page → page}/SubWalleEvmProvider.js +0 -0
|
@@ -7,7 +7,7 @@ import { isJsonPayload, SEED_DEFAULT_LENGTH, SEED_LENGTHS } from '@subwallet/ext
|
|
|
7
7
|
import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
|
|
8
8
|
import { createSubscription } from '@subwallet/extension-base/background/handlers/subscriptions';
|
|
9
9
|
import { AccountExternalErrorCode, BasicTxErrorType, ChainType, ExternalRequestPromiseStatus, ExtrinsicType, TransferTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
10
|
-
import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH } from '@subwallet/extension-base/constants';
|
|
10
|
+
import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH, DEFAULT_TIME_AUTO_LOCK } from '@subwallet/extension-base/constants';
|
|
11
11
|
import { ALLOWED_PATH } from '@subwallet/extension-base/defaults';
|
|
12
12
|
import { parseSubstrateTransaction } from '@subwallet/extension-base/koni/api/dotsama/parseTransaction';
|
|
13
13
|
import { checkReferenceCount, checkSupportTransfer, createTransferExtrinsic } from '@subwallet/extension-base/koni/api/dotsama/transfer';
|
|
@@ -18,7 +18,7 @@ import { getPoolingBondingExtrinsic, getPoolingUnbondingExtrinsic } from '@subwa
|
|
|
18
18
|
import { getERC20TransactionObject, getERC721Transaction, getEVMTransactionObject } from '@subwallet/extension-base/koni/api/tokens/evm/transfer';
|
|
19
19
|
import { getPSP34TransferExtrinsic } from '@subwallet/extension-base/koni/api/tokens/wasm';
|
|
20
20
|
import { createXcmExtrinsic } from '@subwallet/extension-base/koni/api/xcm';
|
|
21
|
-
import { _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getSubstrateGenesisHash, _getTokenMinAmount, _isAssetSmartContractNft, _isChainEvmCompatible, _isCustomAsset, _isNativeToken, _isTokenEvmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
|
|
21
|
+
import { _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getSubstrateGenesisHash, _getTokenMinAmount, _isAssetSmartContractNft, _isChainEvmCompatible, _isCustomAsset, _isLocalToken, _isNativeToken, _isTokenEvmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
|
|
22
22
|
import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
|
|
23
23
|
import { createTransactionFromRLP, signatureToHex } from '@subwallet/extension-base/utils/eth';
|
|
24
24
|
import { parseContractInput, parseEvmRlp } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
@@ -52,6 +52,7 @@ const ACCOUNT_ALL_JSON = {
|
|
|
52
52
|
name: 'All'
|
|
53
53
|
};
|
|
54
54
|
export default class KoniExtension {
|
|
55
|
+
#lockTimeOut = undefined;
|
|
55
56
|
#koniState;
|
|
56
57
|
constructor(state) {
|
|
57
58
|
this.#koniState = state;
|
|
@@ -410,19 +411,18 @@ export default class KoniExtension {
|
|
|
410
411
|
accounts
|
|
411
412
|
};
|
|
412
413
|
setTimeout(() => {
|
|
413
|
-
this.#koniState.
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}
|
|
414
|
+
const accountInfo = this.#koniState.keyringService.currentAccount;
|
|
415
|
+
if (accountInfo) {
|
|
416
|
+
accountsWithCurrentAddress.currentAddress = accountInfo.address;
|
|
417
|
+
if (accountInfo.address === ALL_ACCOUNT_KEY) {
|
|
418
|
+
accountsWithCurrentAddress.currentGenesisHash = accountInfo.currentGenesisHash;
|
|
419
|
+
} else {
|
|
420
|
+
const acc = accounts.find(a => a.address === accountInfo.address);
|
|
421
|
+
accountsWithCurrentAddress.currentGenesisHash = (acc === null || acc === void 0 ? void 0 : acc.genesisHash) || ALL_GENESIS_HASH;
|
|
422
422
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
423
|
+
}
|
|
424
|
+
resolve(accountsWithCurrentAddress);
|
|
425
|
+
cb(accountsWithCurrentAddress);
|
|
426
426
|
}, 300);
|
|
427
427
|
});
|
|
428
428
|
this.createUnsubscriptionHandle(id, subscription.unsubscribe);
|
|
@@ -796,25 +796,24 @@ export default class KoniExtension {
|
|
|
796
796
|
return await this.#koniState.getAuthList();
|
|
797
797
|
}
|
|
798
798
|
_saveCurrentAccountAddress(address, callback) {
|
|
799
|
-
this.#koniState.
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
799
|
+
let accountInfo = this.#koniState.keyringService.currentAccount;
|
|
800
|
+
if (!accountInfo) {
|
|
801
|
+
accountInfo = {
|
|
802
|
+
address,
|
|
803
|
+
currentGenesisHash: ALL_GENESIS_HASH,
|
|
804
|
+
allGenesisHash: ALL_GENESIS_HASH || undefined
|
|
805
|
+
};
|
|
806
|
+
} else {
|
|
807
|
+
accountInfo.address = address;
|
|
808
|
+
if (address !== ALL_ACCOUNT_KEY) {
|
|
809
|
+
const currentKeyPair = keyring.getAccount(address);
|
|
810
|
+
accountInfo.currentGenesisHash = (currentKeyPair === null || currentKeyPair === void 0 ? void 0 : currentKeyPair.meta.genesisHash) || ALL_GENESIS_HASH;
|
|
806
811
|
} else {
|
|
807
|
-
accountInfo.
|
|
808
|
-
if (address !== ALL_ACCOUNT_KEY) {
|
|
809
|
-
const currentKeyPair = keyring.getAccount(address);
|
|
810
|
-
accountInfo.currentGenesisHash = (currentKeyPair === null || currentKeyPair === void 0 ? void 0 : currentKeyPair.meta.genesisHash) || ALL_GENESIS_HASH;
|
|
811
|
-
} else {
|
|
812
|
-
accountInfo.currentGenesisHash = accountInfo.allGenesisHash || ALL_GENESIS_HASH;
|
|
813
|
-
}
|
|
812
|
+
accountInfo.currentGenesisHash = accountInfo.allGenesisHash || ALL_GENESIS_HASH;
|
|
814
813
|
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
814
|
+
}
|
|
815
|
+
this.#koniState.setCurrentAccount(accountInfo, () => {
|
|
816
|
+
callback && callback(accountInfo);
|
|
818
817
|
});
|
|
819
818
|
}
|
|
820
819
|
updateCurrentAccountAddress(address) {
|
|
@@ -969,16 +968,10 @@ export default class KoniExtension {
|
|
|
969
968
|
throw Error('Require password to set up master password');
|
|
970
969
|
} else {
|
|
971
970
|
keyring.changeMasterPassword(password);
|
|
972
|
-
this.#koniState.
|
|
973
|
-
hasMasterPassword: true,
|
|
974
|
-
isLocked: false,
|
|
975
|
-
isReady: true
|
|
976
|
-
});
|
|
971
|
+
this.#koniState.updateKeyringState();
|
|
977
972
|
}
|
|
978
973
|
}
|
|
979
|
-
const currentAccount =
|
|
980
|
-
this.#koniState.getCurrentAccount(resolve);
|
|
981
|
-
});
|
|
974
|
+
const currentAccount = this.#koniState.keyringService.currentAccount;
|
|
982
975
|
const allGenesisHash = (currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.allGenesisHash) || undefined;
|
|
983
976
|
types === null || types === void 0 ? void 0 : types.forEach(type => {
|
|
984
977
|
const suri = getSuri(_suri, type);
|
|
@@ -1038,19 +1031,13 @@ export default class KoniExtension {
|
|
|
1038
1031
|
});
|
|
1039
1032
|
});
|
|
1040
1033
|
|
|
1041
|
-
// Remove history
|
|
1042
|
-
await this.#koniState.historyService.removeHistoryByAddress(address);
|
|
1043
|
-
|
|
1044
1034
|
// Set current account to all account
|
|
1045
1035
|
await new Promise(resolve => {
|
|
1046
|
-
this.#koniState.
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
address: ALL_ACCOUNT_KEY
|
|
1052
|
-
}, resolve);
|
|
1053
|
-
});
|
|
1036
|
+
const currentAccountInfo = this.#koniState.keyringService.currentAccount;
|
|
1037
|
+
this.#koniState.setCurrentAccount({
|
|
1038
|
+
currentGenesisHash: (currentAccountInfo === null || currentAccountInfo === void 0 ? void 0 : currentAccountInfo.allGenesisHash) || null,
|
|
1039
|
+
address: ALL_ACCOUNT_KEY
|
|
1040
|
+
}, resolve);
|
|
1054
1041
|
});
|
|
1055
1042
|
return true;
|
|
1056
1043
|
}
|
|
@@ -1301,7 +1288,7 @@ export default class KoniExtension {
|
|
|
1301
1288
|
if (!tokenInfo) {
|
|
1302
1289
|
errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, 'Not found token from registry'));
|
|
1303
1290
|
}
|
|
1304
|
-
if (isEthereumAddress(from) && isEthereumAddress(to) &&
|
|
1291
|
+
if (isEthereumAddress(from) && isEthereumAddress(to) && _isTokenEvmSmartContract(tokenInfo) && _getContractAddressOfToken(tokenInfo).length === 0) {
|
|
1305
1292
|
errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, 'Not found ERC20 address for this token'));
|
|
1306
1293
|
}
|
|
1307
1294
|
return [errors, keypair, transferValue, tokenInfo];
|
|
@@ -1341,7 +1328,7 @@ export default class KoniExtension {
|
|
|
1341
1328
|
const txVal = transferAll ? freeBalance.value : value || '0';
|
|
1342
1329
|
|
|
1343
1330
|
// Estimate with EVM API
|
|
1344
|
-
if (_isTokenEvmSmartContract(tokenInfo)) {
|
|
1331
|
+
if (_isTokenEvmSmartContract(tokenInfo) || _isLocalToken(tokenInfo)) {
|
|
1345
1332
|
[transaction, transferAmount.value] = await getERC20TransactionObject(_getContractAddressOfToken(tokenInfo), chainInfo, from, to, txVal, !!transferAll, evmApiMap);
|
|
1346
1333
|
} else {
|
|
1347
1334
|
[transaction, transferAmount.value] = await getEVMTransactionObject(chainInfo, to, txVal, !!transferAll, evmApiMap);
|
|
@@ -1740,9 +1727,7 @@ export default class KoniExtension {
|
|
|
1740
1727
|
resolve();
|
|
1741
1728
|
});
|
|
1742
1729
|
}
|
|
1743
|
-
const currentAccount =
|
|
1744
|
-
this.#koniState.getCurrentAccount(resolve);
|
|
1745
|
-
});
|
|
1730
|
+
const currentAccount = this.#koniState.keyringService.currentAccount;
|
|
1746
1731
|
const allGenesisHash = (currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.allGenesisHash) || undefined;
|
|
1747
1732
|
if (addresses.length <= 1) {
|
|
1748
1733
|
this.#koniState.setCurrentAccount({
|
|
@@ -2057,21 +2042,23 @@ export default class KoniExtension {
|
|
|
2057
2042
|
}
|
|
2058
2043
|
async submitBonding(inputData) {
|
|
2059
2044
|
const {
|
|
2045
|
+
address,
|
|
2060
2046
|
amount,
|
|
2061
2047
|
chain,
|
|
2062
2048
|
nominatorMetadata,
|
|
2063
2049
|
selectedValidators
|
|
2064
2050
|
} = inputData;
|
|
2065
|
-
if (!amount || !
|
|
2051
|
+
if (!amount || !selectedValidators) {
|
|
2066
2052
|
// Todo: Check and return error here
|
|
2067
2053
|
|
|
2068
2054
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INVALID_PARAMS)]);
|
|
2069
2055
|
}
|
|
2070
2056
|
const chainInfo = this.#koniState.getChainInfo(chain);
|
|
2071
2057
|
const substrateApi = this.#koniState.getSubstrateApi(chain);
|
|
2072
|
-
const extrinsic = await getBondingExtrinsic(chainInfo, amount,
|
|
2058
|
+
const extrinsic = await getBondingExtrinsic(chainInfo, amount, selectedValidators, substrateApi, address, nominatorMetadata);
|
|
2059
|
+
console.log('Bonding extrinsic: ', chain, extrinsic.toHex());
|
|
2073
2060
|
return await this.#koniState.transactionService.handleTransaction({
|
|
2074
|
-
address
|
|
2061
|
+
address,
|
|
2075
2062
|
chain: chain,
|
|
2076
2063
|
chainType: ChainType.SUBSTRATE,
|
|
2077
2064
|
data: inputData,
|
|
@@ -2092,6 +2079,7 @@ export default class KoniExtension {
|
|
|
2092
2079
|
}
|
|
2093
2080
|
const substrateApi = this.#koniState.getSubstrateApi(chain);
|
|
2094
2081
|
const extrinsic = await getUnbondingExtrinsic(nominatorMetadata, amount, chain, substrateApi, validatorAddress);
|
|
2082
|
+
console.log('unbonding extrinsic: ', extrinsic.toHex());
|
|
2095
2083
|
return await this.#koniState.transactionService.handleTransaction({
|
|
2096
2084
|
address: nominatorMetadata.address,
|
|
2097
2085
|
chain: chain,
|
|
@@ -2112,6 +2100,7 @@ export default class KoniExtension {
|
|
|
2112
2100
|
}
|
|
2113
2101
|
const dotSamaApi = this.#koniState.getSubstrateApi(chain);
|
|
2114
2102
|
const extrinsic = await getWithdrawalExtrinsic(dotSamaApi, chain, nominatorMetadata, validatorAddress);
|
|
2103
|
+
console.log('Stake withdrawal extrinsic: ', extrinsic.toHex());
|
|
2115
2104
|
return await this.#koniState.transactionService.handleTransaction({
|
|
2116
2105
|
address: nominatorMetadata.address,
|
|
2117
2106
|
chain: chain,
|
|
@@ -2133,6 +2122,7 @@ export default class KoniExtension {
|
|
|
2133
2122
|
}
|
|
2134
2123
|
const substrateApi = this.#koniState.getSubstrateApi(chain);
|
|
2135
2124
|
const extrinsic = await getClaimRewardExtrinsic(substrateApi, chain, address, stakingType, bondReward);
|
|
2125
|
+
console.log('Staking claim reward extrinsic: ', extrinsic.toHex());
|
|
2136
2126
|
return await this.#koniState.transactionService.handleTransaction({
|
|
2137
2127
|
address,
|
|
2138
2128
|
chain: chain,
|
|
@@ -2153,6 +2143,7 @@ export default class KoniExtension {
|
|
|
2153
2143
|
}
|
|
2154
2144
|
const substrateApi = this.#koniState.getSubstrateApi(chain);
|
|
2155
2145
|
const extrinsic = await getCancelWithdrawalExtrinsic(substrateApi, chain, selectedUnstaking);
|
|
2146
|
+
console.log('Cancel stake withdrawal extrinsic', extrinsic.toHex());
|
|
2156
2147
|
return await this.#koniState.transactionService.handleTransaction({
|
|
2157
2148
|
address,
|
|
2158
2149
|
chain,
|
|
@@ -2170,8 +2161,11 @@ export default class KoniExtension {
|
|
|
2170
2161
|
nominatorMetadata,
|
|
2171
2162
|
selectedPool
|
|
2172
2163
|
} = inputData;
|
|
2164
|
+
|
|
2165
|
+
// TODO: can't stake when unstake all
|
|
2173
2166
|
const substrateApi = this.#koniState.getSubstrateApi(chain);
|
|
2174
2167
|
const extrinsic = await getPoolingBondingExtrinsic(substrateApi, amount, selectedPool.id, nominatorMetadata);
|
|
2168
|
+
console.log('Join nomination pool extrinsic', extrinsic.toHex());
|
|
2175
2169
|
return await this.#koniState.transactionService.handleTransaction({
|
|
2176
2170
|
address,
|
|
2177
2171
|
chain,
|
|
@@ -2189,6 +2183,7 @@ export default class KoniExtension {
|
|
|
2189
2183
|
} = inputData;
|
|
2190
2184
|
const substrateApi = this.#koniState.getSubstrateApi(chain);
|
|
2191
2185
|
const extrinsic = await getPoolingUnbondingExtrinsic(substrateApi, amount, nominatorMetadata);
|
|
2186
|
+
console.log('Nomination pool unbond extrinsic', extrinsic.toHex());
|
|
2192
2187
|
return await this.#koniState.transactionService.handleTransaction({
|
|
2193
2188
|
address: nominatorMetadata.address,
|
|
2194
2189
|
chain,
|
|
@@ -2259,12 +2254,13 @@ export default class KoniExtension {
|
|
|
2259
2254
|
}
|
|
2260
2255
|
keyringStateSubscribe(id, port) {
|
|
2261
2256
|
const cb = createSubscription(id, port);
|
|
2262
|
-
const
|
|
2257
|
+
const keyringStateSubject = this.#koniState.keyringService.keyringStateSubject;
|
|
2258
|
+
const subscription = keyringStateSubject.subscribe(value => cb(value));
|
|
2263
2259
|
this.createUnsubscriptionHandle(id, subscription.unsubscribe);
|
|
2264
2260
|
port.onDisconnect.addListener(() => {
|
|
2265
2261
|
this.cancelSubscription(id);
|
|
2266
2262
|
});
|
|
2267
|
-
return this.#koniState.
|
|
2263
|
+
return this.#koniState.keyringService.keyringState;
|
|
2268
2264
|
}
|
|
2269
2265
|
keyringChangeMasterPassword({
|
|
2270
2266
|
createNew,
|
|
@@ -2295,11 +2291,7 @@ export default class KoniExtension {
|
|
|
2295
2291
|
status: false
|
|
2296
2292
|
};
|
|
2297
2293
|
}
|
|
2298
|
-
this.#koniState.
|
|
2299
|
-
hasMasterPassword: true,
|
|
2300
|
-
isLocked: false,
|
|
2301
|
-
isReady: true
|
|
2302
|
-
});
|
|
2294
|
+
this.#koniState.updateKeyringState();
|
|
2303
2295
|
return {
|
|
2304
2296
|
status: true,
|
|
2305
2297
|
errors: []
|
|
@@ -2334,11 +2326,7 @@ export default class KoniExtension {
|
|
|
2334
2326
|
status: false
|
|
2335
2327
|
};
|
|
2336
2328
|
}
|
|
2337
|
-
this.#koniState.
|
|
2338
|
-
isReady: true,
|
|
2339
|
-
hasMasterPassword: true,
|
|
2340
|
-
isLocked: false
|
|
2341
|
-
});
|
|
2329
|
+
this.#koniState.updateKeyringState();
|
|
2342
2330
|
return {
|
|
2343
2331
|
status: true,
|
|
2344
2332
|
errors: []
|
|
@@ -2346,11 +2334,8 @@ export default class KoniExtension {
|
|
|
2346
2334
|
}
|
|
2347
2335
|
keyringLock() {
|
|
2348
2336
|
keyring.lockAll();
|
|
2349
|
-
this.#koniState.
|
|
2350
|
-
|
|
2351
|
-
hasMasterPassword: true,
|
|
2352
|
-
isLocked: true
|
|
2353
|
-
});
|
|
2337
|
+
this.#koniState.updateKeyringState();
|
|
2338
|
+
clearTimeout(this.#lockTimeOut);
|
|
2354
2339
|
}
|
|
2355
2340
|
keyringExportMnemonic({
|
|
2356
2341
|
address,
|
|
@@ -2393,6 +2378,7 @@ export default class KoniExtension {
|
|
|
2393
2378
|
payload
|
|
2394
2379
|
} = request;
|
|
2395
2380
|
const registry = new TypeRegistry();
|
|
2381
|
+
let isEvm = false;
|
|
2396
2382
|
if (isJsonPayload(payload)) {
|
|
2397
2383
|
// Get the metadata for the genesisHash
|
|
2398
2384
|
const currentMetadata = this.#koniState.knownMetadata.find(meta => meta.genesisHash === payload.genesisHash);
|
|
@@ -2402,11 +2388,16 @@ export default class KoniExtension {
|
|
|
2402
2388
|
if (currentMetadata) {
|
|
2403
2389
|
registry.register(currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.types);
|
|
2404
2390
|
}
|
|
2391
|
+
const [, chainInfo] = this.#koniState.findNetworkKeyByGenesisHash(payload.genesisHash);
|
|
2392
|
+
if (chainInfo) {
|
|
2393
|
+
isEvm = _isChainEvmCompatible(chainInfo);
|
|
2394
|
+
}
|
|
2405
2395
|
}
|
|
2406
2396
|
const result = request.sign(registry, pair);
|
|
2407
2397
|
resolve({
|
|
2408
2398
|
id,
|
|
2409
|
-
|
|
2399
|
+
// In case evm chain, must be cut 2 character after 0x
|
|
2400
|
+
signature: isEvm ? `0x${result.signature.slice(4)}` : result.signature
|
|
2410
2401
|
});
|
|
2411
2402
|
return true;
|
|
2412
2403
|
}
|
|
@@ -2683,6 +2674,10 @@ export default class KoniExtension {
|
|
|
2683
2674
|
// --------------------------------------------------------------
|
|
2684
2675
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2685
2676
|
async handle(id, type, request, port) {
|
|
2677
|
+
clearTimeout(this.#lockTimeOut);
|
|
2678
|
+
this.#lockTimeOut = setTimeout(() => {
|
|
2679
|
+
this.keyringLock();
|
|
2680
|
+
}, DEFAULT_TIME_AUTO_LOCK);
|
|
2686
2681
|
switch (type) {
|
|
2687
2682
|
/// Clone from PolkadotJs
|
|
2688
2683
|
case 'pri(accounts.create.external)':
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/// <reference types="chrome" />
|
|
2
2
|
import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
|
|
3
|
-
import { AddTokenRequestExternal, ApiMap, AuthRequestV2, BalanceItem, BalanceJson, BrowserConfirmationType, ChainStakingMetadata, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrentAccountInfo, EvmSendTransactionParams, ExternalRequestPromise,
|
|
3
|
+
import { AddTokenRequestExternal, ApiMap, AuthRequestV2, BalanceItem, BalanceJson, BrowserConfirmationType, ChainStakingMetadata, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrentAccountInfo, EvmSendTransactionParams, ExternalRequestPromise, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCheckPublicAndSecretKey, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, ThemeNames, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
4
|
import { AccountJson, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning } from '@subwallet/extension-base/background/types';
|
|
5
5
|
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
|
|
6
6
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
7
7
|
import { _ChainConnectionStatus, _ChainState, _NetworkUpsertParams, _ValidateCustomAssetRequest } from '@subwallet/extension-base/services/chain-service/types';
|
|
8
|
+
import { EventService } from '@subwallet/extension-base/services/event-service';
|
|
8
9
|
import { HistoryService } from '@subwallet/extension-base/services/history-service';
|
|
10
|
+
import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
|
|
9
11
|
import MigrationService from '@subwallet/extension-base/services/migration-service';
|
|
10
12
|
import NotificationService from '@subwallet/extension-base/services/notification-service/NotificationService';
|
|
11
13
|
import { PriceService } from '@subwallet/extension-base/services/price-service';
|
|
@@ -13,6 +15,7 @@ import RequestService from '@subwallet/extension-base/services/request-service';
|
|
|
13
15
|
import { AuthUrls, MetaRequest, SignRequest } from '@subwallet/extension-base/services/request-service/types';
|
|
14
16
|
import SettingService from '@subwallet/extension-base/services/setting-service/SettingService';
|
|
15
17
|
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
18
|
+
import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
|
|
16
19
|
import TransactionService from '@subwallet/extension-base/services/transaction-service';
|
|
17
20
|
import { MetadataDef, ProviderMeta } from '@subwallet/extension-inject/types';
|
|
18
21
|
import SimpleKeyring from 'eth-simple-keyring';
|
|
@@ -26,11 +29,8 @@ export default class KoniState {
|
|
|
26
29
|
private injectedProviders;
|
|
27
30
|
private readonly providers;
|
|
28
31
|
private readonly unsubscriptionMap;
|
|
29
|
-
private readonly currentAccountStore;
|
|
30
32
|
private readonly accountRefStore;
|
|
31
|
-
private readonly keyringStateSubject;
|
|
32
33
|
private externalRequest;
|
|
33
|
-
private keyringState;
|
|
34
34
|
private serviceInfoSubject;
|
|
35
35
|
private balanceMap;
|
|
36
36
|
private balanceSubject;
|
|
@@ -44,6 +44,8 @@ export default class KoniState {
|
|
|
44
44
|
private stakingRewardState;
|
|
45
45
|
private lazyMap;
|
|
46
46
|
readonly notificationService: NotificationService;
|
|
47
|
+
readonly eventService: EventService;
|
|
48
|
+
readonly keyringService: KeyringService;
|
|
47
49
|
readonly chainService: ChainService;
|
|
48
50
|
readonly dbService: DatabaseService;
|
|
49
51
|
private cron;
|
|
@@ -57,6 +59,7 @@ export default class KoniState {
|
|
|
57
59
|
readonly priceService: PriceService;
|
|
58
60
|
readonly balanceService: BalanceService;
|
|
59
61
|
readonly migrationService: MigrationService;
|
|
62
|
+
readonly subscanService: SubscanService;
|
|
60
63
|
constructor(providers?: Providers);
|
|
61
64
|
get knownMetadata(): MetadataDef[];
|
|
62
65
|
injectMetadata(url: string, request: MetadataDef): Promise<boolean>;
|
|
@@ -76,9 +79,7 @@ export default class KoniState {
|
|
|
76
79
|
private startSubscription;
|
|
77
80
|
onReady(): void;
|
|
78
81
|
isReady(): boolean;
|
|
79
|
-
|
|
80
|
-
subscribeKeyringState(): Subject<KeyringState>;
|
|
81
|
-
setKeyringState(data: KeyringState, callback?: () => void): void;
|
|
82
|
+
updateKeyringState(isReady?: boolean, callback?: () => void): void;
|
|
82
83
|
private lazyNext;
|
|
83
84
|
getAuthRequestV2(id: string): AuthRequestV2;
|
|
84
85
|
setAuthorize(data: AuthUrls, callback?: () => void): void;
|
|
@@ -106,7 +107,7 @@ export default class KoniState {
|
|
|
106
107
|
setNftCollection(network: string, data: NftCollection, callback?: (data: NftCollection) => void): void;
|
|
107
108
|
getNftCollection(): import("dexie").PromiseExtended<NftCollection[]>;
|
|
108
109
|
subscribeNftCollection(): import("dexie").Observable<NftCollection[]>;
|
|
109
|
-
resetNft(newAddress: string):
|
|
110
|
+
resetNft(newAddress: string): void;
|
|
110
111
|
updateNftData(network: string, nftData: NftItem, address: string, callback?: (nftData: NftItem) => void): void;
|
|
111
112
|
removeNfts(chain: string, address: string, collectionId: string, nftIds: string[]): import("dexie").PromiseExtended<number>;
|
|
112
113
|
deleteNftCollection(chain: string, collectionId: string): Promise<void>;
|
|
@@ -120,7 +121,6 @@ export default class KoniState {
|
|
|
120
121
|
removeAccountRef(address: string, callback: () => void): void;
|
|
121
122
|
getStakingReward(update: (value: StakingRewardJson) => void): void;
|
|
122
123
|
subscribeStakingReward(): Subject<StakingRewardJson>;
|
|
123
|
-
getCurrentAccount(update: (value: CurrentAccountInfo) => void): void;
|
|
124
124
|
setCurrentAccount(data: CurrentAccountInfo, callback?: () => void): void;
|
|
125
125
|
setAccountTie(address: string, genesisHash: string | null): boolean;
|
|
126
126
|
switchEvmNetworkByUrl(shortenUrl: string, networkKey: string): Promise<void>;
|
|
@@ -135,9 +135,8 @@ export default class KoniState {
|
|
|
135
135
|
setBrowserConfirmationType(browserConfirmationType: BrowserConfirmationType, callback?: (settingData: UiSettings) => void): void;
|
|
136
136
|
setCamera(value: boolean): void;
|
|
137
137
|
subscribeSettingsSubject(): Subject<RequestSettingsType>;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
getDecodedAddresses(address?: string): Promise<string[]>;
|
|
138
|
+
getAccountAddress(): string | null;
|
|
139
|
+
getDecodedAddresses(address?: string): string[];
|
|
141
140
|
getAllAddresses(): string[];
|
|
142
141
|
private removeInactiveChainBalances;
|
|
143
142
|
getBalance(reset?: boolean): BalanceJson;
|
|
@@ -145,7 +144,7 @@ export default class KoniState {
|
|
|
145
144
|
switchAccount(newAddress: string): Promise<void>;
|
|
146
145
|
resetBalanceMap(newAddress: string): Promise<void>;
|
|
147
146
|
resetCrowdloanMap(newAddress: string): Promise<void>;
|
|
148
|
-
resetStaking(newAddress: string):
|
|
147
|
+
resetStaking(newAddress: string): void;
|
|
149
148
|
setBalanceItem(tokenSlug: string, item: BalanceItem): void;
|
|
150
149
|
private updateBalanceStore;
|
|
151
150
|
subscribeBalance(): Subject<BalanceJson>;
|
|
@@ -192,7 +191,7 @@ export default class KoniState {
|
|
|
192
191
|
refreshSubstrateApi(key: string): boolean;
|
|
193
192
|
refreshWeb3Api(key: string): void;
|
|
194
193
|
subscribeServiceInfo(): Subject<ServiceInfo>;
|
|
195
|
-
|
|
194
|
+
getServiceInfo(): ServiceInfo;
|
|
196
195
|
getExternalRequestMap(): Record<string, ExternalRequestPromise>;
|
|
197
196
|
setExternalRequestMap(id: string, value: ExternalRequestPromise): void;
|
|
198
197
|
getExternalRequest(id: string): ExternalRequestPromise;
|
|
@@ -220,5 +219,8 @@ export default class KoniState {
|
|
|
220
219
|
wakeup(): Promise<void>;
|
|
221
220
|
cancelSubscription(id: string): boolean;
|
|
222
221
|
createUnsubscriptionHandle(id: string, unsubscribe: () => void): void;
|
|
222
|
+
autoEnableChains(addresses: string[]): Promise<void>;
|
|
223
|
+
onAccountAdd(): void;
|
|
224
|
+
onAccountRemove(): void;
|
|
223
225
|
}
|
|
224
226
|
export {};
|