@toruslabs/ethereum-controllers 4.1.0 → 4.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/dist/ethereumControllers.cjs.js +48 -35
- package/dist/ethereumControllers.cjs.js.map +1 -1
- package/dist/ethereumControllers.esm.js +48 -36
- 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/Message/AbstractMessageController.d.ts +1 -1
- package/dist/types/Nfts/NftsController.d.ts +1 -4
- package/dist/types/Preferences/PreferencesController.d.ts +5 -0
- package/dist/types/Tokens/TokensController.d.ts +1 -3
- package/dist/types/utils/constants.d.ts +3 -0
- package/dist/types/utils/interfaces.d.ts +0 -1
- package/package.json +3 -3
- package/src/Message/AbstractMessageController.ts +2 -2
- package/src/Message/DecryptMessageController.ts +3 -5
- package/src/Message/EncryptionPublicKeyController.ts +3 -5
- package/src/Message/MessageController.ts +3 -3
- package/src/Message/PersonalMessageController.ts +4 -4
- package/src/Message/TypedMessageController.ts +3 -3
- package/src/Nfts/NftsController.ts +3 -17
- package/src/Preferences/PreferencesController.ts +17 -4
- package/src/Tokens/TokensController.ts +2 -7
- package/src/Transaction/TransactionStateManager.ts +1 -1
- package/src/utils/constants.ts +11 -7
- package/src/utils/interfaces.ts +0 -1
- package/dist/types/utils/abiDecoder.d.ts +0 -17
- package/src/utils/abiDecoder.ts +0 -195
|
@@ -26,7 +26,7 @@ export default abstract class AbstractMessageController<M extends AbstractMessag
|
|
|
26
26
|
[key: string]: M;
|
|
27
27
|
};
|
|
28
28
|
addMessage(message: M): Promise<void>;
|
|
29
|
-
approveMessage(messageParams: P): Promise<P>;
|
|
29
|
+
approveMessage(messageId: string, messageParams: P): Promise<P>;
|
|
30
30
|
setMessageStatus(messageId: string, status: MessageStatusType): void;
|
|
31
31
|
waitForFinishStatus(msgParams: P, messageName: string): Promise<string>;
|
|
32
32
|
protected updateMessage(message: M): void;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BaseController, PreferencesState } from "@toruslabs/base-controllers";
|
|
2
2
|
import { SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc";
|
|
3
|
-
import NetworkController from "../Network/NetworkController";
|
|
4
3
|
import PreferencesController from "../Preferences/PreferencesController";
|
|
5
4
|
import { CustomNftInfo, EthereumNetworkState, ExtendedAddressPreferences } from "../utils/interfaces";
|
|
6
5
|
import { NftsControllerConfig, NftsControllerState } from "./INftsController";
|
|
@@ -8,7 +7,6 @@ export interface INftsControllerOptions {
|
|
|
8
7
|
config?: Partial<NftsControllerConfig>;
|
|
9
8
|
state?: Partial<NftsControllerState>;
|
|
10
9
|
provider: SafeEventEmitterProvider;
|
|
11
|
-
getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
12
10
|
getCustomNfts?: PreferencesController["getCustomNfts"];
|
|
13
11
|
getSimpleHashNfts: PreferencesController["getSimpleHashNfts"];
|
|
14
12
|
onPreferencesStateChange: (listener: (preferencesState: PreferencesState<ExtendedAddressPreferences>) => void) => void;
|
|
@@ -19,10 +17,9 @@ export declare class NftsController extends BaseController<NftsControllerConfig,
|
|
|
19
17
|
private provider;
|
|
20
18
|
private ethersProvider;
|
|
21
19
|
private _timer;
|
|
22
|
-
private getNetworkIdentifier;
|
|
23
20
|
private getCustomNfts;
|
|
24
21
|
private getSimpleHashNfts;
|
|
25
|
-
constructor({ config, state, provider,
|
|
22
|
+
constructor({ config, state, provider, getCustomNfts, getSimpleHashNfts, onPreferencesStateChange, onNetworkStateChange }: INftsControllerOptions);
|
|
26
23
|
get userSelectedAddress(): string;
|
|
27
24
|
get userNfts(): CustomNftInfo[];
|
|
28
25
|
get interval(): number;
|
|
@@ -27,12 +27,17 @@ export default class PreferencesController extends BasePreferencesController<Ext
|
|
|
27
27
|
userInfo?: UserInfo;
|
|
28
28
|
rehydrate?: boolean;
|
|
29
29
|
locale?: string;
|
|
30
|
+
type?: string;
|
|
30
31
|
}): Promise<void>;
|
|
31
32
|
getSelectedAddress(): string;
|
|
32
33
|
sync(address: string): Promise<boolean>;
|
|
33
34
|
patchNewTx(tx: TransactionPayload, address: string): Promise<void>;
|
|
34
35
|
recalculatePastTx(address?: string): void;
|
|
35
36
|
refetchEtherscanTx(address?: string): Promise<void>;
|
|
37
|
+
fetchEtherscanTx<T>(parameters: {
|
|
38
|
+
selectedAddress: string;
|
|
39
|
+
selectedNetwork: string;
|
|
40
|
+
}): Promise<T[]>;
|
|
36
41
|
getEtherScanTokens(address: string, chainId: string): Promise<CustomTokenInfo[]>;
|
|
37
42
|
getSimpleHashNfts(address: string, chainId: string): Promise<CustomNftInfo[]>;
|
|
38
43
|
getCustomTokens(address?: string): CustomToken[];
|
|
@@ -8,7 +8,6 @@ export interface ITokensControllerOptions {
|
|
|
8
8
|
config?: Partial<TokensControllerConfig>;
|
|
9
9
|
state?: Partial<TokensControllerState>;
|
|
10
10
|
provider: SafeEventEmitterProvider;
|
|
11
|
-
getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
12
11
|
getCustomTokens?: PreferencesController["getCustomTokens"];
|
|
13
12
|
getEtherScanTokens: PreferencesController["getEtherScanTokens"];
|
|
14
13
|
getProviderConfig: NetworkController["getProviderConfig"];
|
|
@@ -20,11 +19,10 @@ export declare class TokensController extends BaseController<TokensControllerCon
|
|
|
20
19
|
private provider;
|
|
21
20
|
private ethersProvider;
|
|
22
21
|
private _timer;
|
|
23
|
-
private getNetworkIdentifier;
|
|
24
22
|
private getProviderConfig;
|
|
25
23
|
private getCustomTokens;
|
|
26
24
|
private getEtherScanTokens;
|
|
27
|
-
constructor({ config, state, provider,
|
|
25
|
+
constructor({ config, state, provider, getCustomTokens, getEtherScanTokens, getProviderConfig, onPreferencesStateChange, onNetworkStateChange, }: ITokensControllerOptions);
|
|
28
26
|
get userSelectedAddress(): string;
|
|
29
27
|
get userTokens(): CustomTokenInfo[];
|
|
30
28
|
get interval(): number;
|
|
@@ -229,7 +229,6 @@ export type PollingBlockTrackerState = BaseBlockTrackerState<EthereumBlock>;
|
|
|
229
229
|
export interface EthereumProviderConfig extends ProviderConfig {
|
|
230
230
|
isErc20?: boolean;
|
|
231
231
|
tokenAddress?: string;
|
|
232
|
-
isTestNet?: boolean;
|
|
233
232
|
}
|
|
234
233
|
export interface EthereumNetworkState extends NetworkState {
|
|
235
234
|
providerConfig: EthereumProviderConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toruslabs/ethereum-controllers",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"homepage": "https://github.com/torusresearch/controllers#readme",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"main": "dist/ethereumControllers.cjs.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@ethereumjs/util": "^9.0.0",
|
|
25
25
|
"@metamask/eth-sig-util": "^7.0.0",
|
|
26
26
|
"@metamask/rpc-errors": "^6.0.0",
|
|
27
|
-
"@toruslabs/base-controllers": "^4.
|
|
27
|
+
"@toruslabs/base-controllers": "^4.3.0",
|
|
28
28
|
"@toruslabs/http-helpers": "^5.0.0",
|
|
29
29
|
"@toruslabs/openlogin-jrpc": "^5.1.0",
|
|
30
30
|
"async-mutex": "^0.4.0",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "42139c8f59f8f4be3e8c03bdfc3987e1df9dc1b7",
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"ganache": "^7.9.1"
|
|
70
70
|
}
|
|
@@ -75,8 +75,8 @@ export default abstract class AbstractMessageController<M extends AbstractMessag
|
|
|
75
75
|
this.saveMessageList();
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
approveMessage(messageParams: P): Promise<P> {
|
|
79
|
-
this.setMessageStatus(
|
|
78
|
+
approveMessage(messageId: string, messageParams: P): Promise<P> {
|
|
79
|
+
this.setMessageStatus(messageId, MessageStatus.APPROVED);
|
|
80
80
|
return this.prepMessageForSigning(messageParams);
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -5,7 +5,7 @@ import log from "loglevel";
|
|
|
5
5
|
|
|
6
6
|
import KeyringController from "../Keyring/KeyringController";
|
|
7
7
|
import NetworkController from "../Network/NetworkController";
|
|
8
|
-
import { MessageStatus, METHOD_TYPES } from "../utils/constants";
|
|
8
|
+
import { MESSAGE_EVENTS, MessageStatus, METHOD_TYPES } from "../utils/constants";
|
|
9
9
|
import { DecryptMessage, DecryptMessageParams, Message, UserRequestApprovalParams } from "../utils/interfaces";
|
|
10
10
|
import AbstractMessageController, { MessageControllerState } from "./AbstractMessageController";
|
|
11
11
|
import { normalizeMessageData, parseDecryptMessageData, validateDecryptedMessageData } from "./utils";
|
|
@@ -34,7 +34,7 @@ export class DecryptMessageController extends AbstractMessageController<DecryptM
|
|
|
34
34
|
async processDecryptMessage(messageId: string): Promise<string> {
|
|
35
35
|
try {
|
|
36
36
|
const msgObject = this.getMessage(messageId);
|
|
37
|
-
const cleanMsgParams = await this.approveMessage(msgObject.messageParams);
|
|
37
|
+
const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
|
|
38
38
|
const parsedData = parseDecryptMessageData(cleanMsgParams.data);
|
|
39
39
|
const rawSig = this.decryptMessage(parsedData, cleanMsgParams.from);
|
|
40
40
|
this.updateMessage({ ...msgObject, rawSig });
|
|
@@ -69,9 +69,7 @@ export class DecryptMessageController extends AbstractMessageController<DecryptM
|
|
|
69
69
|
type: METHOD_TYPES.ETH_DECRYPT,
|
|
70
70
|
};
|
|
71
71
|
await this.addMessage(messageData);
|
|
72
|
-
this.emit(
|
|
73
|
-
...messageParams,
|
|
74
|
-
});
|
|
72
|
+
this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, messageData);
|
|
75
73
|
return messageId;
|
|
76
74
|
}
|
|
77
75
|
|
|
@@ -5,7 +5,7 @@ import log from "loglevel";
|
|
|
5
5
|
|
|
6
6
|
import KeyringController from "../Keyring/KeyringController";
|
|
7
7
|
import NetworkController from "../Network/NetworkController";
|
|
8
|
-
import { MessageStatus, METHOD_TYPES } from "../utils/constants";
|
|
8
|
+
import { MESSAGE_EVENTS, MessageStatus, METHOD_TYPES } from "../utils/constants";
|
|
9
9
|
import { EncryptionPublicKey, EncryptionPublicKeyParams, UserRequestApprovalParams } from "../utils/interfaces";
|
|
10
10
|
import AbstractMessageController, { MessageControllerState } from "./AbstractMessageController";
|
|
11
11
|
import { validateEncryptionPublicKeyMessageData } from "./utils";
|
|
@@ -34,7 +34,7 @@ export class EncryptionPublicKeyController extends AbstractMessageController<Enc
|
|
|
34
34
|
async processGetEncryptionPublicKey(messageId: string): Promise<string> {
|
|
35
35
|
try {
|
|
36
36
|
const msgObject = this.getMessage(messageId);
|
|
37
|
-
const cleanMsgParams = await this.approveMessage(msgObject.messageParams);
|
|
37
|
+
const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
|
|
38
38
|
const publicKey = this.signEncryptionPublicKey(cleanMsgParams.from);
|
|
39
39
|
this.updateMessage({ ...msgObject, rawSig: publicKey });
|
|
40
40
|
this.setMessageStatus(messageId, MessageStatus.SIGNED);
|
|
@@ -70,9 +70,7 @@ export class EncryptionPublicKeyController extends AbstractMessageController<Enc
|
|
|
70
70
|
type: METHOD_TYPES.ETH_GET_ENCRYPTION_PUBLIC_KEY,
|
|
71
71
|
};
|
|
72
72
|
await this.addMessage(messageData);
|
|
73
|
-
this.emit(
|
|
74
|
-
...messageParams,
|
|
75
|
-
});
|
|
73
|
+
this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, messageData);
|
|
76
74
|
return messageId;
|
|
77
75
|
}
|
|
78
76
|
|
|
@@ -4,7 +4,7 @@ import log from "loglevel";
|
|
|
4
4
|
|
|
5
5
|
import KeyringController from "../Keyring/KeyringController";
|
|
6
6
|
import NetworkController from "../Network/NetworkController";
|
|
7
|
-
import { MessageStatus, METHOD_TYPES } from "../utils/constants";
|
|
7
|
+
import { MESSAGE_EVENTS, MessageStatus, METHOD_TYPES } from "../utils/constants";
|
|
8
8
|
import { Message, MessageParams, UserRequestApprovalParams } from "../utils/interfaces";
|
|
9
9
|
import AbstractMessageController, { MessageControllerState } from "./AbstractMessageController";
|
|
10
10
|
import { normalizeMessageData, validateSignMessageData } from "./utils";
|
|
@@ -33,7 +33,7 @@ export class MessageController extends AbstractMessageController<Message, Messag
|
|
|
33
33
|
async processSignMessage(messageId: string): Promise<string> {
|
|
34
34
|
try {
|
|
35
35
|
const msgObject = this.getMessage(messageId);
|
|
36
|
-
const cleanMsgParams = await this.approveMessage(msgObject.messageParams);
|
|
36
|
+
const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
|
|
37
37
|
const rawSig = this.signMessage(cleanMsgParams.data, cleanMsgParams.from);
|
|
38
38
|
this.updateMessage({ ...msgObject, rawSig });
|
|
39
39
|
this.setMessageStatus(messageId, MessageStatus.SIGNED);
|
|
@@ -64,7 +64,7 @@ export class MessageController extends AbstractMessageController<Message, Messag
|
|
|
64
64
|
type: METHOD_TYPES.ETH_SIGN,
|
|
65
65
|
};
|
|
66
66
|
await this.addMessage(messageData);
|
|
67
|
-
this.emit(
|
|
67
|
+
this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, messageData);
|
|
68
68
|
return messageId;
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -4,7 +4,7 @@ import log from "loglevel";
|
|
|
4
4
|
|
|
5
5
|
import KeyringController from "../Keyring/KeyringController";
|
|
6
6
|
import NetworkController from "../Network/NetworkController";
|
|
7
|
-
import { MessageStatus, METHOD_TYPES } from "../utils/constants";
|
|
7
|
+
import { MESSAGE_EVENTS, MessageStatus, METHOD_TYPES } from "../utils/constants";
|
|
8
8
|
import { Message, MessageParams, UserRequestApprovalParams } from "../utils/interfaces";
|
|
9
9
|
import AbstractMessageController, { MessageControllerState } from "./AbstractMessageController";
|
|
10
10
|
import { normalizeMessageData, validateSignMessageData } from "./utils";
|
|
@@ -33,7 +33,7 @@ export class PersonalMessageController extends AbstractMessageController<Message
|
|
|
33
33
|
async processPersonalSignMessage(messageId: string): Promise<string> {
|
|
34
34
|
try {
|
|
35
35
|
const msgObject = this.getMessage(messageId);
|
|
36
|
-
const cleanMsgParams = await this.approveMessage(msgObject.messageParams);
|
|
36
|
+
const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
|
|
37
37
|
const rawSig = await this.signPersonalMessage(cleanMsgParams.data, cleanMsgParams.from);
|
|
38
38
|
this.updateMessage({ ...msgObject, rawSig });
|
|
39
39
|
this.setMessageStatus(messageId, MessageStatus.SIGNED);
|
|
@@ -55,7 +55,7 @@ export class PersonalMessageController extends AbstractMessageController<Message
|
|
|
55
55
|
messageParams.origin = req.origin;
|
|
56
56
|
}
|
|
57
57
|
messageParams.data = normalizeMessageData(messageParams.data);
|
|
58
|
-
const messageId = randomId();
|
|
58
|
+
const messageId = messageParams.id || randomId();
|
|
59
59
|
const messageData: Message = {
|
|
60
60
|
id: messageId,
|
|
61
61
|
messageParams,
|
|
@@ -64,7 +64,7 @@ export class PersonalMessageController extends AbstractMessageController<Message
|
|
|
64
64
|
type: METHOD_TYPES.PERSONAL_SIGN,
|
|
65
65
|
};
|
|
66
66
|
await this.addMessage(messageData);
|
|
67
|
-
this.emit(
|
|
67
|
+
this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, messageData);
|
|
68
68
|
return messageId;
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -5,7 +5,7 @@ import log from "loglevel";
|
|
|
5
5
|
|
|
6
6
|
import KeyringController from "../Keyring/KeyringController";
|
|
7
7
|
import NetworkController from "../Network/NetworkController";
|
|
8
|
-
import { MessageStatus, METHOD_TYPES } from "../utils/constants";
|
|
8
|
+
import { MESSAGE_EVENTS, MessageStatus, METHOD_TYPES } from "../utils/constants";
|
|
9
9
|
import { METHOD_TYPES_TYPE, TypedMessage, TypedMessageParams, UserRequestApprovalParams } from "../utils/interfaces";
|
|
10
10
|
import AbstractMessageController, { MessageControllerState } from "./AbstractMessageController";
|
|
11
11
|
import { validateTypedSignMessageDataV1, validateTypedSignMessageDataV3V4 } from "./utils";
|
|
@@ -47,7 +47,7 @@ export class TypedMessageController extends AbstractMessageController<TypedMessa
|
|
|
47
47
|
async processPersonalSignMessage(messageId: string): Promise<string> {
|
|
48
48
|
try {
|
|
49
49
|
const msgObject = this.getMessage(messageId);
|
|
50
|
-
const cleanMsgParams = await this.approveMessage(msgObject.messageParams);
|
|
50
|
+
const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
|
|
51
51
|
const rawSig = await this.signTypedData(
|
|
52
52
|
cleanMsgParams.data as TypedDataV1 | EthSigTypedMessage<MessageTypes>,
|
|
53
53
|
cleanMsgParams.from,
|
|
@@ -102,7 +102,7 @@ export class TypedMessageController extends AbstractMessageController<TypedMessa
|
|
|
102
102
|
type: getMessageType(version),
|
|
103
103
|
};
|
|
104
104
|
await this.addMessage(messageData);
|
|
105
|
-
this.emit(
|
|
105
|
+
this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, messageData);
|
|
106
106
|
return messageId;
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -4,7 +4,6 @@ import { BrowserProvider } from "ethers";
|
|
|
4
4
|
import { merge } from "lodash";
|
|
5
5
|
import log from "loglevel";
|
|
6
6
|
|
|
7
|
-
import NetworkController from "../Network/NetworkController";
|
|
8
7
|
import PreferencesController from "../Preferences/PreferencesController";
|
|
9
8
|
import { SIMPLEHASH_SUPPORTED_CHAINS } from "../utils/constants";
|
|
10
9
|
import { idleTimeTracker } from "../utils/helpers";
|
|
@@ -16,7 +15,6 @@ export interface INftsControllerOptions {
|
|
|
16
15
|
config?: Partial<NftsControllerConfig>;
|
|
17
16
|
state?: Partial<NftsControllerState>;
|
|
18
17
|
provider: SafeEventEmitterProvider;
|
|
19
|
-
getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
20
18
|
getCustomNfts?: PreferencesController["getCustomNfts"];
|
|
21
19
|
getSimpleHashNfts: PreferencesController["getSimpleHashNfts"];
|
|
22
20
|
onPreferencesStateChange: (listener: (preferencesState: PreferencesState<ExtendedAddressPreferences>) => void) => void;
|
|
@@ -34,27 +32,15 @@ export class NftsController extends BaseController<NftsControllerConfig, NftsCon
|
|
|
34
32
|
|
|
35
33
|
private _timer: number;
|
|
36
34
|
|
|
37
|
-
private getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
38
|
-
|
|
39
35
|
private getCustomNfts: PreferencesController["getCustomNfts"];
|
|
40
36
|
|
|
41
37
|
private getSimpleHashNfts: PreferencesController["getSimpleHashNfts"];
|
|
42
38
|
|
|
43
|
-
constructor({
|
|
44
|
-
config,
|
|
45
|
-
state,
|
|
46
|
-
provider,
|
|
47
|
-
getNetworkIdentifier,
|
|
48
|
-
getCustomNfts,
|
|
49
|
-
getSimpleHashNfts,
|
|
50
|
-
onPreferencesStateChange,
|
|
51
|
-
onNetworkStateChange,
|
|
52
|
-
}: INftsControllerOptions) {
|
|
39
|
+
constructor({ config, state, provider, getCustomNfts, getSimpleHashNfts, onPreferencesStateChange, onNetworkStateChange }: INftsControllerOptions) {
|
|
53
40
|
super({ config, state });
|
|
54
41
|
|
|
55
42
|
this.provider = provider;
|
|
56
43
|
this.ethersProvider = new BrowserProvider(this.provider, "any");
|
|
57
|
-
this.getNetworkIdentifier = getNetworkIdentifier;
|
|
58
44
|
|
|
59
45
|
this.getCustomNfts = getCustomNfts;
|
|
60
46
|
this.getSimpleHashNfts = getSimpleHashNfts;
|
|
@@ -133,7 +119,7 @@ export class NftsController extends BaseController<NftsControllerConfig, NftsCon
|
|
|
133
119
|
public detectNewNfts() {
|
|
134
120
|
const userAddress = this.userSelectedAddress;
|
|
135
121
|
if (!userAddress) return;
|
|
136
|
-
const currentChainId = this.
|
|
122
|
+
const currentChainId = this.config.chainId;
|
|
137
123
|
const nftsToDetect: CustomNftInfo[] = []; // object[]
|
|
138
124
|
if (!currentChainId) {
|
|
139
125
|
this.update({ nfts: { [userAddress]: [...nftsToDetect] } });
|
|
@@ -186,7 +172,7 @@ export class NftsController extends BaseController<NftsControllerConfig, NftsCon
|
|
|
186
172
|
const oldNfts = [...this.userNfts];
|
|
187
173
|
const nonZeroNfts: CustomNftInfo[] = [];
|
|
188
174
|
try {
|
|
189
|
-
const currentChainId = this.
|
|
175
|
+
const currentChainId = this.config.chainId;
|
|
190
176
|
if (SIMPLEHASH_SUPPORTED_CHAINS.includes(currentChainId)) {
|
|
191
177
|
const simpleHashBalances = await this.getSimpleHashNfts(userAddress, currentChainId);
|
|
192
178
|
nonZeroNfts.push(...simpleHashBalances);
|
|
@@ -89,9 +89,10 @@ export default class PreferencesController
|
|
|
89
89
|
userInfo?: UserInfo;
|
|
90
90
|
rehydrate?: boolean;
|
|
91
91
|
locale?: string;
|
|
92
|
+
type?: string;
|
|
92
93
|
}): Promise<void> {
|
|
93
|
-
const { address, jwtToken, calledFromEmbed, userInfo, rehydrate, locale = "en-US" } = params;
|
|
94
|
-
await super.init(address, userInfo, jwtToken);
|
|
94
|
+
const { address, jwtToken, calledFromEmbed, userInfo, rehydrate, locale = "en-US", type } = params;
|
|
95
|
+
await super.init(address, userInfo, jwtToken, { type, email: userInfo.email });
|
|
95
96
|
const { aggregateVerifier, verifier, verifierId } = userInfo || {};
|
|
96
97
|
const userExists = await this.sync(address);
|
|
97
98
|
if (!userExists) {
|
|
@@ -218,6 +219,18 @@ export default class PreferencesController
|
|
|
218
219
|
}
|
|
219
220
|
}
|
|
220
221
|
|
|
222
|
+
async fetchEtherscanTx<T>(parameters: { selectedAddress: string; selectedNetwork: string }): Promise<T[]> {
|
|
223
|
+
try {
|
|
224
|
+
const url = new URL(`${this.config.api}/etherscan`);
|
|
225
|
+
Object.keys(parameters).forEach((key) => url.searchParams.append(key, parameters[key as keyof typeof parameters]));
|
|
226
|
+
const response = await get<{ success: boolean; data: T[] }>(url.href, this.headers(parameters.selectedAddress));
|
|
227
|
+
return response.success ? response.data : [];
|
|
228
|
+
} catch (error) {
|
|
229
|
+
log.error("unable to fetch etherscan tx", error);
|
|
230
|
+
return [];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
221
234
|
public async getEtherScanTokens(address: string, chainId: string): Promise<CustomTokenInfo[]> {
|
|
222
235
|
const selectedAddress = address;
|
|
223
236
|
const apiUrl = new URL(this.config.api);
|
|
@@ -258,7 +271,7 @@ export default class PreferencesController
|
|
|
258
271
|
chain_id: network.chainId,
|
|
259
272
|
symbol: network.ticker,
|
|
260
273
|
block_explorer_url: network.blockExplorerUrl || undefined,
|
|
261
|
-
is_test_net: network.
|
|
274
|
+
is_test_net: network.isTestnet || false,
|
|
262
275
|
};
|
|
263
276
|
const res = await post<{ data: CustomNetworks }>(apiUrl.href, payload, this.headers(selectedAddress), { useAPIKey: true });
|
|
264
277
|
await this.sync(selectedAddress);
|
|
@@ -296,7 +309,7 @@ export default class PreferencesController
|
|
|
296
309
|
chain_id: network.chainId,
|
|
297
310
|
symbol: network.ticker || undefined,
|
|
298
311
|
block_explorer_url: network.blockExplorerUrl || undefined,
|
|
299
|
-
is_test_net: network.
|
|
312
|
+
is_test_net: network.isTestnet || false,
|
|
300
313
|
};
|
|
301
314
|
await patch(apiUrl.href, payload, this.headers(selectedAddress), { useAPIKey: true });
|
|
302
315
|
await this.sync(selectedAddress);
|
|
@@ -17,7 +17,6 @@ export interface ITokensControllerOptions {
|
|
|
17
17
|
config?: Partial<TokensControllerConfig>;
|
|
18
18
|
state?: Partial<TokensControllerState>;
|
|
19
19
|
provider: SafeEventEmitterProvider;
|
|
20
|
-
getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
21
20
|
getCustomTokens?: PreferencesController["getCustomTokens"];
|
|
22
21
|
getEtherScanTokens: PreferencesController["getEtherScanTokens"];
|
|
23
22
|
getProviderConfig: NetworkController["getProviderConfig"];
|
|
@@ -55,8 +54,6 @@ export class TokensController extends BaseController<TokensControllerConfig, Tok
|
|
|
55
54
|
|
|
56
55
|
private _timer: number;
|
|
57
56
|
|
|
58
|
-
private getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
59
|
-
|
|
60
57
|
private getProviderConfig: NetworkController["getProviderConfig"];
|
|
61
58
|
|
|
62
59
|
private getCustomTokens: PreferencesController["getCustomTokens"];
|
|
@@ -67,7 +64,6 @@ export class TokensController extends BaseController<TokensControllerConfig, Tok
|
|
|
67
64
|
config,
|
|
68
65
|
state,
|
|
69
66
|
provider,
|
|
70
|
-
getNetworkIdentifier,
|
|
71
67
|
getCustomTokens,
|
|
72
68
|
getEtherScanTokens,
|
|
73
69
|
getProviderConfig,
|
|
@@ -78,7 +74,6 @@ export class TokensController extends BaseController<TokensControllerConfig, Tok
|
|
|
78
74
|
|
|
79
75
|
this.provider = provider;
|
|
80
76
|
this.ethersProvider = new BrowserProvider(this.provider, "any");
|
|
81
|
-
this.getNetworkIdentifier = getNetworkIdentifier;
|
|
82
77
|
|
|
83
78
|
this.getCustomTokens = getCustomTokens;
|
|
84
79
|
this.getEtherScanTokens = getEtherScanTokens;
|
|
@@ -159,7 +154,7 @@ export class TokensController extends BaseController<TokensControllerConfig, Tok
|
|
|
159
154
|
public detectNewTokens() {
|
|
160
155
|
const userAddress = this.userSelectedAddress;
|
|
161
156
|
if (!userAddress) return;
|
|
162
|
-
const currentChainId = this.
|
|
157
|
+
const currentChainId = this.config.chainId;
|
|
163
158
|
const tokens: CustomTokenInfo[] = []; // object[]
|
|
164
159
|
if (!currentChainId) {
|
|
165
160
|
this.update({ tokens: { [userAddress]: [...tokens] } });
|
|
@@ -209,7 +204,7 @@ export class TokensController extends BaseController<TokensControllerConfig, Tok
|
|
|
209
204
|
const tokenAddresses = oldTokens.map((x) => x.tokenAddress);
|
|
210
205
|
const nonZeroTokens: CustomTokenInfo[] = [];
|
|
211
206
|
try {
|
|
212
|
-
const currentChainId = this.
|
|
207
|
+
const currentChainId = this.config.chainId;
|
|
213
208
|
if (ETHERSCAN_SUPPORTED_CHAINS.includes(currentChainId)) {
|
|
214
209
|
const etherscanBalances = await this.getEtherScanTokens(userAddress, currentChainId);
|
|
215
210
|
nonZeroTokens.push(...etherscanBalances);
|
package/src/utils/constants.ts
CHANGED
|
@@ -110,7 +110,7 @@ export const SUPPORTED_NETWORKS: Record<string, EthereumProviderConfig> = {
|
|
|
110
110
|
rpcTarget: `https://goerli.infura.io/v3/${process.env.VITE_APP_INFURA_PROJECT_KEY}`,
|
|
111
111
|
ticker: "ETH",
|
|
112
112
|
tickerName: "Ethereum",
|
|
113
|
-
|
|
113
|
+
isTestnet: true,
|
|
114
114
|
},
|
|
115
115
|
[SEPOLIA_CHAIN_ID]: {
|
|
116
116
|
blockExplorerUrl: "https://sepolia.etherscan.io",
|
|
@@ -120,7 +120,7 @@ export const SUPPORTED_NETWORKS: Record<string, EthereumProviderConfig> = {
|
|
|
120
120
|
rpcTarget: `https://sepolia.infura.io/v3/${process.env.VITE_APP_INFURA_PROJECT_KEY}`,
|
|
121
121
|
ticker: "ETH",
|
|
122
122
|
tickerName: "Ethereum",
|
|
123
|
-
|
|
123
|
+
isTestnet: true,
|
|
124
124
|
},
|
|
125
125
|
[POLYGON_MUMBAI_CHAIN_ID]: {
|
|
126
126
|
blockExplorerUrl: "https://mumbai.polygonscan.com",
|
|
@@ -130,7 +130,7 @@ export const SUPPORTED_NETWORKS: Record<string, EthereumProviderConfig> = {
|
|
|
130
130
|
rpcTarget: `https://polygon-mumbai.infura.io/v3/${process.env.VITE_APP_INFURA_PROJECT_KEY}`,
|
|
131
131
|
ticker: "MATIC",
|
|
132
132
|
tickerName: "Matic Network Token",
|
|
133
|
-
|
|
133
|
+
isTestnet: true,
|
|
134
134
|
},
|
|
135
135
|
[BSC_TESTNET_CHAIN_ID]: {
|
|
136
136
|
blockExplorerUrl: "https://testnet.bscscan.com",
|
|
@@ -140,7 +140,7 @@ export const SUPPORTED_NETWORKS: Record<string, EthereumProviderConfig> = {
|
|
|
140
140
|
rpcTarget: `https://data-seed-prebsc-1-s1.binance.org:8545`,
|
|
141
141
|
ticker: "BNB",
|
|
142
142
|
tickerName: "Binance Coin",
|
|
143
|
-
|
|
143
|
+
isTestnet: true,
|
|
144
144
|
},
|
|
145
145
|
[AVALANCHE_TESTNET_CHAIN_ID]: {
|
|
146
146
|
blockExplorerUrl: "https://testnet.snowtrace.io",
|
|
@@ -150,7 +150,7 @@ export const SUPPORTED_NETWORKS: Record<string, EthereumProviderConfig> = {
|
|
|
150
150
|
rpcTarget: `https://api.avax-test.network/ext/bc/C/rpc`,
|
|
151
151
|
ticker: "AVAX",
|
|
152
152
|
tickerName: "Avalanche",
|
|
153
|
-
|
|
153
|
+
isTestnet: true,
|
|
154
154
|
},
|
|
155
155
|
[ARBITRUM_TESTNET_CHAIN_ID]: {
|
|
156
156
|
blockExplorerUrl: "https://testnet.arbiscan.io",
|
|
@@ -160,7 +160,7 @@ export const SUPPORTED_NETWORKS: Record<string, EthereumProviderConfig> = {
|
|
|
160
160
|
rpcTarget: `https://arbitrum-rinkeby.infura.io/v3/${process.env.VITE_APP_INFURA_PROJECT_KEY}`,
|
|
161
161
|
ticker: "ETH",
|
|
162
162
|
tickerName: "Ethereum",
|
|
163
|
-
|
|
163
|
+
isTestnet: true,
|
|
164
164
|
},
|
|
165
165
|
[OPTIMISM_TESTNET_CHAIN_ID]: {
|
|
166
166
|
blockExplorerUrl: "https://goerli-optimism.etherscan.io",
|
|
@@ -170,7 +170,7 @@ export const SUPPORTED_NETWORKS: Record<string, EthereumProviderConfig> = {
|
|
|
170
170
|
rpcTarget: `https://optimism-goerli.infura.io/v3/${process.env.VITE_APP_INFURA_PROJECT_KEY}`,
|
|
171
171
|
ticker: "ETH",
|
|
172
172
|
tickerName: "Ethereum",
|
|
173
|
-
|
|
173
|
+
isTestnet: true,
|
|
174
174
|
},
|
|
175
175
|
};
|
|
176
176
|
|
|
@@ -377,3 +377,7 @@ export const MessageStatus = {
|
|
|
377
377
|
REJECTED: "rejected",
|
|
378
378
|
FAILED: "failed",
|
|
379
379
|
} as const;
|
|
380
|
+
|
|
381
|
+
export const MESSAGE_EVENTS = {
|
|
382
|
+
UNAPPROVED_MESSAGE: "unapprovedMessage",
|
|
383
|
+
};
|
package/src/utils/interfaces.ts
CHANGED
|
@@ -277,7 +277,6 @@ export type PollingBlockTrackerState = BaseBlockTrackerState<EthereumBlock>;
|
|
|
277
277
|
export interface EthereumProviderConfig extends ProviderConfig {
|
|
278
278
|
isErc20?: boolean;
|
|
279
279
|
tokenAddress?: string;
|
|
280
|
-
isTestNet?: boolean;
|
|
281
280
|
// infuraKey?: string;
|
|
282
281
|
}
|
|
283
282
|
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
declare class AbiDecoder {
|
|
2
|
-
state: {
|
|
3
|
-
savedABIs: any[];
|
|
4
|
-
methodIDs: Record<string, any>;
|
|
5
|
-
};
|
|
6
|
-
constructor(abi: any);
|
|
7
|
-
getABIs(): any[];
|
|
8
|
-
addABI(abiArray: any): void;
|
|
9
|
-
removeABI(abiArray: any): void;
|
|
10
|
-
getMethodIDs(): Record<string, any>;
|
|
11
|
-
decodeMethod(data: any): {
|
|
12
|
-
name: any;
|
|
13
|
-
params: any[];
|
|
14
|
-
};
|
|
15
|
-
decodeLogs(logs: any): any;
|
|
16
|
-
}
|
|
17
|
-
export default AbiDecoder;
|