@subwallet/extension-base 1.0.2-1b → 1.0.2-2
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 +34 -16
- package/background/KoniTypes.js +7 -6
- package/background/errors/TransactionError.js +1 -21
- package/cjs/background/KoniTypes.js +7 -6
- package/cjs/background/errors/TransactionError.js +0 -20
- package/cjs/constants/index.js +26 -8
- package/cjs/koni/api/dotsama/balance.js +224 -49
- package/cjs/koni/api/dotsama/transfer.js +29 -30
- package/cjs/koni/api/nft/acala_nft/index.js +1 -4
- package/cjs/koni/api/nft/bit.country/index.js +1 -4
- package/cjs/koni/api/nft/evm_nft/index.js +3 -7
- package/cjs/koni/api/nft/index.js +6 -3
- package/cjs/koni/api/nft/karura_nft/index.js +1 -4
- package/cjs/koni/api/nft/rmrk_nft/index.js +1 -8
- package/cjs/koni/api/nft/statemine_nft/index.js +1 -4
- package/cjs/koni/api/nft/unique_nft/index.js +1 -6
- package/cjs/koni/api/nft/wasm_nft/index.js +111 -169
- package/cjs/koni/api/nft/wasm_nft/utils.js +7 -11
- package/cjs/koni/api/staking/bonding/amplitude.js +9 -13
- package/cjs/koni/api/staking/bonding/astar.js +13 -15
- package/cjs/koni/api/staking/bonding/index.js +10 -22
- package/cjs/koni/api/staking/bonding/paraChain.js +2 -85
- package/cjs/koni/api/staking/bonding/relayChain.js +16 -119
- package/cjs/koni/api/staking/bonding/utils.js +8 -27
- package/cjs/koni/api/tokens/wasm/index.js +4 -5
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/utils.js +13 -18
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/api/xcm/xcmPallet.js +6 -9
- package/cjs/koni/background/cron.js +47 -150
- package/cjs/koni/background/handlers/Extension.js +64 -106
- package/cjs/koni/background/handlers/State.js +21 -19
- package/cjs/koni/background/handlers/Tabs.js +1 -8
- package/cjs/koni/background/subscription.js +29 -32
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +8 -13
- package/cjs/services/chain-service/handler/light-client/index.js +0 -2
- package/cjs/services/chain-service/index.js +7 -6
- package/cjs/services/event-service/index.js +1 -5
- package/cjs/services/event-service/types.js +1 -11
- package/cjs/services/history-service/index.js +10 -16
- package/cjs/services/history-service/subsquid-multi-chain-history.js +9 -12
- package/cjs/services/price-service/coingecko.js +1 -0
- package/cjs/services/price-service/index.js +3 -2
- package/cjs/services/request-service/handler/AuthRequestHandler.js +2 -6
- package/cjs/services/storage-service/DatabaseService.js +33 -52
- package/cjs/services/storage-service/db-stores/Nft.js +17 -4
- package/cjs/services/transaction-service/event-parser/index.js +48 -20
- package/cjs/services/transaction-service/index.js +14 -23
- package/cjs/utils/index.js +14 -7
- package/constants/index.d.ts +13 -7
- package/constants/index.js +13 -7
- package/koni/api/dotsama/balance.d.ts +1 -0
- package/koni/api/dotsama/balance.js +197 -22
- package/koni/api/dotsama/transfer.js +4 -5
- package/koni/api/nft/acala_nft/index.js +1 -3
- package/koni/api/nft/bit.country/index.js +1 -3
- package/koni/api/nft/evm_nft/index.js +3 -6
- package/koni/api/nft/index.d.ts +2 -1
- package/koni/api/nft/index.js +6 -3
- package/koni/api/nft/karura_nft/index.js +1 -3
- package/koni/api/nft/nft.d.ts +0 -1
- package/koni/api/nft/rmrk_nft/index.js +1 -8
- package/koni/api/nft/statemine_nft/index.js +1 -3
- package/koni/api/nft/unique_nft/index.js +1 -5
- package/koni/api/nft/wasm_nft/index.d.ts +2 -0
- package/koni/api/nft/wasm_nft/index.js +109 -167
- package/koni/api/nft/wasm_nft/utils.d.ts +5 -7
- package/koni/api/nft/wasm_nft/utils.js +5 -7
- package/koni/api/staking/bonding/amplitude.d.ts +1 -0
- package/koni/api/staking/bonding/amplitude.js +10 -15
- package/koni/api/staking/bonding/astar.js +6 -8
- package/koni/api/staking/bonding/index.d.ts +1 -4
- package/koni/api/staking/bonding/index.js +13 -23
- package/koni/api/staking/bonding/paraChain.d.ts +0 -3
- package/koni/api/staking/bonding/paraChain.js +5 -86
- package/koni/api/staking/bonding/relayChain.d.ts +1 -5
- package/koni/api/staking/bonding/relayChain.js +18 -118
- package/koni/api/staking/bonding/utils.d.ts +2 -3
- package/koni/api/staking/bonding/utils.js +9 -27
- package/koni/api/tokens/wasm/index.js +4 -5
- package/koni/api/xcm/polkadotXcm.js +2 -2
- package/koni/api/xcm/utils.d.ts +6 -5
- package/koni/api/xcm/utils.js +10 -15
- package/koni/api/xcm/xTokens.js +2 -2
- package/koni/api/xcm/xcmPallet.js +9 -10
- package/koni/background/cron.d.ts +1 -6
- package/koni/background/cron.js +48 -151
- package/koni/background/handlers/Extension.d.ts +2 -2
- package/koni/background/handlers/Extension.js +67 -108
- package/koni/background/handlers/State.d.ts +6 -5
- package/koni/background/handlers/State.js +21 -19
- package/koni/background/handlers/Tabs.js +1 -8
- package/koni/background/subscription.js +30 -31
- package/package.json +8 -13
- package/packageInfo.js +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +9 -14
- package/services/chain-service/handler/light-client/index.d.ts +1 -17
- package/services/chain-service/handler/light-client/index.js +1 -1
- package/services/chain-service/helper/psp22_abi.json +881 -1041
- package/services/chain-service/helper/psp34_abi.json +1808 -2964
- package/services/chain-service/index.js +7 -6
- package/services/event-service/index.js +1 -5
- package/services/event-service/types.d.ts +9 -5
- package/services/event-service/types.js +1 -4
- package/services/history-service/index.d.ts +1 -1
- package/services/history-service/index.js +10 -16
- package/services/history-service/subsquid-multi-chain-history.js +11 -15
- package/services/price-service/coingecko.js +1 -0
- package/services/price-service/index.js +3 -2
- package/services/request-service/handler/AuthRequestHandler.js +2 -6
- package/services/storage-service/DatabaseService.d.ts +0 -1
- package/services/storage-service/DatabaseService.js +33 -52
- package/services/storage-service/db-stores/Nft.d.ts +2 -1
- package/services/storage-service/db-stores/Nft.js +16 -4
- package/services/transaction-service/event-parser/index.js +49 -21
- package/services/transaction-service/index.js +14 -23
- package/utils/index.d.ts +1 -1
- package/utils/index.js +12 -6
- package/cjs/koni/api/tokens/wasm/utils.js +0 -63
- package/koni/api/tokens/wasm/utils.d.ts +0 -6
- package/koni/api/tokens/wasm/utils.js +0 -54
|
@@ -427,11 +427,11 @@ export default class TransactionService {
|
|
|
427
427
|
}
|
|
428
428
|
try {
|
|
429
429
|
// Return one more history record if transaction send to account in the wallets
|
|
430
|
-
const toAccount = (historyItem === null || historyItem === void 0 ? void 0 : historyItem.to) && keyring.
|
|
430
|
+
const toAccount = (historyItem === null || historyItem === void 0 ? void 0 : historyItem.to) && keyring.getAccount(historyItem.to);
|
|
431
431
|
if (toAccount) {
|
|
432
432
|
return [historyItem, {
|
|
433
433
|
...historyItem,
|
|
434
|
-
address:
|
|
434
|
+
address: historyItem.to,
|
|
435
435
|
direction: TransactionDirection.RECEIVED
|
|
436
436
|
}];
|
|
437
437
|
}
|
|
@@ -456,27 +456,18 @@ export default class TransactionService {
|
|
|
456
456
|
handlePostProcessing(id) {
|
|
457
457
|
// must be done after success/failure to make sure the transaction is finalized
|
|
458
458
|
const transaction = this.getTransaction(id);
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
recipient && this.databaseService.addNft(recipient.address, {
|
|
472
|
-
...inputData.nftItem,
|
|
473
|
-
owner: recipient.address
|
|
474
|
-
}).catch(console.error);
|
|
475
|
-
} catch (e) {
|
|
476
|
-
console.error(e);
|
|
477
|
-
}
|
|
478
|
-
} else if ([ExtrinsicType.STAKING_BOND, ExtrinsicType.STAKING_UNBOND, ExtrinsicType.STAKING_WITHDRAW, ExtrinsicType.STAKING_CANCEL_UNSTAKE, ExtrinsicType.STAKING_CLAIM_REWARD, ExtrinsicType.STAKING_JOIN_POOL, ExtrinsicType.STAKING_POOL_WITHDRAW, ExtrinsicType.STAKING_LEAVE_POOL].includes(transaction.extrinsicType)) {
|
|
479
|
-
this.eventService.emit('transaction.submitStaking', transaction.chain);
|
|
459
|
+
switch (transaction.extrinsicType) {
|
|
460
|
+
case ExtrinsicType.SEND_NFT:
|
|
461
|
+
{
|
|
462
|
+
const inputData = parseTransactionData(transaction.data);
|
|
463
|
+
const sender = keyring.getAccount(inputData.senderAddress);
|
|
464
|
+
const recipient = keyring.getAccount(inputData.recipientAddress);
|
|
465
|
+
sender && this.databaseService.handleNftTransfer(transaction.chain, [sender.address, ALL_ACCOUNT_KEY], inputData.nftItem).catch(console.error);
|
|
466
|
+
recipient && this.databaseService.addNft(recipient.address, {
|
|
467
|
+
...inputData.nftItem,
|
|
468
|
+
owner: recipient.address
|
|
469
|
+
}).catch(console.error);
|
|
470
|
+
}
|
|
480
471
|
}
|
|
481
472
|
}
|
|
482
473
|
onSuccess({
|
package/utils/index.d.ts
CHANGED
|
@@ -34,6 +34,6 @@ export declare function mergeNetworkProviders(customNetwork: NetworkJson, predef
|
|
|
34
34
|
};
|
|
35
35
|
export declare const filterAndSortingAccountByAuthType: (accounts: AccountJson[], accountAuthType: AccountAuthType, sorting?: boolean) => AccountJson[];
|
|
36
36
|
export declare function parseRawNumber(value: string): number;
|
|
37
|
+
export declare function parseNumberToDisplay(amount: BN, decimals: number | undefined): string;
|
|
37
38
|
export declare function isSameAddress(address1: string, address2: string): boolean;
|
|
38
39
|
export declare function getDomainFromUrl(url: string): string;
|
|
39
|
-
export declare function waitTimeout(ms: number): Promise<void>;
|
package/utils/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { CrowdloanParaState } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
6
|
+
import BigNumber from 'bignumber.js';
|
|
6
7
|
import { BN, hexToU8a, isHex } from '@polkadot/util';
|
|
7
8
|
import { decodeAddress, encodeAddress, ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
|
|
8
9
|
export { canDerive } from "./canDerive.js";
|
|
@@ -263,16 +264,21 @@ export const filterAndSortingAccountByAuthType = (accounts, accountAuthType, sor
|
|
|
263
264
|
export function parseRawNumber(value) {
|
|
264
265
|
return parseFloat(value.replaceAll(',', ''));
|
|
265
266
|
}
|
|
266
|
-
export function
|
|
267
|
-
if (
|
|
268
|
-
return
|
|
267
|
+
export function parseNumberToDisplay(amount, decimals) {
|
|
268
|
+
if (!decimals) {
|
|
269
|
+
return '0';
|
|
269
270
|
}
|
|
271
|
+
const parsedAmount = parseRawNumber(amount.toString());
|
|
272
|
+
const bigN = new BigNumber(parsedAmount / 10 ** decimals);
|
|
273
|
+
const roundedString = bigN.toFixed(9);
|
|
274
|
+
const formattedString = parseFloat(roundedString); // remove excess zeros at the end
|
|
275
|
+
|
|
276
|
+
return formattedString.toString();
|
|
277
|
+
}
|
|
278
|
+
export function isSameAddress(address1, address2) {
|
|
270
279
|
return reformatAddress(address1, 0) === reformatAddress(address2, 0); // TODO: maybe there's a better way
|
|
271
280
|
}
|
|
272
281
|
|
|
273
282
|
export function getDomainFromUrl(url) {
|
|
274
283
|
return url.replace(/^(https?:\/\/)?(www\.)?/, '').split('/')[0];
|
|
275
|
-
}
|
|
276
|
-
export async function waitTimeout(ms) {
|
|
277
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
278
284
|
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getDefaultWeightV2 = getDefaultWeightV2;
|
|
7
|
-
exports.getWasmContractGasLimit = getWasmContractGasLimit;
|
|
8
|
-
var _util = require("@polkadot/util");
|
|
9
|
-
// Copyright 2019-2022 @subwallet/extension-base
|
|
10
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
-
|
|
12
|
-
const MAX_CALL_WEIGHT = '5000000000000';
|
|
13
|
-
const DEFAULT_REF_TIME = '1000000000000';
|
|
14
|
-
const toContractAbiMessage = (contractPromise, message) => {
|
|
15
|
-
const value = contractPromise.abi.messages.find(m => m.method === message);
|
|
16
|
-
if (!value) {
|
|
17
|
-
const messages = contractPromise === null || contractPromise === void 0 ? void 0 : contractPromise.abi.messages.map(m => m.method).join(', ');
|
|
18
|
-
const error = `"${message}" not found in metadata.spec.messages: [${messages}]`;
|
|
19
|
-
console.error(error);
|
|
20
|
-
return {
|
|
21
|
-
ok: false,
|
|
22
|
-
error
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
ok: true,
|
|
27
|
-
value
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
async function getWasmContractGasLimit(api, callerAddress, message, contract) {
|
|
31
|
-
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
32
|
-
let args = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
|
|
33
|
-
try {
|
|
34
|
-
var _abiMessage$value;
|
|
35
|
-
const abiMessage = toContractAbiMessage(contract, message);
|
|
36
|
-
if (!abiMessage.ok) {
|
|
37
|
-
return getDefaultWeightV2(api, true);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
const {
|
|
42
|
-
gasLimit,
|
|
43
|
-
storageDepositLimit,
|
|
44
|
-
value
|
|
45
|
-
} = options;
|
|
46
|
-
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
const {
|
|
49
|
-
gasRequired
|
|
50
|
-
} = await api.call.contractsApi.call(callerAddress, contract.address, value !== null && value !== void 0 ? value : new _util.BN(0), gasLimit !== null && gasLimit !== void 0 ? gasLimit : null, storageDepositLimit !== null && storageDepositLimit !== void 0 ? storageDepositLimit : null, abiMessage === null || abiMessage === void 0 ? void 0 : (_abiMessage$value = abiMessage.value) === null || _abiMessage$value === void 0 ? void 0 : _abiMessage$value.toU8a(args));
|
|
51
|
-
return gasRequired;
|
|
52
|
-
} catch {
|
|
53
|
-
return getDefaultWeightV2(api, true);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function getDefaultWeightV2(apiPromise, isFallback) {
|
|
57
|
-
const proofSize = isFallback ? 3407872 : MAX_CALL_WEIGHT; // TODO: handle error better
|
|
58
|
-
const refTime = isFallback ? 32490000000 : DEFAULT_REF_TIME;
|
|
59
|
-
return apiPromise.registry.createType('WeightV2', {
|
|
60
|
-
refTime,
|
|
61
|
-
proofSize
|
|
62
|
-
});
|
|
63
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ApiPromise } from '@polkadot/api';
|
|
2
|
-
import { ContractPromise } from '@polkadot/api-contract';
|
|
3
|
-
import { WeightV2 } from '@polkadot/types/interfaces';
|
|
4
|
-
import { Codec } from '@polkadot/types/types';
|
|
5
|
-
export declare function getWasmContractGasLimit(api: ApiPromise, callerAddress: string, message: string, contract: ContractPromise, options?: {}, args?: never[]): Promise<Codec>;
|
|
6
|
-
export declare function getDefaultWeightV2(apiPromise: ApiPromise, isFallback?: boolean): WeightV2;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { BN } from '@polkadot/util';
|
|
5
|
-
const MAX_CALL_WEIGHT = '5000000000000';
|
|
6
|
-
const DEFAULT_REF_TIME = '1000000000000';
|
|
7
|
-
const toContractAbiMessage = (contractPromise, message) => {
|
|
8
|
-
const value = contractPromise.abi.messages.find(m => m.method === message);
|
|
9
|
-
if (!value) {
|
|
10
|
-
const messages = contractPromise === null || contractPromise === void 0 ? void 0 : contractPromise.abi.messages.map(m => m.method).join(', ');
|
|
11
|
-
const error = `"${message}" not found in metadata.spec.messages: [${messages}]`;
|
|
12
|
-
console.error(error);
|
|
13
|
-
return {
|
|
14
|
-
ok: false,
|
|
15
|
-
error
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
return {
|
|
19
|
-
ok: true,
|
|
20
|
-
value
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
export async function getWasmContractGasLimit(api, callerAddress, message, contract, options = {}, args = []) {
|
|
24
|
-
try {
|
|
25
|
-
var _abiMessage$value;
|
|
26
|
-
const abiMessage = toContractAbiMessage(contract, message);
|
|
27
|
-
if (!abiMessage.ok) {
|
|
28
|
-
return getDefaultWeightV2(api, true);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
const {
|
|
33
|
-
gasLimit,
|
|
34
|
-
storageDepositLimit,
|
|
35
|
-
value
|
|
36
|
-
} = options;
|
|
37
|
-
|
|
38
|
-
// @ts-ignore
|
|
39
|
-
const {
|
|
40
|
-
gasRequired
|
|
41
|
-
} = await api.call.contractsApi.call(callerAddress, contract.address, value !== null && value !== void 0 ? value : new BN(0), gasLimit !== null && gasLimit !== void 0 ? gasLimit : null, storageDepositLimit !== null && storageDepositLimit !== void 0 ? storageDepositLimit : null, abiMessage === null || abiMessage === void 0 ? void 0 : (_abiMessage$value = abiMessage.value) === null || _abiMessage$value === void 0 ? void 0 : _abiMessage$value.toU8a(args));
|
|
42
|
-
return gasRequired;
|
|
43
|
-
} catch {
|
|
44
|
-
return getDefaultWeightV2(api, true);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export function getDefaultWeightV2(apiPromise, isFallback) {
|
|
48
|
-
const proofSize = isFallback ? 3407872 : MAX_CALL_WEIGHT; // TODO: handle error better
|
|
49
|
-
const refTime = isFallback ? 32490000000 : DEFAULT_REF_TIME;
|
|
50
|
-
return apiPromise.registry.createType('WeightV2', {
|
|
51
|
-
refTime,
|
|
52
|
-
proofSize
|
|
53
|
-
});
|
|
54
|
-
}
|