@toruslabs/ethereum-controllers 4.10.0 → 4.11.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/dist/ethereumControllers.cjs.js +14 -41
- package/dist/ethereumControllers.cjs.js.map +1 -1
- package/dist/ethereumControllers.esm.js +14 -42
- package/dist/ethereumControllers.esm.js.map +1 -1
- package/dist/ethereumControllers.umd.min.js +1 -1
- package/dist/ethereumControllers.umd.min.js.map +1 -1
- package/dist/types/Preferences/PreferencesController.d.ts +2 -1
- package/package.json +7 -6
- package/src/Preferences/PreferencesController.ts +20 -48
|
@@ -32,6 +32,7 @@ export default class PreferencesController extends BasePreferencesController<Ext
|
|
|
32
32
|
type?: string;
|
|
33
33
|
signatures?: string[];
|
|
34
34
|
network?: string;
|
|
35
|
+
web3AuthClientId?: string;
|
|
35
36
|
}): Promise<void>;
|
|
36
37
|
getSelectedAddress(): string;
|
|
37
38
|
sync(address: string): Promise<boolean>;
|
|
@@ -46,6 +47,7 @@ export default class PreferencesController extends BasePreferencesController<Ext
|
|
|
46
47
|
getSimpleHashNfts(address: string, chainId: string): Promise<CustomNftInfo[]>;
|
|
47
48
|
getCustomTokens(address?: string): CustomToken[];
|
|
48
49
|
getCustomNfts(address?: string): CustomNft[];
|
|
50
|
+
isChainIdSupported(address: string, chainId: string): boolean;
|
|
49
51
|
addChain(network: AddChainMessageParams): Promise<void>;
|
|
50
52
|
switchChain(data: {
|
|
51
53
|
chainId: string;
|
|
@@ -59,7 +61,6 @@ export default class PreferencesController extends BasePreferencesController<Ext
|
|
|
59
61
|
network: CustomNetworkPayload;
|
|
60
62
|
id: number | null;
|
|
61
63
|
}): Promise<boolean>;
|
|
62
|
-
private calculatePaymentTx;
|
|
63
64
|
private getChainOptions;
|
|
64
65
|
private calculatePastTx;
|
|
65
66
|
private cancelTxCalculate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toruslabs/ethereum-controllers",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.11.0",
|
|
4
4
|
"homepage": "https://github.com/torusresearch/controllers#readme",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"main": "dist/ethereumControllers.cjs.js",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"@ethereumjs/util": "^9.0.1",
|
|
25
25
|
"@metamask/eth-sig-util": "^7.0.1",
|
|
26
26
|
"@metamask/rpc-errors": "^6.1.0",
|
|
27
|
-
"@toruslabs/base-controllers": "^4.
|
|
28
|
-
"@toruslabs/http-helpers": "^
|
|
27
|
+
"@toruslabs/base-controllers": "^4.11.0",
|
|
28
|
+
"@toruslabs/http-helpers": "^6.0.0",
|
|
29
29
|
"@toruslabs/openlogin-jrpc": "^6.1.0",
|
|
30
30
|
"async-mutex": "^0.4.0",
|
|
31
31
|
"bignumber.js": "^9.1.2",
|
|
32
32
|
"bn.js": "^5.2.1",
|
|
33
|
-
"ethers": "^6.9.
|
|
33
|
+
"ethers": "^6.9.1",
|
|
34
34
|
"fast-json-patch": "^3.1.1",
|
|
35
35
|
"jsonschema": "^1.4.1",
|
|
36
36
|
"lodash": "^4.17.21",
|
|
@@ -64,8 +64,9 @@
|
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "ece0fb5e61005a05f63eb85dd6a76a0c6e108089",
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"hardhat": "^
|
|
69
|
+
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
|
|
70
|
+
"hardhat": "^2.19.3"
|
|
70
71
|
}
|
|
71
72
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
+
import { stripHexPrefix } from "@ethereumjs/util";
|
|
1
2
|
import {
|
|
2
|
-
ACTIVITY_ACTION_RECEIVE,
|
|
3
|
-
ACTIVITY_ACTION_SEND,
|
|
4
|
-
ACTIVITY_ACTION_TOPUP,
|
|
5
3
|
BasePreferencesController,
|
|
6
4
|
CustomNft,
|
|
7
5
|
CustomToken,
|
|
@@ -30,7 +28,6 @@ import type {
|
|
|
30
28
|
EthereumProviderConfig,
|
|
31
29
|
EthereumUser,
|
|
32
30
|
ExtendedAddressPreferences,
|
|
33
|
-
FetchCommonTransaction,
|
|
34
31
|
FetchedTransaction,
|
|
35
32
|
FormattedTransactionActivity,
|
|
36
33
|
TransactionPayload,
|
|
@@ -98,8 +95,9 @@ export default class PreferencesController
|
|
|
98
95
|
type?: string;
|
|
99
96
|
signatures?: string[];
|
|
100
97
|
network?: string;
|
|
98
|
+
web3AuthClientId?: string;
|
|
101
99
|
}): Promise<void> {
|
|
102
|
-
const { address, jwtToken, calledFromEmbed, userInfo, rehydrate, locale = "en-US", type, signatures, network } = params;
|
|
100
|
+
const { address, jwtToken, calledFromEmbed, userInfo, rehydrate, locale = "en-US", type, signatures, network, web3AuthClientId } = params;
|
|
103
101
|
await super.init(address, userInfo, jwtToken, { type, email: userInfo.email, signatures, network });
|
|
104
102
|
const { aggregateVerifier, verifier, verifierId } = userInfo || {};
|
|
105
103
|
const userExists = await this.sync(address);
|
|
@@ -115,7 +113,13 @@ export default class PreferencesController
|
|
|
115
113
|
});
|
|
116
114
|
}
|
|
117
115
|
if (!rehydrate)
|
|
118
|
-
await this.storeUserLogin({
|
|
116
|
+
await this.storeUserLogin({
|
|
117
|
+
verifier: aggregateVerifier || verifier,
|
|
118
|
+
verifierId,
|
|
119
|
+
options: { calledFromEmbed, rehydrate },
|
|
120
|
+
address,
|
|
121
|
+
web3AuthClientId,
|
|
122
|
+
});
|
|
119
123
|
}
|
|
120
124
|
|
|
121
125
|
public getSelectedAddress(): string {
|
|
@@ -163,15 +167,9 @@ export default class PreferencesController
|
|
|
163
167
|
this.getWalletOrders<FetchedTransaction>(address).catch((error) => {
|
|
164
168
|
log.error("unable to fetch wallet orders", error);
|
|
165
169
|
}),
|
|
166
|
-
this.getTopUpOrders<FetchCommonTransaction>(address).catch((error) => {
|
|
167
|
-
log.error("unable to fetch top up orders", error);
|
|
168
|
-
}),
|
|
169
170
|
])
|
|
170
171
|
.then((data) => {
|
|
171
|
-
const [walletTx
|
|
172
|
-
if (paymentTx) {
|
|
173
|
-
this.calculatePaymentTx(paymentTx, address);
|
|
174
|
-
}
|
|
172
|
+
const [walletTx] = data;
|
|
175
173
|
// eslint-disable-next-line promise/always-return
|
|
176
174
|
if (walletTx && walletTx.length > 0) {
|
|
177
175
|
this.updateState({ fetchedPastTx: [...walletTx] }, address);
|
|
@@ -267,6 +265,12 @@ export default class PreferencesController
|
|
|
267
265
|
return this.getAddressState(address)?.customNfts ?? [];
|
|
268
266
|
}
|
|
269
267
|
|
|
268
|
+
public isChainIdSupported(address: string, chainId: string): boolean {
|
|
269
|
+
const approveChainOptions = this.getChainOptions(address);
|
|
270
|
+
const providerConfig = approveChainOptions.find((x) => stripHexPrefix(x.chainId) === chainId);
|
|
271
|
+
return !!providerConfig;
|
|
272
|
+
}
|
|
273
|
+
|
|
270
274
|
public async addChain(network: AddChainMessageParams): Promise<void> {
|
|
271
275
|
const approveChainOptions = this.getChainOptions();
|
|
272
276
|
const providerConfig = approveChainOptions.find((x) => x.chainId === network.chainId);
|
|
@@ -358,41 +362,9 @@ export default class PreferencesController
|
|
|
358
362
|
}
|
|
359
363
|
}
|
|
360
364
|
|
|
361
|
-
private
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
let action = "";
|
|
365
|
-
const lowerCaseAction = x.action.toLowerCase();
|
|
366
|
-
if (ACTIVITY_ACTION_TOPUP.includes(lowerCaseAction)) action = ACTIVITY_ACTION_TOPUP;
|
|
367
|
-
else if (ACTIVITY_ACTION_SEND.includes(lowerCaseAction)) action = ACTIVITY_ACTION_SEND;
|
|
368
|
-
else if (ACTIVITY_ACTION_RECEIVE.includes(lowerCaseAction)) action = ACTIVITY_ACTION_RECEIVE;
|
|
369
|
-
|
|
370
|
-
accumulator.push({
|
|
371
|
-
id: x.id,
|
|
372
|
-
date: new Date(x.date).toDateString(),
|
|
373
|
-
from: x.from,
|
|
374
|
-
slicedFrom: x.slicedFrom,
|
|
375
|
-
action,
|
|
376
|
-
to: x.to,
|
|
377
|
-
slicedTo: x.slicedTo,
|
|
378
|
-
totalAmount: x.totalAmount,
|
|
379
|
-
totalAmountString: x.totalAmountString,
|
|
380
|
-
currencyAmount: x.currencyAmount,
|
|
381
|
-
currencyAmountString: x.currencyAmountString,
|
|
382
|
-
amount: x.amount,
|
|
383
|
-
ethRate: x.ethRate,
|
|
384
|
-
status: x.status.toLowerCase(),
|
|
385
|
-
etherscanLink: x.etherscanLink || "",
|
|
386
|
-
blockExplorerLink: "",
|
|
387
|
-
currencyUsed: x.currencyUsed,
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
this.updateState({ paymentTx: accumulator }, address);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
private getChainOptions(): EthereumProviderConfig[] {
|
|
394
|
-
const { selectedAddress, identities } = this.state;
|
|
395
|
-
const customNetworks = identities[selectedAddress]?.customNetworks ?? [];
|
|
365
|
+
private getChainOptions(address: string = this.state.selectedAddress): EthereumProviderConfig[] {
|
|
366
|
+
const { identities } = this.state;
|
|
367
|
+
const customNetworks = identities[address]?.customNetworks ?? [];
|
|
396
368
|
|
|
397
369
|
const custom: EthereumProviderConfig[] = Object.values(customNetworks).reduce((chains, network) => {
|
|
398
370
|
const networkItem = {
|