@subwallet/extension-base 1.1.25-0 → 1.1.26-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 +2 -2
- package/background/handlers/State.js +3 -2
- package/cjs/background/handlers/State.js +3 -2
- package/cjs/constants/staking.js +4 -2
- package/cjs/koni/api/dotsama/transfer.js +2 -2
- package/cjs/koni/api/nft/config.js +2 -1
- package/cjs/koni/api/staking/bonding/relayChain.js +48 -25
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/background/handlers/Extension.js +11 -8
- package/cjs/koni/background/handlers/Mobile.js +81 -5
- package/cjs/koni/background/handlers/State.js +45 -117
- package/cjs/koni/background/subscription.js +2 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/BalanceMapImpl.js +114 -0
- package/cjs/services/campaign-service/index.js +2 -0
- package/cjs/services/chain-service/constants.js +24 -3
- package/cjs/services/event-service/index.js +7 -7
- package/cjs/services/event-service/types.js +1 -1
- package/cjs/services/history-service/index.js +1 -0
- package/cjs/services/keyring-service/index.js +10 -6
- package/cjs/services/migration-service/scripts/index.js +3 -1
- package/cjs/services/migration-service/scripts/tokens/MigratePolygonUSDCProvider.js +16 -0
- package/cjs/services/migration-service/scripts/tokens/MigrateToken.js +33 -0
- package/cjs/services/setting-service/SettingService.js +2 -1
- package/cjs/services/setting-service/i18n/i18n.js +2 -1
- package/cjs/services/storage-service/DatabaseService.js +8 -19
- package/cjs/services/storage-service/db-stores/Balance.js +4 -13
- package/cjs/services/wallet-connect-service/index.js +6 -3
- package/cjs/storage/index.js +59 -0
- package/cjs/utils/array.js +27 -1
- package/constants/staking.d.ts +1 -0
- package/constants/staking.js +2 -1
- package/koni/api/dotsama/transfer.js +2 -2
- package/koni/api/nft/config.js +2 -1
- package/koni/api/staking/bonding/relayChain.js +40 -17
- package/koni/api/xcm/xTokens.js +1 -1
- package/koni/background/handlers/Extension.js +11 -8
- package/koni/background/handlers/Mobile.d.ts +6 -0
- package/koni/background/handlers/Mobile.js +75 -3
- package/koni/background/handlers/State.d.ts +7 -8
- package/koni/background/handlers/State.js +34 -104
- package/koni/background/subscription.js +2 -2
- package/package.json +40 -20
- package/packageInfo.js +1 -1
- package/services/balance-service/BalanceMapImpl.d.ts +17 -0
- package/services/balance-service/BalanceMapImpl.js +104 -0
- package/services/campaign-service/index.d.ts +1 -0
- package/services/campaign-service/index.js +2 -0
- package/services/chain-service/constants.d.ts +1 -0
- package/services/chain-service/constants.js +22 -2
- package/services/event-service/index.d.ts +1 -4
- package/services/event-service/index.js +8 -7
- package/services/event-service/types.js +1 -1
- package/services/history-service/index.js +1 -0
- package/services/keyring-service/index.js +10 -6
- package/services/migration-service/scripts/index.js +3 -1
- package/services/migration-service/scripts/tokens/MigratePolygonUSDCProvider.d.ts +5 -0
- package/services/migration-service/scripts/tokens/MigratePolygonUSDCProvider.js +8 -0
- package/services/migration-service/scripts/tokens/MigrateToken.d.ts +9 -0
- package/services/migration-service/scripts/tokens/MigrateToken.js +26 -0
- package/services/setting-service/SettingService.js +2 -1
- package/services/setting-service/i18n/i18n.js +2 -1
- package/services/storage-service/DatabaseService.d.ts +3 -1
- package/services/storage-service/DatabaseService.js +7 -19
- package/services/storage-service/db-stores/Balance.d.ts +3 -2
- package/services/storage-service/db-stores/Balance.js +4 -13
- package/services/wallet-connect-service/index.js +5 -3
- package/storage/index.d.ts +14 -0
- package/storage/index.js +52 -0
- package/utils/array.d.ts +1 -0
- package/utils/array.js +26 -1
|
@@ -98,6 +98,22 @@ export const _STAKING_ERA_LENGTH_MAP = {
|
|
|
98
98
|
vara_network: 12,
|
|
99
99
|
goldberg_testnet: 24
|
|
100
100
|
};
|
|
101
|
+
export const _EXPECTED_BLOCK_TIME = {
|
|
102
|
+
// in seconds
|
|
103
|
+
alephTest: 1,
|
|
104
|
+
aleph: 1,
|
|
105
|
+
polkadot: 6,
|
|
106
|
+
kusama: 6,
|
|
107
|
+
polkadex: 12,
|
|
108
|
+
ternoa: 6,
|
|
109
|
+
ternoa_alphanet: 6,
|
|
110
|
+
westend: 6,
|
|
111
|
+
kate: 20,
|
|
112
|
+
edgeware: 6,
|
|
113
|
+
creditcoin: 12,
|
|
114
|
+
vara_network: 3,
|
|
115
|
+
goldberg_testnet: 20
|
|
116
|
+
};
|
|
101
117
|
export const _PARACHAIN_INFLATION_DISTRIBUTION = {
|
|
102
118
|
moonbeam: {
|
|
103
119
|
// https://docs.moonbeam.network/learn/features/staking/#annual-inflation
|
|
@@ -180,6 +196,10 @@ export const _KNOWN_CHAIN_INFLATION_PARAMS = {
|
|
|
180
196
|
polkadot: {
|
|
181
197
|
..._SUBSTRATE_DEFAULT_INFLATION_PARAMS,
|
|
182
198
|
stakeTarget: 0.75
|
|
199
|
+
},
|
|
200
|
+
vara_network: {
|
|
201
|
+
..._SUBSTRATE_DEFAULT_INFLATION_PARAMS,
|
|
202
|
+
stakeTarget: 0.8
|
|
183
203
|
}
|
|
184
204
|
};
|
|
185
205
|
|
|
@@ -188,7 +208,7 @@ export const _KNOWN_CHAIN_INFLATION_PARAMS = {
|
|
|
188
208
|
export const _TRANSFER_NOT_SUPPORTED_CHAINS = ['subspace_gemini_3a', 'kulupu', 'joystream', 'equilibrium_parachain', 'genshiro_testnet', 'genshiro'];
|
|
189
209
|
export const _TRANSFER_CHAIN_GROUP = {
|
|
190
210
|
acala: ['karura', 'acala', 'acala_testnet'],
|
|
191
|
-
kintsugi: ['kintsugi', 'kintsugi_test', 'interlay', '
|
|
211
|
+
kintsugi: ['kintsugi', 'kintsugi_test', 'interlay', 'mangatax_para'],
|
|
192
212
|
genshiro: ['genshiro_testnet', 'genshiro', 'equilibrium_parachain'],
|
|
193
213
|
crab: ['crab', 'pangolin'],
|
|
194
214
|
bitcountry: ['pioneer', 'bitcountry', 'bifrost', 'bifrost_dot'],
|
|
@@ -196,7 +216,7 @@ export const _TRANSFER_CHAIN_GROUP = {
|
|
|
196
216
|
riochain: ['riochain'],
|
|
197
217
|
sora_substrate: ['sora_substrate'],
|
|
198
218
|
avail: ['kate', 'goldberg_testnet'],
|
|
199
|
-
pendulum: ['pendulum', 'amplitude', 'amplitude_test'],
|
|
219
|
+
pendulum: ['pendulum', 'amplitude', 'amplitude_test', 'hydradx_main'],
|
|
200
220
|
centrifuge: ['centrifuge']
|
|
201
221
|
};
|
|
202
222
|
export const _BALANCE_PARSING_CHAIN_GROUP = {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { EventItem, EventRegistry, EventType } from '@subwallet/extension-base/services/event-service/types';
|
|
2
2
|
import EventEmitter from 'eventemitter3';
|
|
3
3
|
export declare class EventService extends EventEmitter<EventRegistry> {
|
|
4
|
-
private lazyTime;
|
|
5
4
|
private timeoutId;
|
|
6
5
|
private pendingEvents;
|
|
7
6
|
private lazyEmitter;
|
|
@@ -15,9 +14,7 @@ export declare class EventService extends EventEmitter<EventRegistry> {
|
|
|
15
14
|
readonly waitCampaignReady: Promise<boolean>;
|
|
16
15
|
readonly waitBuyTokenReady: Promise<boolean>;
|
|
17
16
|
readonly waitBuyServiceReady: Promise<boolean>;
|
|
18
|
-
constructor(
|
|
19
|
-
lazyTime: number;
|
|
20
|
-
});
|
|
17
|
+
constructor();
|
|
21
18
|
private generateWaitPromise;
|
|
22
19
|
private setLazyTimeout;
|
|
23
20
|
private emitLazy;
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
// Stateless service handle runtime event on background
|
|
5
5
|
|
|
6
6
|
import EventEmitter from 'eventemitter3';
|
|
7
|
+
const DEFAULT_LAZY_TIME = 300;
|
|
8
|
+
const LONG_LAZY_TIME = 900;
|
|
9
|
+
const LONG_LAZY_EVENTS = ['account.add', 'chain.add'];
|
|
7
10
|
export class EventService extends EventEmitter {
|
|
8
11
|
pendingEvents = [];
|
|
9
12
|
lazyEmitter = new EventEmitter();
|
|
10
|
-
constructor(
|
|
11
|
-
lazyTime: 300
|
|
12
|
-
}) {
|
|
13
|
+
constructor() {
|
|
13
14
|
super();
|
|
14
|
-
this.lazyTime = options.lazyTime;
|
|
15
15
|
this.timeoutId = null;
|
|
16
16
|
this.waitCryptoReady = this.generateWaitPromise('crypto.ready');
|
|
17
17
|
this.waitDatabaseReady = this.generateWaitPromise('database.ready');
|
|
@@ -31,13 +31,14 @@ export class EventService extends EventEmitter {
|
|
|
31
31
|
});
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
setLazyTimeout() {
|
|
34
|
+
setLazyTimeout(eventType) {
|
|
35
35
|
if (this.timeoutId) {
|
|
36
36
|
clearTimeout(this.timeoutId);
|
|
37
37
|
}
|
|
38
|
+
const timeout = LONG_LAZY_EVENTS.includes(eventType) ? LONG_LAZY_TIME : DEFAULT_LAZY_TIME;
|
|
38
39
|
this.timeoutId = setTimeout(() => {
|
|
39
40
|
this.emitLazy();
|
|
40
|
-
},
|
|
41
|
+
}, timeout);
|
|
41
42
|
}
|
|
42
43
|
emitLazy() {
|
|
43
44
|
try {
|
|
@@ -63,7 +64,7 @@ export class EventService extends EventEmitter {
|
|
|
63
64
|
type: eventType,
|
|
64
65
|
data: args
|
|
65
66
|
});
|
|
66
|
-
this.setLazyTimeout();
|
|
67
|
+
this.setLazyTimeout(eventType);
|
|
67
68
|
return super.emit(eventType, ...args);
|
|
68
69
|
}
|
|
69
70
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
export const COMMON_RELOAD_EVENTS = ['account.updateCurrent', '
|
|
4
|
+
export const COMMON_RELOAD_EVENTS = ['account.updateCurrent', 'account.add', 'account.remove', 'asset.updateState', 'chain.updateState', 'chain.add', 'mantaPay.initSync',
|
|
5
5
|
// TODO: re-check this
|
|
6
6
|
'mantaPay.enable'];
|
|
@@ -240,6 +240,7 @@ export class HistoryService {
|
|
|
240
240
|
startPromiseHandler = createPromiseHandler();
|
|
241
241
|
async init() {
|
|
242
242
|
this.status = ServiceStatus.INITIALIZING;
|
|
243
|
+
await this.eventService.waitCryptoReady;
|
|
243
244
|
await this.loadData();
|
|
244
245
|
Promise.all([this.eventService.waitKeyringReady, this.eventService.waitChainReady]).then(() => {
|
|
245
246
|
this.getHistories().catch(console.log);
|
|
@@ -22,10 +22,12 @@ export class KeyringService {
|
|
|
22
22
|
});
|
|
23
23
|
constructor(eventService) {
|
|
24
24
|
this.eventService = eventService;
|
|
25
|
-
this.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
this.eventService.waitCryptoReady.then(() => {
|
|
26
|
+
this.currentAccountStore.get('CurrentAccountInfo', rs => {
|
|
27
|
+
rs && this.currentAccountSubject.next(rs);
|
|
28
|
+
});
|
|
29
|
+
this.subscribeAccounts().catch(console.error);
|
|
30
|
+
}).catch(console.error);
|
|
29
31
|
}
|
|
30
32
|
async subscribeAccounts() {
|
|
31
33
|
// Wait until account ready
|
|
@@ -65,8 +67,10 @@ export class KeyringService {
|
|
|
65
67
|
updateKeyringState(isReady = true) {
|
|
66
68
|
var _keyring$keyring, _keyring$keyring2;
|
|
67
69
|
if (!this.keyringState.isReady && isReady) {
|
|
68
|
-
this.eventService.
|
|
69
|
-
|
|
70
|
+
this.eventService.waitCryptoReady.then(() => {
|
|
71
|
+
this.eventService.emit('keyring.ready', true);
|
|
72
|
+
this.eventService.emit('account.ready', true);
|
|
73
|
+
}).catch(console.error);
|
|
70
74
|
}
|
|
71
75
|
this.keyringStateSubject.next({
|
|
72
76
|
hasMasterPassword: !!((_keyring$keyring = keyring.keyring) !== null && _keyring$keyring !== void 0 && _keyring$keyring.hasMasterPassword),
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import MigrateEthProvider from "./providers/MigrateEthProvider.js";
|
|
5
5
|
import MigratePioneerProvider from "./providers/MigratePioneerProvider.js";
|
|
6
6
|
import MigrateProvidersV1M1P24 from "./providers/MigrateProvidersV1M1P24.js";
|
|
7
|
+
import MigratePolygonUSDCProvider from "./tokens/MigratePolygonUSDCProvider.js";
|
|
7
8
|
import AutoEnableChainsTokens from "./AutoEnableChainsTokens.js";
|
|
8
9
|
import DeleteChain from "./DeleteChain.js";
|
|
9
10
|
import EnableVaraChain from "./EnableVaraChain.js";
|
|
@@ -34,6 +35,7 @@ export default {
|
|
|
34
35
|
'1.1.13-01': MigrateTokenDecimals,
|
|
35
36
|
'1.1.17-01': MigratePioneerProvider,
|
|
36
37
|
'1.1.17-03': EnableVaraChain,
|
|
37
|
-
'1.1.24-01': MigrateProvidersV1M1P24
|
|
38
|
+
'1.1.24-01': MigrateProvidersV1M1P24,
|
|
39
|
+
'1.1.26-01': MigratePolygonUSDCProvider
|
|
38
40
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
39
41
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import MigrateToken from "./MigrateToken.js";
|
|
5
|
+
export default class MigratePolygonUSDCProvider extends MigrateToken {
|
|
6
|
+
oldToken = 'polygon-ERC20-USDC-0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174';
|
|
7
|
+
newTokens = ['polygon-ERC20-USDC.e-0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', 'polygon-ERC20-USDC-0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359'];
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
2
|
+
/**
|
|
3
|
+
* @description Enable `newTokens` if `oldToken` active
|
|
4
|
+
* */
|
|
5
|
+
export default abstract class MigrateToken extends BaseMigrationJob {
|
|
6
|
+
abstract oldToken: string;
|
|
7
|
+
abstract newTokens: string[];
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @description Enable `newTokens` if `oldToken` active
|
|
8
|
+
* */
|
|
9
|
+
export default class MigrateToken extends BaseMigrationJob {
|
|
10
|
+
async run() {
|
|
11
|
+
const state = this.state;
|
|
12
|
+
const assetSettings = await state.chainService.getAssetSettings();
|
|
13
|
+
const oldAssetSetting = assetSettings[this.oldToken];
|
|
14
|
+
if (oldAssetSetting) {
|
|
15
|
+
if (oldAssetSetting.visible) {
|
|
16
|
+
for (const newToken of this.newTokens) {
|
|
17
|
+
assetSettings[newToken] = {
|
|
18
|
+
visible: true
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
delete assetSettings[this.oldToken];
|
|
23
|
+
state.chainService.setAssetSettings(assetSettings);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { LANGUAGE } from '@subwallet/extension-base/constants';
|
|
5
|
+
import { SWStorage } from '@subwallet/extension-base/storage';
|
|
5
6
|
import PassPhishingStore from '@subwallet/extension-base/stores/PassPhishingStore';
|
|
6
7
|
import SettingsStore from '@subwallet/extension-base/stores/Settings';
|
|
7
8
|
import i18n from "./i18n/i18n.js";
|
|
@@ -10,7 +11,7 @@ export default class SettingService {
|
|
|
10
11
|
settingsStore = new SettingsStore();
|
|
11
12
|
passPhishingStore = new PassPhishingStore();
|
|
12
13
|
constructor() {
|
|
13
|
-
let old =
|
|
14
|
+
let old = SWStorage.instance.getItem(LANGUAGE) || 'en';
|
|
14
15
|
const updateLanguage = ({
|
|
15
16
|
language
|
|
16
17
|
}) => {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { LANGUAGE } from '@subwallet/extension-base/constants';
|
|
5
|
+
import { SWStorage } from '@subwallet/extension-base/storage';
|
|
5
6
|
import i18next from 'i18next';
|
|
6
7
|
import Backend from "./Backend.js";
|
|
7
8
|
i18next.use(Backend).init({
|
|
@@ -12,7 +13,7 @@ i18next.use(Backend).init({
|
|
|
12
13
|
escapeValue: false
|
|
13
14
|
},
|
|
14
15
|
keySeparator: false,
|
|
15
|
-
lng:
|
|
16
|
+
lng: SWStorage.instance.getItem(LANGUAGE) || 'en',
|
|
16
17
|
load: 'languageOnly',
|
|
17
18
|
nsSeparator: false,
|
|
18
19
|
returnEmptyString: false,
|
|
@@ -10,6 +10,8 @@ import NominatorMetadataStore from '@subwallet/extension-base/services/storage-s
|
|
|
10
10
|
import { HistoryQuery } from '@subwallet/extension-base/services/storage-service/db-stores/Transaction';
|
|
11
11
|
import { BalanceItem } from '@subwallet/extension-base/types';
|
|
12
12
|
import { Subscription } from 'dexie';
|
|
13
|
+
import { DexieExportJsonStructure } from 'dexie-export-import';
|
|
14
|
+
export declare const DEXIE_BACKUP_TABLES: string[];
|
|
13
15
|
export default class DatabaseService {
|
|
14
16
|
private eventService;
|
|
15
17
|
private _db;
|
|
@@ -87,5 +89,5 @@ export default class DatabaseService {
|
|
|
87
89
|
upsertCampaign(campaign: ICampaign): import("dexie").PromiseExtended<unknown>;
|
|
88
90
|
exportDB(): Promise<string>;
|
|
89
91
|
importDB(data: string): Promise<boolean>;
|
|
90
|
-
|
|
92
|
+
getExportJson(): Promise<DexieExportJsonStructure>;
|
|
91
93
|
}
|
|
@@ -9,9 +9,9 @@ import ChainStakingMetadataStore from '@subwallet/extension-base/services/storag
|
|
|
9
9
|
import MantaPayStore from '@subwallet/extension-base/services/storage-service/db-stores/MantaPay';
|
|
10
10
|
import NominatorMetadataStore from '@subwallet/extension-base/services/storage-service/db-stores/NominatorMetadata';
|
|
11
11
|
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
12
|
-
import { exportDB
|
|
12
|
+
import { exportDB } from 'dexie-export-import';
|
|
13
13
|
import { logger as createLogger } from '@polkadot/util';
|
|
14
|
-
const
|
|
14
|
+
export const DEXIE_BACKUP_TABLES = ['chain', 'asset', 'migrations', 'transactions', 'campaign'];
|
|
15
15
|
export default class DatabaseService {
|
|
16
16
|
// TODO: might remove this
|
|
17
17
|
|
|
@@ -289,10 +289,7 @@ export default class DatabaseService {
|
|
|
289
289
|
async exportDB() {
|
|
290
290
|
const blob = await exportDB(this._db, {
|
|
291
291
|
filter: (table, value, key) => {
|
|
292
|
-
|
|
293
|
-
return false;
|
|
294
|
-
}
|
|
295
|
-
return true;
|
|
292
|
+
return DEXIE_BACKUP_TABLES.indexOf(table) >= 0;
|
|
296
293
|
}
|
|
297
294
|
});
|
|
298
295
|
return await blob.text();
|
|
@@ -303,9 +300,8 @@ export default class DatabaseService {
|
|
|
303
300
|
type: 'application/json'
|
|
304
301
|
});
|
|
305
302
|
await this._db.import(blob, {
|
|
306
|
-
|
|
307
|
-
acceptMissingTables: true
|
|
308
|
-
acceptVersionDiff: true
|
|
303
|
+
clearTablesBeforeImport: true,
|
|
304
|
+
acceptMissingTables: true
|
|
309
305
|
});
|
|
310
306
|
return true;
|
|
311
307
|
} catch (e) {
|
|
@@ -313,15 +309,7 @@ export default class DatabaseService {
|
|
|
313
309
|
return false;
|
|
314
310
|
}
|
|
315
311
|
}
|
|
316
|
-
async
|
|
317
|
-
|
|
318
|
-
const blob = new Blob([data], {
|
|
319
|
-
type: 'application/json'
|
|
320
|
-
});
|
|
321
|
-
return await peakImportFile(blob);
|
|
322
|
-
} catch (e) {
|
|
323
|
-
this.logger.error(e);
|
|
324
|
-
return null;
|
|
325
|
-
}
|
|
312
|
+
async getExportJson() {
|
|
313
|
+
return JSON.parse(await this.exportDB());
|
|
326
314
|
}
|
|
327
315
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BalanceItem } from '@subwallet/extension-base/types';
|
|
2
2
|
import { IBalance } from '../databases';
|
|
3
3
|
import BaseStoreWithAddress from '../db-stores/BaseStoreWithAddress';
|
|
4
4
|
export default class BalanceStore extends BaseStoreWithAddress<IBalance> {
|
|
5
|
-
getBalanceMapByAddresses(addresses: string): Promise<
|
|
5
|
+
getBalanceMapByAddresses(addresses: string): Promise<BalanceItem[]>;
|
|
6
6
|
removeBySlugs(tokenSlugs: string[]): Promise<number>;
|
|
7
|
+
removeByAddresses(addresses: string[]): Promise<number>;
|
|
7
8
|
}
|
|
@@ -4,21 +4,12 @@
|
|
|
4
4
|
import BaseStoreWithAddress from "./BaseStoreWithAddress.js";
|
|
5
5
|
export default class BalanceStore extends BaseStoreWithAddress {
|
|
6
6
|
async getBalanceMapByAddresses(addresses) {
|
|
7
|
-
|
|
8
|
-
const balanceMap = {};
|
|
9
|
-
data.forEach(storedBalance => {
|
|
10
|
-
const address = storedBalance.address;
|
|
11
|
-
const slug = storedBalance.tokenSlug;
|
|
12
|
-
if (!balanceMap[address]) {
|
|
13
|
-
balanceMap[address] = {};
|
|
14
|
-
}
|
|
15
|
-
balanceMap[address][slug] = {
|
|
16
|
-
...storedBalance
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
return balanceMap;
|
|
7
|
+
return this.table.where('address').anyOf(addresses).toArray();
|
|
20
8
|
}
|
|
21
9
|
async removeBySlugs(tokenSlugs) {
|
|
22
10
|
return this.table.where('tokenSlug').anyOfIgnoreCase(tokenSlugs).delete();
|
|
23
11
|
}
|
|
12
|
+
async removeByAddresses(addresses) {
|
|
13
|
+
return this.table.where('address').anyOfIgnoreCase(addresses).delete();
|
|
14
|
+
}
|
|
24
15
|
}
|
|
@@ -5,6 +5,7 @@ import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateF
|
|
|
5
5
|
|
|
6
6
|
import { formatJsonRpcError } from '@json-rpc-tools/utils';
|
|
7
7
|
import Eip155RequestHandler from '@subwallet/extension-base/services/wallet-connect-service/handler/Eip155RequestHandler';
|
|
8
|
+
import { SWStorage } from '@subwallet/extension-base/storage';
|
|
8
9
|
import SignClient from '@walletconnect/sign-client';
|
|
9
10
|
import { getInternalError, getSdkError } from '@walletconnect/utils';
|
|
10
11
|
import { BehaviorSubject } from 'rxjs';
|
|
@@ -12,6 +13,7 @@ import PolkadotRequestHandler from "./handler/PolkadotRequestHandler.js";
|
|
|
12
13
|
import { ALL_WALLET_CONNECT_EVENT, DEFAULT_WALLET_CONNECT_OPTIONS, WALLET_CONNECT_SUPPORTED_METHODS } from "./constants.js";
|
|
13
14
|
import { convertConnectRequest, convertNotSupportRequest, isSupportWalletConnectChain } from "./helpers.js";
|
|
14
15
|
import { EIP155_SIGNING_METHODS, POLKADOT_SIGNING_METHODS } from "./types.js";
|
|
16
|
+
const storage = SWStorage.instance;
|
|
15
17
|
var _requestService = /*#__PURE__*/_classPrivateFieldLooseKey("requestService");
|
|
16
18
|
var _polkadotRequestHandler = /*#__PURE__*/_classPrivateFieldLooseKey("polkadotRequestHandler");
|
|
17
19
|
var _eip155RequestHandler = /*#__PURE__*/_classPrivateFieldLooseKey("eip155RequestHandler");
|
|
@@ -185,9 +187,9 @@ export default class WalletConnectService {
|
|
|
185
187
|
}
|
|
186
188
|
}
|
|
187
189
|
function _get_haveData() {
|
|
188
|
-
const sessionStorage =
|
|
189
|
-
const pairingStorage =
|
|
190
|
-
const subscriptionStorage =
|
|
190
|
+
const sessionStorage = storage.getItem('wc@2:client:0.3//session');
|
|
191
|
+
const pairingStorage = storage.getItem('wc@2:core:0.3//pairing');
|
|
192
|
+
const subscriptionStorage = storage.getItem('wc@2:core:0.3//subscription');
|
|
191
193
|
const sessions = sessionStorage ? JSON.parse(sessionStorage) : [];
|
|
192
194
|
const pairings = pairingStorage ? JSON.parse(pairingStorage) : [];
|
|
193
195
|
const subscriptions = subscriptionStorage ? JSON.parse(subscriptionStorage) : [];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class SWStorage {
|
|
2
|
+
private _storage;
|
|
3
|
+
constructor();
|
|
4
|
+
setItem(key: string, value: string): void;
|
|
5
|
+
getItem(key: string): string | null;
|
|
6
|
+
removeItem(key: string): void;
|
|
7
|
+
clear(): void;
|
|
8
|
+
key(index: number): string | null;
|
|
9
|
+
length(index: number): string | null;
|
|
10
|
+
keys(): string[];
|
|
11
|
+
copy(): Record<string, string>;
|
|
12
|
+
sync(): void;
|
|
13
|
+
static get instance(): SWStorage;
|
|
14
|
+
}
|
package/storage/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Copyright 2019-2022 @polkadot/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export class SWStorage {
|
|
5
|
+
_storage = {};
|
|
6
|
+
constructor() {
|
|
7
|
+
this.sync();
|
|
8
|
+
}
|
|
9
|
+
setItem(key, value) {
|
|
10
|
+
this._storage[key] = value;
|
|
11
|
+
localStorage.setItem(key, value);
|
|
12
|
+
}
|
|
13
|
+
getItem(key) {
|
|
14
|
+
return this._storage[key] || localStorage.getItem(key) || null;
|
|
15
|
+
}
|
|
16
|
+
removeItem(key) {
|
|
17
|
+
this._storage[key] && delete this._storage[key];
|
|
18
|
+
localStorage.removeItem(key);
|
|
19
|
+
}
|
|
20
|
+
clear() {
|
|
21
|
+
this._storage = {};
|
|
22
|
+
localStorage.clear();
|
|
23
|
+
}
|
|
24
|
+
key(index) {
|
|
25
|
+
return Object.keys(this._storage)[index] || null;
|
|
26
|
+
}
|
|
27
|
+
length(index) {
|
|
28
|
+
return Object.keys(this._storage)[index] || null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Additional methods
|
|
32
|
+
keys() {
|
|
33
|
+
return Object.keys(this._storage) || [];
|
|
34
|
+
}
|
|
35
|
+
copy() {
|
|
36
|
+
return JSON.parse(JSON.stringify(this._storage));
|
|
37
|
+
}
|
|
38
|
+
sync() {
|
|
39
|
+
this._storage = JSON.parse(JSON.stringify(localStorage));
|
|
40
|
+
}
|
|
41
|
+
static get instance() {
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
if (!window.SWStorage) {
|
|
44
|
+
console.log('SWStorage init');
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
window.SWStorage = new SWStorage();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
return window.SWStorage;
|
|
51
|
+
}
|
|
52
|
+
}
|
package/utils/array.d.ts
CHANGED
package/utils/array.js
CHANGED
|
@@ -7,4 +7,29 @@ export const uniqueStringArray = array => {
|
|
|
7
7
|
map[v] = v;
|
|
8
8
|
});
|
|
9
9
|
return Object.keys(map);
|
|
10
|
-
};
|
|
10
|
+
};
|
|
11
|
+
export function listMerge(keys, existed, newItems) {
|
|
12
|
+
const getKey = (ks, item) => {
|
|
13
|
+
if (typeof ks === 'string') {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
|
|
15
|
+
return item[ks].toString();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
|
|
19
|
+
return ks.map(k => item[k].toString()).join('_');
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Build existed map with keys
|
|
23
|
+
const existedMap = Object.fromEntries(existed.map(v => {
|
|
24
|
+
return [getKey(keys, v), v];
|
|
25
|
+
}));
|
|
26
|
+
newItems.forEach(item => {
|
|
27
|
+
const key = getKey(keys, item);
|
|
28
|
+
if (existedMap[key]) {
|
|
29
|
+
Object.assign(existedMap[key], item);
|
|
30
|
+
} else {
|
|
31
|
+
existed.push(item);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return existed;
|
|
35
|
+
}
|