@subwallet/extension-base 1.0.2-2 → 1.0.3-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 +56 -40
- package/background/KoniTypes.js +11 -9
- package/background/errors/TransactionError.js +25 -1
- package/background/types.d.ts +10 -5
- package/cjs/background/KoniTypes.js +11 -9
- package/cjs/background/errors/TransactionError.js +24 -0
- package/cjs/constants/index.js +8 -26
- package/cjs/koni/api/dotsama/balance.js +49 -224
- package/cjs/koni/api/dotsama/transfer.js +34 -39
- package/cjs/koni/api/nft/acala_nft/index.js +7 -7
- package/cjs/koni/api/nft/bit.country/index.js +7 -6
- package/cjs/koni/api/nft/evm_nft/index.js +8 -3
- package/cjs/koni/api/nft/index.js +3 -6
- package/cjs/koni/api/nft/karura_nft/index.js +7 -6
- package/cjs/koni/api/nft/rmrk_nft/index.js +11 -1
- package/cjs/koni/api/nft/statemine_nft/index.js +7 -6
- package/cjs/koni/api/nft/unique_nft/index.js +5 -1
- package/cjs/koni/api/nft/wasm_nft/index.js +170 -111
- package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
- package/cjs/koni/api/staking/bonding/amplitude.js +13 -9
- package/cjs/koni/api/staking/bonding/astar.js +15 -13
- package/cjs/koni/api/staking/bonding/index.js +22 -10
- package/cjs/koni/api/staking/bonding/paraChain.js +85 -2
- package/cjs/koni/api/staking/bonding/relayChain.js +122 -16
- package/cjs/koni/api/staking/bonding/utils.js +27 -8
- package/cjs/koni/api/tokens/wasm/index.js +5 -4
- package/cjs/koni/api/tokens/wasm/utils.js +63 -0
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/utils.js +18 -13
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/api/xcm/xcmPallet.js +9 -6
- package/cjs/koni/background/cron.js +171 -61
- package/cjs/koni/background/handlers/Extension.js +391 -207
- package/cjs/koni/background/handlers/State.js +49 -34
- package/cjs/koni/background/handlers/Tabs.js +50 -17
- package/cjs/koni/background/subscription.js +53 -28
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/base/types.js +20 -0
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
- package/cjs/services/chain-service/index.js +73 -49
- package/cjs/services/event-service/index.js +5 -1
- package/cjs/services/event-service/types.js +11 -1
- package/cjs/services/history-service/index.js +101 -50
- package/cjs/services/history-service/subsquid-multi-chain-history.js +13 -10
- package/cjs/services/keyring-service/index.js +11 -13
- package/cjs/services/migration-service/scripts/MigrateImportedToken.js +2 -1
- package/cjs/services/price-service/coingecko.js +0 -1
- package/cjs/services/price-service/index.js +71 -24
- package/cjs/services/request-service/handler/AuthRequestHandler.js +13 -7
- package/cjs/services/request-service/handler/EvmRequestHandler.js +8 -12
- package/cjs/services/request-service/index.js +14 -5
- package/cjs/services/storage-service/DatabaseService.js +66 -34
- package/cjs/services/storage-service/db-stores/Nft.js +7 -15
- package/cjs/services/storage-service/db-stores/Transaction.js +6 -10
- package/cjs/services/transaction-service/event-parser/index.js +20 -48
- package/cjs/services/transaction-service/index.js +104 -48
- package/cjs/services/transaction-service/utils.js +10 -8
- package/cjs/utils/address.js +10 -1
- package/cjs/utils/index.js +9 -15
- package/cjs/utils/promise.js +26 -0
- package/constants/index.d.ts +7 -13
- package/constants/index.js +7 -13
- package/koni/api/dotsama/balance.d.ts +0 -1
- package/koni/api/dotsama/balance.js +22 -197
- package/koni/api/dotsama/transfer.js +11 -16
- package/koni/api/nft/acala_nft/index.js +7 -7
- package/koni/api/nft/bit.country/index.js +7 -6
- package/koni/api/nft/evm_nft/index.js +7 -3
- package/koni/api/nft/index.d.ts +1 -2
- package/koni/api/nft/index.js +3 -6
- package/koni/api/nft/karura_nft/index.js +7 -6
- package/koni/api/nft/nft.d.ts +1 -0
- package/koni/api/nft/rmrk_nft/index.js +11 -1
- package/koni/api/nft/statemine_nft/index.js +7 -6
- package/koni/api/nft/unique_nft/index.js +5 -1
- package/koni/api/nft/wasm_nft/index.d.ts +0 -2
- package/koni/api/nft/wasm_nft/index.js +168 -109
- package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
- package/koni/api/nft/wasm_nft/utils.js +7 -5
- package/koni/api/staking/bonding/amplitude.d.ts +0 -1
- package/koni/api/staking/bonding/amplitude.js +15 -10
- package/koni/api/staking/bonding/astar.js +8 -6
- package/koni/api/staking/bonding/index.d.ts +4 -1
- package/koni/api/staking/bonding/index.js +23 -13
- package/koni/api/staking/bonding/paraChain.d.ts +3 -0
- package/koni/api/staking/bonding/paraChain.js +86 -5
- package/koni/api/staking/bonding/relayChain.d.ts +5 -1
- package/koni/api/staking/bonding/relayChain.js +121 -18
- package/koni/api/staking/bonding/utils.d.ts +3 -2
- package/koni/api/staking/bonding/utils.js +27 -9
- package/koni/api/tokens/wasm/index.js +5 -4
- package/koni/api/tokens/wasm/utils.d.ts +6 -0
- package/koni/api/tokens/wasm/utils.js +54 -0
- package/koni/api/xcm/polkadotXcm.js +2 -2
- package/koni/api/xcm/utils.d.ts +5 -6
- package/koni/api/xcm/utils.js +15 -10
- package/koni/api/xcm/xTokens.js +2 -2
- package/koni/api/xcm/xcmPallet.js +10 -9
- package/koni/background/cron.d.ts +6 -1
- package/koni/background/cron.js +172 -62
- package/koni/background/handlers/Extension.d.ts +9 -3
- package/koni/background/handlers/Extension.js +306 -126
- package/koni/background/handlers/State.d.ts +5 -6
- package/koni/background/handlers/State.js +51 -34
- package/koni/background/handlers/Tabs.js +50 -17
- package/koni/background/subscription.d.ts +2 -0
- package/koni/background/subscription.js +51 -29
- package/package.json +29 -14
- package/packageInfo.js +1 -1
- package/services/base/types.d.ts +34 -0
- package/services/base/types.js +15 -0
- package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
- package/services/chain-service/helper/psp22_abi.json +1041 -881
- package/services/chain-service/helper/psp34_abi.json +2963 -1807
- package/services/chain-service/index.d.ts +5 -2
- package/services/chain-service/index.js +68 -45
- package/services/chain-service/types.d.ts +1 -0
- package/services/event-service/index.js +5 -1
- package/services/event-service/types.d.ts +5 -9
- package/services/event-service/types.js +4 -1
- package/services/history-service/index.d.ts +28 -7
- package/services/history-service/index.js +101 -50
- package/services/history-service/subsquid-multi-chain-history.js +16 -12
- package/services/keyring-service/index.d.ts +4 -2
- package/services/keyring-service/index.js +11 -13
- package/services/migration-service/scripts/MigrateImportedToken.js +2 -1
- package/services/price-service/coingecko.js +0 -1
- package/services/price-service/index.d.ts +22 -1
- package/services/price-service/index.js +71 -24
- package/services/request-service/handler/AuthRequestHandler.d.ts +3 -1
- package/services/request-service/handler/AuthRequestHandler.js +13 -7
- package/services/request-service/handler/EvmRequestHandler.js +8 -12
- package/services/request-service/index.d.ts +3 -1
- package/services/request-service/index.js +14 -5
- package/services/storage-service/DatabaseService.d.ts +2 -0
- package/services/storage-service/DatabaseService.js +66 -34
- package/services/storage-service/db-stores/Nft.d.ts +2 -2
- package/services/storage-service/db-stores/Nft.js +7 -14
- package/services/storage-service/db-stores/Transaction.d.ts +2 -0
- package/services/storage-service/db-stores/Transaction.js +6 -10
- package/services/transaction-service/event-parser/index.js +21 -49
- package/services/transaction-service/index.d.ts +2 -0
- package/services/transaction-service/index.js +86 -32
- package/services/transaction-service/types.d.ts +2 -0
- package/services/transaction-service/utils.js +10 -8
- package/utils/address.d.ts +3 -0
- package/utils/address.js +8 -1
- package/utils/index.d.ts +2 -2
- package/utils/index.js +7 -13
- package/utils/promise.d.ts +6 -0
- package/utils/promise.js +20 -0
|
@@ -3,17 +3,19 @@ import { EventService } from '@subwallet/extension-base/services/event-service';
|
|
|
3
3
|
import { SubjectInfo } from '@subwallet/ui-keyring/observable/types';
|
|
4
4
|
import { BehaviorSubject } from 'rxjs';
|
|
5
5
|
export declare class KeyringService {
|
|
6
|
+
private eventService;
|
|
6
7
|
private readonly currentAccountStore;
|
|
7
8
|
readonly currentAccountSubject: BehaviorSubject<CurrentAccountInfo>;
|
|
8
|
-
readonly
|
|
9
|
+
readonly addressesSubject: BehaviorSubject<SubjectInfo>;
|
|
10
|
+
readonly accountSubject: BehaviorSubject<SubjectInfo>;
|
|
9
11
|
private beforeAccount;
|
|
10
12
|
readonly keyringStateSubject: BehaviorSubject<KeyringState>;
|
|
11
|
-
private eventService;
|
|
12
13
|
constructor(eventService: EventService);
|
|
13
14
|
private subscribeAccounts;
|
|
14
15
|
get keyringState(): KeyringState;
|
|
15
16
|
updateKeyringState(isReady?: boolean): void;
|
|
16
17
|
get accounts(): SubjectInfo;
|
|
18
|
+
get addresses(): SubjectInfo;
|
|
17
19
|
get currentAccount(): CurrentAccountInfo;
|
|
18
20
|
setCurrentAccount(currentAccountData: CurrentAccountInfo): void;
|
|
19
21
|
}
|
|
@@ -10,8 +10,9 @@ export class KeyringService {
|
|
|
10
10
|
address: '',
|
|
11
11
|
currentGenesisHash: null
|
|
12
12
|
});
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
addressesSubject = keyring.addresses.subject;
|
|
14
|
+
accountSubject = keyring.accounts.subject;
|
|
15
|
+
beforeAccount = this.accountSubject.value;
|
|
15
16
|
keyringStateSubject = new BehaviorSubject({
|
|
16
17
|
isReady: false,
|
|
17
18
|
hasMasterPassword: false,
|
|
@@ -20,23 +21,17 @@ export class KeyringService {
|
|
|
20
21
|
constructor(eventService) {
|
|
21
22
|
this.eventService = eventService;
|
|
22
23
|
this.currentAccountStore.get('CurrentAccountInfo', rs => {
|
|
23
|
-
this.currentAccountSubject.next(rs);
|
|
24
|
+
rs && this.currentAccountSubject.next(rs);
|
|
24
25
|
});
|
|
25
26
|
this.subscribeAccounts().catch(console.error);
|
|
26
27
|
}
|
|
27
28
|
async subscribeAccounts() {
|
|
28
29
|
// Wait until account ready
|
|
29
|
-
await
|
|
30
|
-
const onReady = () => {
|
|
31
|
-
this.eventService.off('account.ready', onReady);
|
|
32
|
-
resolve(true);
|
|
33
|
-
};
|
|
34
|
-
this.eventService.on('account.ready', onReady);
|
|
35
|
-
});
|
|
30
|
+
await this.eventService.waitAccountReady;
|
|
36
31
|
this.beforeAccount = {
|
|
37
|
-
...this.
|
|
32
|
+
...this.accountSubject.value
|
|
38
33
|
};
|
|
39
|
-
this.
|
|
34
|
+
this.accountSubject.subscribe(subjectInfo => {
|
|
40
35
|
// Check if accounts changed
|
|
41
36
|
const beforeAddresses = Object.keys(this.beforeAccount);
|
|
42
37
|
const afterAddresses = Object.keys(subjectInfo);
|
|
@@ -80,7 +75,10 @@ export class KeyringService {
|
|
|
80
75
|
});
|
|
81
76
|
}
|
|
82
77
|
get accounts() {
|
|
83
|
-
return this.
|
|
78
|
+
return this.accountSubject.value;
|
|
79
|
+
}
|
|
80
|
+
get addresses() {
|
|
81
|
+
return this.addressesSubject.value;
|
|
84
82
|
}
|
|
85
83
|
get currentAccount() {
|
|
86
84
|
return this.currentAccountSubject.value;
|
|
@@ -16,7 +16,6 @@ export const getTokenPrice = async (priceIds, currency = 'usd') => {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
if (useBackupApi || ((_res = res) === null || _res === void 0 ? void 0 : _res.status) !== 200) {
|
|
19
|
-
console.log('Use backup api for price');
|
|
20
19
|
useBackupApi = true;
|
|
21
20
|
res = await axios.get(`https://chain-data.subwallet.app/api/price/get?ids=${idStr}`);
|
|
22
21
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { PriceJson } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import { CronServiceInterface, PersistDataServiceInterface, ServiceStatus, StoppableServiceInterface } from '@subwallet/extension-base/services/base/types';
|
|
2
3
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
3
4
|
import { EventService } from '@subwallet/extension-base/services/event-service';
|
|
4
5
|
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
5
6
|
import { BehaviorSubject } from 'rxjs';
|
|
6
|
-
export declare class PriceService {
|
|
7
|
+
export declare class PriceService implements StoppableServiceInterface, PersistDataServiceInterface, CronServiceInterface {
|
|
8
|
+
status: ServiceStatus;
|
|
7
9
|
private dbService;
|
|
8
10
|
private eventService;
|
|
9
11
|
private chainService;
|
|
@@ -15,4 +17,23 @@ export declare class PriceService {
|
|
|
15
17
|
getPriceSubject(): BehaviorSubject<PriceJson>;
|
|
16
18
|
getPriceIds(): Set<string>;
|
|
17
19
|
refreshPriceData(priceIds?: Set<string>): void;
|
|
20
|
+
init(): Promise<void>;
|
|
21
|
+
loadData(): Promise<void>;
|
|
22
|
+
persistData(): Promise<void>;
|
|
23
|
+
startPromiseHandler: {
|
|
24
|
+
resolve: (value: void) => void;
|
|
25
|
+
reject: (reason?: unknown) => void;
|
|
26
|
+
promise: Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
start(): Promise<void>;
|
|
29
|
+
startCron(): Promise<void>;
|
|
30
|
+
stopPromiseHandler: {
|
|
31
|
+
resolve: (value: void) => void;
|
|
32
|
+
reject: (reason?: unknown) => void;
|
|
33
|
+
promise: Promise<void>;
|
|
34
|
+
};
|
|
35
|
+
stop(): Promise<void>;
|
|
36
|
+
stopCron(): Promise<void>;
|
|
37
|
+
waitForStarted(): Promise<void>;
|
|
38
|
+
waitForStopped(): Promise<void>;
|
|
18
39
|
}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { CRON_REFRESH_PRICE_INTERVAL } from '@subwallet/extension-base/constants';
|
|
5
|
+
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
5
6
|
import { getTokenPrice } from '@subwallet/extension-base/services/price-service/coingecko';
|
|
7
|
+
import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
|
|
6
8
|
import { BehaviorSubject } from 'rxjs';
|
|
7
9
|
const DEFAULT_PRICE_SUBJECT = {
|
|
8
10
|
ready: false,
|
|
@@ -14,34 +16,14 @@ export class PriceService {
|
|
|
14
16
|
priceSubject = new BehaviorSubject(DEFAULT_PRICE_SUBJECT);
|
|
15
17
|
priceIds = new Set();
|
|
16
18
|
constructor(dbService, eventService, chainService) {
|
|
19
|
+
this.status = ServiceStatus.NOT_INITIALIZED;
|
|
17
20
|
this.dbService = dbService;
|
|
18
21
|
this.eventService = eventService;
|
|
19
22
|
this.chainService = chainService;
|
|
20
|
-
|
|
21
|
-
// Fetch data from storage
|
|
22
|
-
this.getPrice().catch(console.error);
|
|
23
|
-
const eventHandler = () => {
|
|
24
|
-
const newPriceIds = this.getPriceIds();
|
|
25
|
-
|
|
26
|
-
// Compare two set newPriceIds and this.priceIds
|
|
27
|
-
if (newPriceIds.size !== this.priceIds.size || !Array.from(newPriceIds).every(v => this.priceIds.has(v))) {
|
|
28
|
-
this.priceIds = newPriceIds;
|
|
29
|
-
this.refreshPriceData(this.priceIds);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
this.eventService.waitAssetReady.then(() => {
|
|
33
|
-
this.refreshPriceData();
|
|
34
|
-
this.eventService.on('asset.enable', eventHandler);
|
|
35
|
-
this.eventService.on('asset.update', eventHandler);
|
|
36
|
-
}).catch(console.error);
|
|
23
|
+
this.init().catch(console.error);
|
|
37
24
|
}
|
|
38
25
|
async getPrice() {
|
|
39
|
-
|
|
40
|
-
if (!isReady) {
|
|
41
|
-
const data = await this.dbService.getPriceStore();
|
|
42
|
-
this.priceSubject.next(data || DEFAULT_PRICE_SUBJECT);
|
|
43
|
-
}
|
|
44
|
-
return this.priceSubject.value;
|
|
26
|
+
return Promise.resolve(this.priceSubject.value);
|
|
45
27
|
}
|
|
46
28
|
getPriceSubject() {
|
|
47
29
|
return this.priceSubject;
|
|
@@ -62,8 +44,73 @@ export class PriceService {
|
|
|
62
44
|
ready: true
|
|
63
45
|
});
|
|
64
46
|
this.dbService.updatePriceStore(rs).catch(console.error);
|
|
65
|
-
console.log('Get Token Price From CoinGecko');
|
|
66
47
|
}).catch(console.error);
|
|
67
48
|
this.refreshTimeout = setTimeout(this.refreshPriceData.bind(this), CRON_REFRESH_PRICE_INTERVAL);
|
|
68
49
|
}
|
|
50
|
+
async init() {
|
|
51
|
+
this.status = ServiceStatus.INITIALIZING;
|
|
52
|
+
// Fetch data from storage
|
|
53
|
+
await this.loadData();
|
|
54
|
+
const eventHandler = () => {
|
|
55
|
+
const newPriceIds = this.getPriceIds();
|
|
56
|
+
|
|
57
|
+
// Compare two set newPriceIds and this.priceIds
|
|
58
|
+
if (newPriceIds.size !== this.priceIds.size || !Array.from(newPriceIds).every(v => this.priceIds.has(v))) {
|
|
59
|
+
this.priceIds = newPriceIds;
|
|
60
|
+
this.refreshPriceData(this.priceIds);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
await this.eventService.waitAssetReady;
|
|
64
|
+
this.status = ServiceStatus.INITIALIZED;
|
|
65
|
+
this.eventService.on('asset.updateState', eventHandler);
|
|
66
|
+
this.eventService.on('asset.updateState', eventHandler);
|
|
67
|
+
}
|
|
68
|
+
async loadData() {
|
|
69
|
+
const data = await this.dbService.getPriceStore();
|
|
70
|
+
this.priceSubject.next(data || DEFAULT_PRICE_SUBJECT);
|
|
71
|
+
}
|
|
72
|
+
async persistData() {
|
|
73
|
+
await this.dbService.updatePriceStore(this.priceSubject.value).catch(console.error);
|
|
74
|
+
}
|
|
75
|
+
startPromiseHandler = createPromiseHandler();
|
|
76
|
+
async start() {
|
|
77
|
+
console.debug('Start price service');
|
|
78
|
+
try {
|
|
79
|
+
this.startPromiseHandler = createPromiseHandler();
|
|
80
|
+
this.status = ServiceStatus.STARTING;
|
|
81
|
+
await this.startCron();
|
|
82
|
+
this.status = ServiceStatus.STARTED;
|
|
83
|
+
this.startPromiseHandler.resolve();
|
|
84
|
+
} catch (e) {
|
|
85
|
+
this.startPromiseHandler.reject(e);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async startCron() {
|
|
89
|
+
this.refreshPriceData();
|
|
90
|
+
return Promise.resolve();
|
|
91
|
+
}
|
|
92
|
+
stopPromiseHandler = createPromiseHandler();
|
|
93
|
+
async stop() {
|
|
94
|
+
console.debug('Stop price service');
|
|
95
|
+
try {
|
|
96
|
+
this.status = ServiceStatus.STOPPING;
|
|
97
|
+
this.stopPromiseHandler = createPromiseHandler();
|
|
98
|
+
await this.stopCron();
|
|
99
|
+
await this.persistData();
|
|
100
|
+
this.status = ServiceStatus.STOPPED;
|
|
101
|
+
this.stopPromiseHandler.resolve();
|
|
102
|
+
} catch (e) {
|
|
103
|
+
this.stopPromiseHandler.reject(e);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
stopCron() {
|
|
107
|
+
clearTimeout(this.refreshTimeout);
|
|
108
|
+
return Promise.resolve(undefined);
|
|
109
|
+
}
|
|
110
|
+
waitForStarted() {
|
|
111
|
+
return this.startPromiseHandler.promise;
|
|
112
|
+
}
|
|
113
|
+
waitForStopped() {
|
|
114
|
+
return this.stopPromiseHandler.promise;
|
|
115
|
+
}
|
|
69
116
|
}
|
|
@@ -2,17 +2,19 @@ import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
|
2
2
|
import { AuthRequestV2 } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { AccountAuthType, AuthorizeRequest, RequestAuthorizeTab } from '@subwallet/extension-base/background/types';
|
|
4
4
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
5
|
+
import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
|
|
5
6
|
import RequestService from '@subwallet/extension-base/services/request-service';
|
|
6
7
|
import { AuthUrls } from '@subwallet/extension-base/services/request-service/types';
|
|
7
8
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
8
9
|
export default class AuthRequestHandler {
|
|
9
10
|
#private;
|
|
11
|
+
private keyringService;
|
|
10
12
|
private readonly authorizeStore;
|
|
11
13
|
private authorizeCached;
|
|
12
14
|
private readonly authorizeUrlSubject;
|
|
13
15
|
private readonly evmChainSubject;
|
|
14
16
|
readonly authSubjectV2: BehaviorSubject<AuthorizeRequest[]>;
|
|
15
|
-
constructor(requestService: RequestService, chainService: ChainService);
|
|
17
|
+
constructor(requestService: RequestService, chainService: ChainService, keyringService: KeyringService);
|
|
16
18
|
private stripUrl;
|
|
17
19
|
private getAddressList;
|
|
18
20
|
get numAuthRequestsV2(): number;
|
|
@@ -6,7 +6,6 @@ import { PREDEFINED_CHAIN_DAPP_CHAIN_MAP } from '@subwallet/extension-base/servi
|
|
|
6
6
|
import AuthorizeStore from '@subwallet/extension-base/stores/Authorize';
|
|
7
7
|
import { getDomainFromUrl } from '@subwallet/extension-base/utils';
|
|
8
8
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
9
|
-
import { accounts } from '@subwallet/ui-keyring/observable/accounts';
|
|
10
9
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
11
10
|
import { assert } from '@polkadot/util';
|
|
12
11
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
@@ -20,7 +19,8 @@ export default class AuthRequestHandler {
|
|
|
20
19
|
authorizeUrlSubject = new Subject();
|
|
21
20
|
evmChainSubject = new Subject();
|
|
22
21
|
authSubjectV2 = new BehaviorSubject([]);
|
|
23
|
-
constructor(requestService, chainService) {
|
|
22
|
+
constructor(requestService, chainService, keyringService) {
|
|
23
|
+
this.keyringService = keyringService;
|
|
24
24
|
this.#requestService = requestService;
|
|
25
25
|
this.#chainService = chainService;
|
|
26
26
|
}
|
|
@@ -30,7 +30,7 @@ export default class AuthRequestHandler {
|
|
|
30
30
|
return parts[2];
|
|
31
31
|
}
|
|
32
32
|
getAddressList(value = false) {
|
|
33
|
-
const addressList = Object.keys(
|
|
33
|
+
const addressList = Object.keys(this.keyringService.accounts);
|
|
34
34
|
return addressList.reduce((addressList, v) => ({
|
|
35
35
|
...addressList,
|
|
36
36
|
[v]: value
|
|
@@ -84,11 +84,11 @@ export default class AuthRequestHandler {
|
|
|
84
84
|
const chainInfoMaps = this.#chainService.getChainInfoMap();
|
|
85
85
|
const chainStateMap = this.#chainService.getChainStateMap();
|
|
86
86
|
let defaultChain = options.defaultChain;
|
|
87
|
-
|
|
87
|
+
let needEnableChains = [];
|
|
88
88
|
if (options.url) {
|
|
89
89
|
const domain = getDomainFromUrl(options.url);
|
|
90
90
|
const predefinedSupportChains = PREDEFINED_CHAIN_DAPP_CHAIN_MAP[domain];
|
|
91
|
-
if (predefinedSupportChains) {
|
|
91
|
+
if (!defaultChain && predefinedSupportChains) {
|
|
92
92
|
defaultChain = predefinedSupportChains[0];
|
|
93
93
|
options.autoActive && needEnableChains.push(...predefinedSupportChains);
|
|
94
94
|
}
|
|
@@ -101,11 +101,17 @@ export default class AuthRequestHandler {
|
|
|
101
101
|
return (_chainStateMap$chain$ = chainStateMap[chain.slug]) === null || _chainStateMap$chain$ === void 0 ? void 0 : _chainStateMap$chain$.active;
|
|
102
102
|
})) || evmChains[0];
|
|
103
103
|
if (options.autoActive) {
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
var _chainInfo;
|
|
105
|
+
if (!needEnableChains.includes((_chainInfo = chainInfo) === null || _chainInfo === void 0 ? void 0 : _chainInfo.slug)) {
|
|
106
|
+
var _chainInfo2;
|
|
107
|
+
needEnableChains.push((_chainInfo2 = chainInfo) === null || _chainInfo2 === void 0 ? void 0 : _chainInfo2.slug);
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
}
|
|
111
|
+
needEnableChains = needEnableChains.filter(slug => {
|
|
112
|
+
var _chainStateMap$slug;
|
|
113
|
+
return !((_chainStateMap$slug = chainStateMap[slug]) !== null && _chainStateMap$slug !== void 0 && _chainStateMap$slug.active);
|
|
114
|
+
});
|
|
109
115
|
needEnableChains.length > 0 && this.#chainService.enableChains(needEnableChains);
|
|
110
116
|
return chainInfo;
|
|
111
117
|
}
|
|
@@ -67,16 +67,7 @@ export default class EvmRequestHandler {
|
|
|
67
67
|
});
|
|
68
68
|
this.confirmationsQueueSubject.next(confirmations);
|
|
69
69
|
if (!isInternal) {
|
|
70
|
-
|
|
71
|
-
const popupList = this.#requestService.popup;
|
|
72
|
-
if (this.#requestService.popup.length > 0) {
|
|
73
|
-
// eslint-disable-next-line no-void
|
|
74
|
-
void chrome.windows.update(popupList[0], {
|
|
75
|
-
focused: true
|
|
76
|
-
});
|
|
77
|
-
} else {
|
|
78
|
-
this.#requestService.popupOpen();
|
|
79
|
-
}
|
|
70
|
+
this.#requestService.popupOpen();
|
|
80
71
|
}
|
|
81
72
|
this.#requestService.updateIconV2();
|
|
82
73
|
return promise;
|
|
@@ -127,7 +118,8 @@ export default class EvmRequestHandler {
|
|
|
127
118
|
data: toBuffer(config.data)
|
|
128
119
|
};
|
|
129
120
|
const common = Common.custom({
|
|
130
|
-
chainId: config.chainId
|
|
121
|
+
chainId: config.chainId,
|
|
122
|
+
defaultHardfork: 'petersburg'
|
|
131
123
|
});
|
|
132
124
|
|
|
133
125
|
// @ts-ignore
|
|
@@ -140,11 +132,15 @@ export default class EvmRequestHandler {
|
|
|
140
132
|
const {
|
|
141
133
|
estimateGas,
|
|
142
134
|
from,
|
|
143
|
-
|
|
135
|
+
gas,
|
|
136
|
+
gasPrice,
|
|
137
|
+
value
|
|
144
138
|
} = transaction;
|
|
145
139
|
const pair = keyring.getPair(from);
|
|
146
140
|
const params = {
|
|
147
141
|
...transaction,
|
|
142
|
+
gas: anyNumberToBN(gas).toNumber(),
|
|
143
|
+
value: anyNumberToBN(value).toNumber(),
|
|
148
144
|
gasPrice: anyNumberToBN(gasPrice).toNumber(),
|
|
149
145
|
gasLimit: anyNumberToBN(estimateGas).toNumber()
|
|
150
146
|
// nonce: await web3.eth.getTransactionCount(from) // Todo: fill this value from transaction service
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AuthRequestV2, ConfirmationDefinitions, ConfirmationsQueue, ConfirmationsQueueItemOptions, ConfirmationType, RequestConfirmationComplete } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
2
|
import { AccountAuthType, AccountJson, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestSign, ResponseSigning, SigningRequest } from '@subwallet/extension-base/background/types';
|
|
3
3
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
4
|
+
import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
|
|
4
5
|
import { AuthUrls, MetaRequest } from '@subwallet/extension-base/services/request-service/types';
|
|
5
6
|
import SettingService from '@subwallet/extension-base/services/setting-service/SettingService';
|
|
6
7
|
import { MetadataDef } from '@subwallet/extension-inject/types';
|
|
@@ -8,8 +9,9 @@ import { BehaviorSubject, Subject } from 'rxjs';
|
|
|
8
9
|
import { SignerPayloadJSON } from '@polkadot/types/types/extrinsic';
|
|
9
10
|
export default class RequestService {
|
|
10
11
|
#private;
|
|
12
|
+
private keyringService;
|
|
11
13
|
readonly settingService: SettingService;
|
|
12
|
-
constructor(chainService: ChainService, settingService: SettingService);
|
|
14
|
+
constructor(chainService: ChainService, settingService: SettingService, keyringService: KeyringService);
|
|
13
15
|
get numAllRequests(): number;
|
|
14
16
|
updateIconV2(shouldClose?: boolean): void;
|
|
15
17
|
getAddressList(value?: boolean): Record<string, boolean>;
|
|
@@ -6,7 +6,6 @@ import EvmRequestHandler from '@subwallet/extension-base/services/request-servic
|
|
|
6
6
|
import MetadataRequestHandler from '@subwallet/extension-base/services/request-service/handler/MetadataRequestHandler';
|
|
7
7
|
import PopupHandler from '@subwallet/extension-base/services/request-service/handler/PopupHandler';
|
|
8
8
|
import SubstrateRequestHandler from '@subwallet/extension-base/services/request-service/handler/SubstrateRequestHandler';
|
|
9
|
-
import { accounts } from '@subwallet/ui-keyring/observable/accounts';
|
|
10
9
|
export default class RequestService {
|
|
11
10
|
// Common
|
|
12
11
|
#chainService;
|
|
@@ -17,12 +16,13 @@ export default class RequestService {
|
|
|
17
16
|
#evmRequestHandler;
|
|
18
17
|
|
|
19
18
|
// Common
|
|
20
|
-
constructor(chainService, settingService) {
|
|
19
|
+
constructor(chainService, settingService, keyringService) {
|
|
20
|
+
this.keyringService = keyringService;
|
|
21
21
|
this.#chainService = chainService;
|
|
22
22
|
this.settingService = settingService;
|
|
23
23
|
this.#popupHandler = new PopupHandler(this);
|
|
24
24
|
this.#metadataRequestHandler = new MetadataRequestHandler(this);
|
|
25
|
-
this.#authRequestHandler = new AuthRequestHandler(this, this.#chainService);
|
|
25
|
+
this.#authRequestHandler = new AuthRequestHandler(this, this.#chainService, this.keyringService);
|
|
26
26
|
this.#substrateRequestHandler = new SubstrateRequestHandler(this);
|
|
27
27
|
this.#evmRequestHandler = new EvmRequestHandler(this);
|
|
28
28
|
|
|
@@ -36,7 +36,7 @@ export default class RequestService {
|
|
|
36
36
|
this.#popupHandler.updateIconV2(shouldClose);
|
|
37
37
|
}
|
|
38
38
|
getAddressList(value = false) {
|
|
39
|
-
const addressList = Object.keys(
|
|
39
|
+
const addressList = Object.keys(this.keyringService.accounts);
|
|
40
40
|
return addressList.reduce((addressList, v) => ({
|
|
41
41
|
...addressList,
|
|
42
42
|
[v]: value
|
|
@@ -51,7 +51,16 @@ export default class RequestService {
|
|
|
51
51
|
this.#popupHandler.popupClose();
|
|
52
52
|
}
|
|
53
53
|
popupOpen() {
|
|
54
|
-
|
|
54
|
+
// Not open new popup and use existed
|
|
55
|
+
const popupList = this.#popupHandler.popup;
|
|
56
|
+
if (popupList && popupList.length > 0) {
|
|
57
|
+
var _chrome$windows$updat;
|
|
58
|
+
(_chrome$windows$updat = chrome.windows.update(popupList[0], {
|
|
59
|
+
focused: true
|
|
60
|
+
})) === null || _chrome$windows$updat === void 0 ? void 0 : _chrome$windows$updat.catch(console.error);
|
|
61
|
+
} else {
|
|
62
|
+
this.#popupHandler.popupOpen();
|
|
63
|
+
}
|
|
55
64
|
}
|
|
56
65
|
|
|
57
66
|
// Metadata
|
|
@@ -41,10 +41,12 @@ export default class DatabaseService {
|
|
|
41
41
|
subscribeNominatorMetadata(callback: (data: NominatorMetadata[]) => void): void;
|
|
42
42
|
getHistories(query?: HistoryQuery): Promise<import("@subwallet/extension-base/services/storage-service/databases").ITransactionHistoryItem[]>;
|
|
43
43
|
upsertHistory(histories: TransactionHistoryItem[]): Promise<unknown>;
|
|
44
|
+
updateHistoryByNewExtrinsicHash(extrinsicHash: string, updateData: Partial<TransactionHistoryItem>): Promise<unknown>;
|
|
44
45
|
addNftCollection(collection: NftCollection): Promise<unknown>;
|
|
45
46
|
deleteNftCollection(chain: string, collectionId: string): Promise<void>;
|
|
46
47
|
getAllNftCollection(chainHashes?: string[]): import("dexie").PromiseExtended<NftCollection[]>;
|
|
47
48
|
subscribeNft(addresses: string[], chainHashes?: string[], callback?: (nfts: INft[]) => void): Subscription;
|
|
49
|
+
cleanUpNft(chain: string, owner: string, collectionIds: string[], nftIds: string[], ownNothing?: boolean): Promise<number>;
|
|
48
50
|
getNft(addresses: string[], chainHashes?: string[]): Promise<INft[]>;
|
|
49
51
|
addNft(address: string, nft: NftItem): Promise<unknown>;
|
|
50
52
|
handleNftTransfer(chain: string, addresses: string[], nftItem: NftItem): import("dexie").PromiseExtended<number>;
|