@subwallet/extension-base 1.0.4-0 → 1.0.5-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 +37 -16
- package/background/KoniTypes.js +2 -0
- package/background/errors/TransactionError.js +4 -0
- package/background/handlers/State.d.ts +1 -1
- package/background/handlers/State.js +2 -8
- package/background/handlers/subscriptions.js +0 -1
- package/background/types.d.ts +2 -2
- package/cjs/background/KoniTypes.js +2 -0
- package/cjs/background/errors/TransactionError.js +4 -0
- package/cjs/background/handlers/State.js +1 -7
- package/cjs/background/handlers/subscriptions.js +0 -1
- package/cjs/constants/index.js +6 -6
- package/cjs/koni/api/coingecko.js +1 -4
- package/cjs/koni/api/dotsama/balance.js +7 -5
- package/cjs/koni/api/dotsama/crowdloan.js +0 -4
- package/cjs/koni/api/dotsama/transfer.js +0 -4
- package/cjs/koni/api/nft/acala_nft/index.js +1 -1
- package/cjs/koni/api/nft/bit.country/index.js +1 -1
- package/cjs/koni/api/nft/evm_nft/index.js +2 -3
- package/cjs/koni/api/nft/index.js +1 -2
- package/cjs/koni/api/nft/karura_nft/index.js +1 -1
- package/cjs/koni/api/nft/quartz_nft/index.js +1 -1
- package/cjs/koni/api/nft/rmrk_nft/index.js +2 -3
- package/cjs/koni/api/nft/statemine_nft/index.js +1 -1
- package/cjs/koni/api/nft/transfer.js +5 -5
- package/cjs/koni/api/nft/unique_nft/index.js +1 -1
- package/cjs/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
- package/cjs/koni/api/nft/wasm_nft/index.js +1 -2
- package/cjs/koni/api/staking/bonding/amplitude.js +9 -2
- package/cjs/koni/api/staking/bonding/astar.js +37 -13
- package/cjs/koni/api/staking/bonding/paraChain.js +10 -2
- package/cjs/koni/api/staking/bonding/relayChain.js +21 -4
- package/cjs/koni/api/staking/bonding/utils.js +4 -0
- package/cjs/koni/api/staking/relayChain.js +0 -1
- package/cjs/koni/api/staking/subsquidStaking.js +0 -2
- package/cjs/koni/api/tokens/wasm/index.js +0 -1
- package/cjs/koni/api/tokens/wasm/utils.js +0 -1
- package/cjs/koni/api/xcm/index.js +0 -1
- package/cjs/koni/background/cron.js +0 -45
- package/cjs/koni/background/handlers/Extension.js +204 -132
- package/cjs/koni/background/handlers/State.js +30 -3
- package/cjs/koni/background/handlers/Tabs.js +34 -2
- package/cjs/koni/background/handlers/index.js +3 -2
- package/cjs/koni/background/subscription.js +0 -26
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +1 -1
- package/cjs/services/chain-service/handler/EvmChainHandler.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +3 -10
- package/cjs/services/chain-service/handler/light-client/index.js +9 -6
- package/cjs/services/chain-service/index.js +75 -28
- package/cjs/services/chain-service/utils.js +3 -0
- package/cjs/services/history-service/helpers/recoverHistoryStatus.js +108 -0
- package/cjs/services/history-service/index.js +60 -5
- package/cjs/services/history-service/subsquid-multi-chain-history.js +3 -2
- package/cjs/services/history-service/testChainMap.js +724 -0
- package/cjs/services/keyring-service/index.js +9 -2
- package/cjs/services/migration-service/index.js +7 -7
- package/cjs/services/migration-service/scripts/MigrateAuthUrls.js +39 -0
- package/cjs/services/migration-service/scripts/MigrateAutoLock.js +30 -0
- package/cjs/services/migration-service/scripts/MigrateChainPatrol.js +30 -0
- package/cjs/services/migration-service/scripts/index.js +7 -1
- package/cjs/services/price-service/coingecko.js +1 -1
- package/cjs/services/price-service/index.js +0 -4
- package/cjs/services/request-service/handler/AuthRequestHandler.js +8 -1
- package/cjs/services/request-service/handler/EvmRequestHandler.js +21 -0
- package/cjs/services/request-service/handler/MetadataRequestHandler.js +6 -0
- package/cjs/services/request-service/handler/SubstrateRequestHandler.js +6 -0
- package/cjs/services/request-service/index.js +6 -0
- package/cjs/services/setting-service/SettingService.js +4 -9
- package/cjs/services/setting-service/constants.js +18 -2
- package/cjs/services/storage-service/DatabaseService.js +16 -44
- package/cjs/services/storage-service/databases/index.js +1 -1
- package/cjs/services/storage-service/db-stores/BaseStore.js +3 -0
- package/cjs/services/transaction-service/constants.js +11 -0
- package/cjs/services/transaction-service/index.js +31 -9
- package/cjs/services/transaction-service/utils.js +25 -14
- package/constants/index.d.ts +1 -1
- package/constants/index.js +1 -1
- package/koni/api/coingecko.js +1 -4
- package/koni/api/dotsama/balance.js +7 -5
- package/koni/api/dotsama/crowdloan.js +0 -4
- package/koni/api/dotsama/transfer.js +0 -4
- package/koni/api/nft/acala_nft/index.js +1 -1
- package/koni/api/nft/bit.country/index.js +1 -1
- package/koni/api/nft/evm_nft/index.js +2 -3
- package/koni/api/nft/index.js +1 -2
- package/koni/api/nft/karura_nft/index.js +1 -1
- package/koni/api/nft/quartz_nft/index.js +1 -1
- package/koni/api/nft/rmrk_nft/index.js +2 -3
- package/koni/api/nft/statemine_nft/index.js +1 -1
- package/koni/api/nft/transfer.js +5 -5
- package/koni/api/nft/unique_nft/index.js +1 -1
- package/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
- package/koni/api/nft/wasm_nft/index.js +1 -2
- package/koni/api/staking/bonding/amplitude.js +9 -2
- package/koni/api/staking/bonding/astar.d.ts +2 -1
- package/koni/api/staking/bonding/astar.js +36 -13
- package/koni/api/staking/bonding/paraChain.js +10 -2
- package/koni/api/staking/bonding/relayChain.js +21 -4
- package/koni/api/staking/bonding/utils.js +4 -0
- package/koni/api/staking/relayChain.js +0 -1
- package/koni/api/staking/subsquidStaking.js +0 -2
- package/koni/api/tokens/wasm/index.js +0 -1
- package/koni/api/tokens/wasm/utils.js +0 -1
- package/koni/api/xcm/index.js +0 -1
- package/koni/background/cron.js +0 -45
- package/koni/background/handlers/Extension.d.ts +3 -0
- package/koni/background/handlers/Extension.js +120 -51
- package/koni/background/handlers/State.d.ts +4 -1
- package/koni/background/handlers/State.js +30 -3
- package/koni/background/handlers/Tabs.d.ts +1 -0
- package/koni/background/handlers/Tabs.js +32 -1
- package/koni/background/handlers/index.js +3 -2
- package/koni/background/subscription.d.ts +0 -1
- package/koni/background/subscription.js +0 -26
- package/package.json +65 -39
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.js +1 -1
- package/services/chain-service/handler/EvmChainHandler.js +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +3 -10
- package/services/chain-service/handler/light-client/index.js +8 -6
- package/services/chain-service/helper/api-helper/spec/acala.d.ts +3 -3
- package/services/chain-service/index.d.ts +2 -1
- package/services/chain-service/index.js +75 -28
- package/services/chain-service/utils.js +3 -0
- package/services/history-service/helpers/recoverHistoryStatus.d.ts +11 -0
- package/services/history-service/helpers/recoverHistoryStatus.js +98 -0
- package/services/history-service/index.d.ts +6 -0
- package/services/history-service/index.js +61 -6
- package/services/history-service/subsquid-multi-chain-history.js +3 -2
- package/services/history-service/testChainMap.d.ts +3 -0
- package/services/history-service/testChainMap.js +716 -0
- package/services/keyring-service/index.d.ts +1 -0
- package/services/keyring-service/index.js +9 -2
- package/services/migration-service/index.js +7 -7
- package/services/migration-service/scripts/MigrateAuthUrls.d.ts +4 -0
- package/services/migration-service/scripts/MigrateAuthUrls.js +31 -0
- package/services/migration-service/scripts/MigrateAutoLock.d.ts +4 -0
- package/services/migration-service/scripts/MigrateAutoLock.js +22 -0
- package/services/migration-service/scripts/MigrateChainPatrol.d.ts +4 -0
- package/services/migration-service/scripts/MigrateChainPatrol.js +22 -0
- package/services/migration-service/scripts/index.js +7 -1
- package/services/price-service/coingecko.js +1 -1
- package/services/price-service/index.js +0 -4
- package/services/request-service/handler/AuthRequestHandler.d.ts +1 -0
- package/services/request-service/handler/AuthRequestHandler.js +8 -1
- package/services/request-service/handler/EvmRequestHandler.d.ts +1 -0
- package/services/request-service/handler/EvmRequestHandler.js +21 -0
- package/services/request-service/handler/MetadataRequestHandler.d.ts +1 -0
- package/services/request-service/handler/MetadataRequestHandler.js +6 -0
- package/services/request-service/handler/SubstrateRequestHandler.d.ts +1 -0
- package/services/request-service/handler/SubstrateRequestHandler.js +6 -0
- package/services/request-service/index.d.ts +1 -0
- package/services/request-service/index.js +6 -0
- package/services/setting-service/SettingService.d.ts +1 -0
- package/services/setting-service/SettingService.js +5 -10
- package/services/setting-service/constants.d.ts +4 -1
- package/services/setting-service/constants.js +14 -1
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +16 -44
- package/services/storage-service/databases/index.js +1 -1
- package/services/storage-service/db-stores/BaseStore.d.ts +1 -0
- package/services/storage-service/db-stores/BaseStore.js +3 -0
- package/services/transaction-service/constants.d.ts +1 -0
- package/services/transaction-service/constants.js +4 -0
- package/services/transaction-service/index.d.ts +2 -0
- package/services/transaction-service/index.js +32 -10
- package/services/transaction-service/utils.d.ts +1 -1
- package/services/transaction-service/utils.js +24 -13
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
4
5
|
import { CurrentAccountStore } from '@subwallet/extension-base/stores';
|
|
5
6
|
import { keyring } from '@subwallet/ui-keyring';
|
|
6
7
|
import { BehaviorSubject } from 'rxjs';
|
|
@@ -40,7 +41,6 @@ export class KeyringService {
|
|
|
40
41
|
|
|
41
42
|
// Remove account
|
|
42
43
|
removedAddresses.forEach(address => {
|
|
43
|
-
console.log('account.remove', address);
|
|
44
44
|
this.eventService.emit('account.remove', address);
|
|
45
45
|
});
|
|
46
46
|
} else if (beforeAddresses.length < afterAddresses.length) {
|
|
@@ -48,7 +48,6 @@ export class KeyringService {
|
|
|
48
48
|
|
|
49
49
|
// Add account
|
|
50
50
|
addedAddresses.forEach(address => {
|
|
51
|
-
console.log('account.add', address);
|
|
52
51
|
this.eventService.emit('account.add', address);
|
|
53
52
|
});
|
|
54
53
|
} else {
|
|
@@ -88,4 +87,12 @@ export class KeyringService {
|
|
|
88
87
|
this.eventService.emit('account.updateCurrent', currentAccountData);
|
|
89
88
|
this.currentAccountStore.set('CurrentAccountInfo', currentAccountData);
|
|
90
89
|
}
|
|
90
|
+
resetWallet(resetAll) {
|
|
91
|
+
keyring.resetWallet(resetAll);
|
|
92
|
+
this.updateKeyringState();
|
|
93
|
+
this.currentAccountSubject.next({
|
|
94
|
+
address: ALL_ACCOUNT_KEY,
|
|
95
|
+
currentGenesisHash: null
|
|
96
|
+
});
|
|
97
|
+
}
|
|
91
98
|
}
|
|
@@ -9,10 +9,12 @@ export default class MigrationService {
|
|
|
9
9
|
this.logger = createLogger('Migration');
|
|
10
10
|
}
|
|
11
11
|
async run() {
|
|
12
|
-
this.logger.log('Migrating...');
|
|
13
12
|
const keys = Object.keys(MigrationScripts).sort((a, b) => a.localeCompare(b));
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
|
|
14
|
+
// Await timeout 2s
|
|
15
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
16
|
+
for (let i = 0; i < keys.length; i++) {
|
|
17
|
+
try {
|
|
16
18
|
const JobClass = MigrationScripts[keys[i]];
|
|
17
19
|
const key = keys[i];
|
|
18
20
|
const name = JobClass.name;
|
|
@@ -21,7 +23,6 @@ export default class MigrationService {
|
|
|
21
23
|
key
|
|
22
24
|
}).first();
|
|
23
25
|
if (!check || key.startsWith(EVERYTIME)) {
|
|
24
|
-
this.logger.log('Running script: ', JobClass.name);
|
|
25
26
|
const job = new JobClass(this.state);
|
|
26
27
|
await job.run();
|
|
27
28
|
await this.state.dbService.stores.migration.table.put({
|
|
@@ -30,10 +31,9 @@ export default class MigrationService {
|
|
|
30
31
|
timestamp: new Date().getTime()
|
|
31
32
|
});
|
|
32
33
|
}
|
|
34
|
+
} catch (error) {
|
|
35
|
+
this.logger.error('Migration error: ', MigrationScripts[keys[i]].name, error);
|
|
33
36
|
}
|
|
34
|
-
} catch (error) {
|
|
35
|
-
this.logger.error('Migration error: ', error);
|
|
36
37
|
}
|
|
37
|
-
this.logger.log('Migration done.');
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
5
|
+
export default class MigrateSettings extends BaseMigrationJob {
|
|
6
|
+
async run() {
|
|
7
|
+
try {
|
|
8
|
+
return new Promise(resolve => {
|
|
9
|
+
this.state.getAuthorize(value => {
|
|
10
|
+
if (value) {
|
|
11
|
+
const key = 'app.stellaswap.com';
|
|
12
|
+
const stellaSwap = value[key];
|
|
13
|
+
if (stellaSwap) {
|
|
14
|
+
stellaSwap.currentEvmNetworkKey = 'moonbeam';
|
|
15
|
+
value[key] = stellaSwap;
|
|
16
|
+
this.state.setAuthorize(value, () => {
|
|
17
|
+
resolve();
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
resolve();
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
resolve();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.error(e);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
5
|
+
import { DEFAULT_AUTO_LOCK_TIME } from '@subwallet/extension-base/services/setting-service/constants';
|
|
6
|
+
export default class MigrateAutoLock extends BaseMigrationJob {
|
|
7
|
+
async run() {
|
|
8
|
+
try {
|
|
9
|
+
return new Promise(resolve => {
|
|
10
|
+
this.state.settingService.getSettings(currentSettings => {
|
|
11
|
+
this.state.settingService.setSettings({
|
|
12
|
+
...currentSettings,
|
|
13
|
+
timeAutoLock: DEFAULT_AUTO_LOCK_TIME
|
|
14
|
+
});
|
|
15
|
+
resolve();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
} catch (e) {
|
|
19
|
+
console.error(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
5
|
+
import { DEFAULT_CHAIN_PATROL_ENABLE } from '@subwallet/extension-base/services/setting-service/constants';
|
|
6
|
+
export default class MigrateChainPatrol extends BaseMigrationJob {
|
|
7
|
+
async run() {
|
|
8
|
+
try {
|
|
9
|
+
return new Promise(resolve => {
|
|
10
|
+
this.state.settingService.getSettings(currentSettings => {
|
|
11
|
+
this.state.settingService.setSettings({
|
|
12
|
+
...currentSettings,
|
|
13
|
+
enableChainPatrol: DEFAULT_CHAIN_PATROL_ENABLE
|
|
14
|
+
});
|
|
15
|
+
resolve();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
} catch (e) {
|
|
19
|
+
console.error(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import AutoEnableChainsTokens from '@subwallet/extension-base/services/migration-service/scripts/AutoEnableChainsTokens';
|
|
5
|
+
import MigrateAuthUrls from '@subwallet/extension-base/services/migration-service/scripts/MigrateAuthUrls';
|
|
6
|
+
import MigrateAutoLock from '@subwallet/extension-base/services/migration-service/scripts/MigrateAutoLock';
|
|
7
|
+
import MigrateChainPatrol from '@subwallet/extension-base/services/migration-service/scripts/MigrateChainPatrol';
|
|
5
8
|
import MigrateImportedToken from '@subwallet/extension-base/services/migration-service/scripts/MigrateImportedToken';
|
|
6
9
|
import MigrateNetworkSettings from '@subwallet/extension-base/services/migration-service/scripts/MigrateNetworkSettings';
|
|
7
10
|
import MigrateSettings from '@subwallet/extension-base/services/migration-service/scripts/MigrateSettings';
|
|
@@ -12,6 +15,9 @@ export default {
|
|
|
12
15
|
'1.0.1-20': MigrateImportedToken,
|
|
13
16
|
'1.0.1-30': MigrateTransactionHistory,
|
|
14
17
|
'1.0.1-40': AutoEnableChainsTokens,
|
|
15
|
-
'1.0.1-50': MigrateSettings
|
|
18
|
+
'1.0.1-50': MigrateSettings,
|
|
19
|
+
'1.0.1-60': MigrateAuthUrls,
|
|
20
|
+
'1.0.3-01': MigrateAutoLock,
|
|
21
|
+
'1.0.3-02': MigrateChainPatrol
|
|
16
22
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
17
23
|
};
|
|
@@ -34,7 +34,6 @@ export class PriceService {
|
|
|
34
34
|
}
|
|
35
35
|
refreshPriceData(priceIds) {
|
|
36
36
|
clearTimeout(this.refreshTimeout);
|
|
37
|
-
console.log('Refresh Price Data');
|
|
38
37
|
this.priceIds = priceIds || this.getPriceIds();
|
|
39
38
|
|
|
40
39
|
// Update for tokens price
|
|
@@ -63,7 +62,6 @@ export class PriceService {
|
|
|
63
62
|
await this.eventService.waitAssetReady;
|
|
64
63
|
this.status = ServiceStatus.INITIALIZED;
|
|
65
64
|
this.eventService.on('asset.updateState', eventHandler);
|
|
66
|
-
this.eventService.on('asset.updateState', eventHandler);
|
|
67
65
|
}
|
|
68
66
|
async loadData() {
|
|
69
67
|
const data = await this.dbService.getPriceStore();
|
|
@@ -74,7 +72,6 @@ export class PriceService {
|
|
|
74
72
|
}
|
|
75
73
|
startPromiseHandler = createPromiseHandler();
|
|
76
74
|
async start() {
|
|
77
|
-
console.debug('Start price service');
|
|
78
75
|
try {
|
|
79
76
|
this.startPromiseHandler = createPromiseHandler();
|
|
80
77
|
this.status = ServiceStatus.STARTING;
|
|
@@ -91,7 +88,6 @@ export class PriceService {
|
|
|
91
88
|
}
|
|
92
89
|
stopPromiseHandler = createPromiseHandler();
|
|
93
90
|
async stop() {
|
|
94
|
-
console.debug('Stop price service');
|
|
95
91
|
try {
|
|
96
92
|
this.status = ServiceStatus.STOPPING;
|
|
97
93
|
this.stopPromiseHandler = createPromiseHandler();
|
|
@@ -68,7 +68,7 @@ export default class AuthRequestHandler {
|
|
|
68
68
|
update(this.authorizeCached);
|
|
69
69
|
} else {
|
|
70
70
|
this.authorizeStore.get('authUrls', data => {
|
|
71
|
-
this.authorizeCached = data;
|
|
71
|
+
this.authorizeCached = data || {};
|
|
72
72
|
update(this.authorizeCached);
|
|
73
73
|
});
|
|
74
74
|
}
|
|
@@ -283,4 +283,11 @@ export default class AuthRequestHandler {
|
|
|
283
283
|
});
|
|
284
284
|
});
|
|
285
285
|
}
|
|
286
|
+
resetWallet() {
|
|
287
|
+
for (const request of Object.values(this.#authRequestsV2)) {
|
|
288
|
+
request.reject(new Error('Reset wallet'));
|
|
289
|
+
}
|
|
290
|
+
this.authSubjectV2.next([]);
|
|
291
|
+
this.setAuthorize({});
|
|
292
|
+
}
|
|
286
293
|
}
|
|
@@ -200,4 +200,25 @@ export default class EvmRequestHandler {
|
|
|
200
200
|
}
|
|
201
201
|
return true;
|
|
202
202
|
}
|
|
203
|
+
resetWallet() {
|
|
204
|
+
const confirmations = this.confirmationsQueueSubject.getValue();
|
|
205
|
+
for (const [type, requests] of Object.entries(confirmations)) {
|
|
206
|
+
for (const confirmation of Object.values(requests)) {
|
|
207
|
+
const {
|
|
208
|
+
id
|
|
209
|
+
} = confirmation;
|
|
210
|
+
const {
|
|
211
|
+
resolver
|
|
212
|
+
} = this.confirmationsPromiseMap[id];
|
|
213
|
+
if (!resolver || !confirmation) {
|
|
214
|
+
console.error('Not found confirmation', type, id);
|
|
215
|
+
} else {
|
|
216
|
+
resolver.reject(new Error('Reset wallet'));
|
|
217
|
+
}
|
|
218
|
+
delete this.confirmationsPromiseMap[id];
|
|
219
|
+
delete confirmations[type][id];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
this.confirmationsQueueSubject.next(confirmations);
|
|
223
|
+
}
|
|
203
224
|
}
|
|
@@ -72,4 +72,10 @@ export default class MetadataRequestHandler {
|
|
|
72
72
|
this.#requestService.popupOpen();
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
+
resetWallet() {
|
|
76
|
+
for (const request of Object.values(this.#metaRequests)) {
|
|
77
|
+
request.reject(new Error('Reset wallet'));
|
|
78
|
+
}
|
|
79
|
+
this.metaSubject.next([]);
|
|
80
|
+
}
|
|
75
81
|
}
|
|
@@ -14,4 +14,5 @@ export default class SubstrateRequestHandler {
|
|
|
14
14
|
get numSubstrateRequests(): number;
|
|
15
15
|
sign(url: string, request: RequestSign, account: AccountJson): Promise<ResponseSigning>;
|
|
16
16
|
signTransaction(id: string, address: string, url: string, payload: SignerPayloadJSON): Promise<ResponseSigning>;
|
|
17
|
+
resetWallet(): void;
|
|
17
18
|
}
|
|
@@ -51,4 +51,5 @@ export default class RequestService {
|
|
|
51
51
|
addConfirmation<CT extends ConfirmationType>(id: string, url: string, type: CT, payload: ConfirmationDefinitions[CT][0]['payload'], options?: ConfirmationsQueueItemOptions, validator?: (input: ConfirmationDefinitions[CT][1]) => Error | undefined): Promise<ConfirmationDefinitions[CT][1]>;
|
|
52
52
|
completeConfirmation(request: RequestConfirmationComplete): Promise<boolean>;
|
|
53
53
|
get numRequests(): number;
|
|
54
|
+
resetWallet(): void;
|
|
54
55
|
}
|
|
@@ -156,4 +156,10 @@ export default class RequestService {
|
|
|
156
156
|
get numRequests() {
|
|
157
157
|
return this.numMetaRequests + this.numAuthRequests + this.numSubstrateRequests + this.numEvmRequests;
|
|
158
158
|
}
|
|
159
|
+
resetWallet() {
|
|
160
|
+
this.#authRequestHandler.resetWallet();
|
|
161
|
+
this.#substrateRequestHandler.resetWallet();
|
|
162
|
+
this.#evmRequestHandler.resetWallet();
|
|
163
|
+
this.#metadataRequestHandler.resetWallet();
|
|
164
|
+
}
|
|
159
165
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import SettingsStore from '@subwallet/extension-base/stores/Settings';
|
|
5
|
-
import {
|
|
5
|
+
import { DEFAULT_SETTING } from "./constants.js";
|
|
6
6
|
export default class SettingService {
|
|
7
7
|
settingsStore = new SettingsStore();
|
|
8
8
|
getSubject() {
|
|
@@ -11,15 +11,7 @@ export default class SettingService {
|
|
|
11
11
|
getSettings(update) {
|
|
12
12
|
this.settingsStore.get('Settings', value => {
|
|
13
13
|
if (!value) {
|
|
14
|
-
update(
|
|
15
|
-
// language: 'en',
|
|
16
|
-
browserConfirmationType: DEFAULT_NOTIFICATION_TYPE,
|
|
17
|
-
// isShowZeroBalance: true,
|
|
18
|
-
isShowBalance: false,
|
|
19
|
-
accountAllLogo: '',
|
|
20
|
-
theme: DEFAULT_THEME,
|
|
21
|
-
camera: false
|
|
22
|
-
});
|
|
14
|
+
update(DEFAULT_SETTING);
|
|
23
15
|
} else {
|
|
24
16
|
update(value);
|
|
25
17
|
}
|
|
@@ -28,4 +20,7 @@ export default class SettingService {
|
|
|
28
20
|
setSettings(data, callback) {
|
|
29
21
|
this.settingsStore.set('Settings', data, callback);
|
|
30
22
|
}
|
|
23
|
+
resetWallet() {
|
|
24
|
+
this.settingsStore.set('Settings', DEFAULT_SETTING);
|
|
25
|
+
}
|
|
31
26
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import { BrowserConfirmationType, ThemeNames } from '@subwallet/extension-base/background/KoniTypes';
|
|
1
|
+
import { BrowserConfirmationType, ThemeNames, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
2
|
export declare const DEFAULT_THEME: ThemeNames;
|
|
3
3
|
export declare const DEFAULT_NOTIFICATION_TYPE: BrowserConfirmationType;
|
|
4
|
+
export declare const DEFAULT_AUTO_LOCK_TIME = 15;
|
|
5
|
+
export declare const DEFAULT_CHAIN_PATROL_ENABLE = false;
|
|
6
|
+
export declare const DEFAULT_SETTING: UiSettings;
|
|
@@ -3,4 +3,17 @@
|
|
|
3
3
|
|
|
4
4
|
import { ThemeNames } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
export const DEFAULT_THEME = ThemeNames.DARK;
|
|
6
|
-
export const DEFAULT_NOTIFICATION_TYPE = 'popup';
|
|
6
|
+
export const DEFAULT_NOTIFICATION_TYPE = 'popup';
|
|
7
|
+
export const DEFAULT_AUTO_LOCK_TIME = 15;
|
|
8
|
+
export const DEFAULT_CHAIN_PATROL_ENABLE = false;
|
|
9
|
+
export const DEFAULT_SETTING = {
|
|
10
|
+
// language: 'en',
|
|
11
|
+
browserConfirmationType: DEFAULT_NOTIFICATION_TYPE,
|
|
12
|
+
// isShowZeroBalance: true,
|
|
13
|
+
isShowBalance: false,
|
|
14
|
+
accountAllLogo: '',
|
|
15
|
+
theme: DEFAULT_THEME,
|
|
16
|
+
camera: false,
|
|
17
|
+
timeAutoLock: DEFAULT_AUTO_LOCK_TIME,
|
|
18
|
+
enableChainPatrol: DEFAULT_CHAIN_PATROL_ENABLE
|
|
19
|
+
};
|
|
@@ -63,4 +63,5 @@ export default class DatabaseService {
|
|
|
63
63
|
getStakingMetadataByChain(chain: string, type?: StakingType): Promise<ChainStakingMetadata | undefined>;
|
|
64
64
|
updateNominatorMetadata(item: NominatorMetadata): Promise<unknown>;
|
|
65
65
|
getNominatorMetadata(): Promise<NominatorMetadata[]>;
|
|
66
|
+
resetWallet(resetAll: boolean): Promise<void>;
|
|
66
67
|
}
|
|
@@ -38,6 +38,7 @@ export default class DatabaseService {
|
|
|
38
38
|
const rs = await this.stores.price.table.get('usd');
|
|
39
39
|
return rs;
|
|
40
40
|
} catch (e) {
|
|
41
|
+
this.logger.error(e);
|
|
41
42
|
return undefined;
|
|
42
43
|
}
|
|
43
44
|
}
|
|
@@ -48,8 +49,6 @@ export default class DatabaseService {
|
|
|
48
49
|
}
|
|
49
50
|
async updateBalanceStore(address, item) {
|
|
50
51
|
if (item.state === APIItemState.READY) {
|
|
51
|
-
// this.logger.log(`Updating balance for [${item.tokenSlug}]`);
|
|
52
|
-
|
|
53
52
|
return this.stores.balance.upsert({
|
|
54
53
|
address,
|
|
55
54
|
...item
|
|
@@ -57,23 +56,18 @@ export default class DatabaseService {
|
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
async removeFromBalanceStore(assets) {
|
|
60
|
-
this.logger.log('Bulk removing AssetStore');
|
|
61
59
|
return this.stores.balance.removeBySlugs(assets);
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
// Crowdloan
|
|
65
63
|
async updateCrowdloanStore(chain, address, item) {
|
|
66
64
|
if (item.state === APIItemState.READY && item.contribute !== '0') {
|
|
67
|
-
// this.logger.log(`Updating crowdloan for [${chain}]`);
|
|
68
|
-
|
|
69
65
|
return this.stores.crowdloan.upsert({
|
|
70
66
|
chain,
|
|
71
67
|
address,
|
|
72
68
|
...item
|
|
73
69
|
});
|
|
74
70
|
} else {
|
|
75
|
-
// this.logger.debug(`Removing crowdloan for [${chain}]`);
|
|
76
|
-
|
|
77
71
|
return this.stores.crowdloan.deleteByChainAndAddress(chain, address);
|
|
78
72
|
}
|
|
79
73
|
}
|
|
@@ -81,22 +75,16 @@ export default class DatabaseService {
|
|
|
81
75
|
// Staking
|
|
82
76
|
async updateStaking(chain, address, item) {
|
|
83
77
|
if (item.state === APIItemState.READY) {
|
|
84
|
-
// this.logger.log(`Updating staking for [${chain}]`);
|
|
85
|
-
|
|
86
78
|
return this.stores.staking.upsert(item);
|
|
87
79
|
}
|
|
88
80
|
}
|
|
89
81
|
async getStakings(addresses, chains) {
|
|
90
|
-
// this.logger.log('Get Stakings: ', stakings);
|
|
91
|
-
|
|
92
82
|
return this.stores.staking.getStakings(addresses, chains);
|
|
93
83
|
}
|
|
94
84
|
async getStakingsByChains(chains) {
|
|
95
85
|
return this.stores.staking.getStakingsByChains(chains);
|
|
96
86
|
}
|
|
97
87
|
async getPooledStakings(addresses, chainHashes) {
|
|
98
|
-
// this.logger.log('Get Pooled Stakings: ', stakings);
|
|
99
|
-
|
|
100
88
|
return this.stores.staking.getPooledStakings(addresses, chainHashes);
|
|
101
89
|
}
|
|
102
90
|
subscribeStaking(addresses, chainList, callback) {
|
|
@@ -122,12 +110,10 @@ export default class DatabaseService {
|
|
|
122
110
|
return this.stores.transaction.queryHistory(query);
|
|
123
111
|
}
|
|
124
112
|
async upsertHistory(histories) {
|
|
125
|
-
// this.logger.log('Updating transaction histories');
|
|
126
113
|
const cleanedHistory = histories.filter(x => x && x.address && x.chain && x.extrinsicHash);
|
|
127
114
|
return this.stores.transaction.bulkUpsert(cleanedHistory);
|
|
128
115
|
}
|
|
129
116
|
async updateHistoryByNewExtrinsicHash(extrinsicHash, updateData) {
|
|
130
|
-
// this.logger.log('Updating transaction histories');
|
|
131
117
|
const canUpdate = updateData && extrinsicHash;
|
|
132
118
|
if (!canUpdate) {
|
|
133
119
|
return;
|
|
@@ -139,8 +125,6 @@ export default class DatabaseService {
|
|
|
139
125
|
|
|
140
126
|
// NFT Collection
|
|
141
127
|
async addNftCollection(collection) {
|
|
142
|
-
// this.logger.log(`Updating NFT collection for [${collection.chain}]`);
|
|
143
|
-
|
|
144
128
|
return this.stores.nftCollection.upsert(collection);
|
|
145
129
|
}
|
|
146
130
|
async deleteNftCollection(chain, collectionId) {
|
|
@@ -163,18 +147,12 @@ export default class DatabaseService {
|
|
|
163
147
|
if (ownNothing) {
|
|
164
148
|
return this.stores.nft.deleteNftsByChainAndOwner(chain, reformatAddress(owner, 42));
|
|
165
149
|
}
|
|
166
|
-
|
|
167
|
-
result > 0 && console.debug(`Cleaned up ${result} NFTs on chain ${chain} for owner ${reformatAddress(owner, 42)}`, collectionIds, nftIds);
|
|
168
|
-
return result;
|
|
150
|
+
return this.stores.nft.cleanUpNfts(chain, reformatAddress(owner, 42), collectionIds, nftIds);
|
|
169
151
|
}
|
|
170
152
|
async getNft(addresses, chainHashes) {
|
|
171
|
-
// this.logger.log('Get NFTs: ', nfts);
|
|
172
|
-
|
|
173
153
|
return this.stores.nft.getNft(addresses, chainHashes);
|
|
174
154
|
}
|
|
175
155
|
async addNft(address, nft) {
|
|
176
|
-
// this.logger.log(`Updating NFT for [${nft.chain}]`);
|
|
177
|
-
|
|
178
156
|
return this.stores.nft.upsert({
|
|
179
157
|
...nft,
|
|
180
158
|
address
|
|
@@ -184,54 +162,36 @@ export default class DatabaseService {
|
|
|
184
162
|
return this.stores.nft.deleteNftItem(chain, addresses, nftItem);
|
|
185
163
|
}
|
|
186
164
|
removeNfts(chain, address, collectionId, nftIds) {
|
|
187
|
-
// this.logger.log(`Remove NFTs [${nftIds.join(', ')}]`);
|
|
188
|
-
|
|
189
165
|
return this.stores.nft.removeNfts(chain, address, collectionId, nftIds);
|
|
190
166
|
}
|
|
191
167
|
|
|
192
168
|
// Chain
|
|
193
169
|
async updateChainStore(item) {
|
|
194
|
-
// this.logger.log(`Updating storageInfo for chain [${item.slug}]`);
|
|
195
|
-
|
|
196
170
|
return this.stores.chain.upsert(item);
|
|
197
171
|
}
|
|
198
172
|
async bulkUpdateChainStore(data) {
|
|
199
|
-
// this.logger.log('Bulk updating ChainStore');
|
|
200
|
-
|
|
201
173
|
return this.stores.chain.bulkUpsert(data);
|
|
202
174
|
}
|
|
203
175
|
async removeFromChainStore(chains) {
|
|
204
|
-
// this.logger.log('Bulk removing ChainStore');
|
|
205
|
-
|
|
206
176
|
return this.stores.chain.removeChains(chains);
|
|
207
177
|
}
|
|
208
178
|
async getAllChainStore() {
|
|
209
|
-
// this.logger.log('Get all chains: ', allChains);
|
|
210
|
-
|
|
211
179
|
return this.stores.chain.getAll();
|
|
212
180
|
}
|
|
213
181
|
|
|
214
182
|
// Asset
|
|
215
183
|
async updateAssetStore(item) {
|
|
216
|
-
// this.logger.log(`Updating storageInfo for chainAsset [${item.originChain}]`);
|
|
217
|
-
|
|
218
184
|
return this.stores.asset.upsert(item);
|
|
219
185
|
}
|
|
220
186
|
async getAllAssetStore() {
|
|
221
|
-
// this.logger.log('Get all stored assets: ', allAssets);
|
|
222
|
-
|
|
223
187
|
return this.stores.asset.getAll();
|
|
224
188
|
}
|
|
225
189
|
async removeFromAssetStore(items) {
|
|
226
|
-
// this.logger.log('Bulk removing AssetStore');
|
|
227
|
-
|
|
228
190
|
return this.stores.asset.removeAssets(items);
|
|
229
191
|
}
|
|
230
192
|
|
|
231
193
|
// Staking
|
|
232
194
|
async updateChainStakingMetadata(item) {
|
|
233
|
-
// this.logger.log('Update ChainStakingMetadata: ', item.chain);
|
|
234
|
-
|
|
235
195
|
return this.stores.chainStakingMetadata.upsert(item);
|
|
236
196
|
}
|
|
237
197
|
async getChainStakingMetadata() {
|
|
@@ -241,11 +201,23 @@ export default class DatabaseService {
|
|
|
241
201
|
return this.stores.chainStakingMetadata.getByChainAndType(chain, type);
|
|
242
202
|
}
|
|
243
203
|
async updateNominatorMetadata(item) {
|
|
244
|
-
// this.logger.log('Update NominatorMetadata: ', item.address, item.chain);
|
|
245
|
-
|
|
246
204
|
return this.stores.nominatorMetadata.upsert(item);
|
|
247
205
|
}
|
|
248
206
|
async getNominatorMetadata() {
|
|
249
207
|
return this.stores.nominatorMetadata.getAll();
|
|
250
208
|
}
|
|
209
|
+
async resetWallet(resetAll) {
|
|
210
|
+
return new Promise((resolve, reject) => {
|
|
211
|
+
const stores = [this.stores.balance, this.stores.nft, this.stores.nftCollection, this.stores.crowdloan, this.stores.staking, this.stores.transaction, this.stores.nominatorMetadata];
|
|
212
|
+
if (resetAll) {
|
|
213
|
+
stores.push(this.stores.chain, this.stores.asset);
|
|
214
|
+
}
|
|
215
|
+
const promises = stores.map(store => store.clear());
|
|
216
|
+
Promise.all(promises).then(() => {
|
|
217
|
+
resolve();
|
|
218
|
+
}).catch(e => {
|
|
219
|
+
reject(e);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
}
|
|
251
223
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import Dexie from 'dexie';
|
|
5
5
|
const DEFAULT_DATABASE = 'SubWalletDB_v2';
|
|
6
6
|
export default class KoniDatabase extends Dexie {
|
|
7
|
-
constructor(name = DEFAULT_DATABASE, schemaVersion =
|
|
7
|
+
constructor(name = DEFAULT_DATABASE, schemaVersion = 11) {
|
|
8
8
|
super(name);
|
|
9
9
|
this.schemaVersion = schemaVersion;
|
|
10
10
|
this.conditionalVersion(1, {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TRANSACTION_TIMEOUT: number;
|