@toruslabs/ethereum-controllers 4.10.1 → 5.0.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.
@@ -1031,14 +1031,6 @@ class AccountTrackerController extends base_controllers_namespaceObject.BaseCont
1031
1031
  this.provider = provider;
1032
1032
  this.blockTracker = blockTracker;
1033
1033
  this.ethersProvider = new external_ethers_namespaceObject.BrowserProvider(this.provider, "any");
1034
-
1035
- // Initiate block tracker internal tracking.
1036
- this.blockTracker.on("latest", block => {
1037
- this.configure({
1038
- _currentBlock: block
1039
- });
1040
- this.refresh();
1041
- });
1042
1034
  this.getIdentities = getIdentities;
1043
1035
  this.getCurrentChainId = getCurrentChainId;
1044
1036
  onPreferencesStateChange(() => {
@@ -1046,6 +1038,24 @@ class AccountTrackerController extends base_controllers_namespaceObject.BaseCont
1046
1038
  const refreshNeeded = this.syncAccounts();
1047
1039
  if (refreshNeeded) this.refresh();
1048
1040
  });
1041
+ this.blockTrackerListener = this.blockTrackerListener.bind(this);
1042
+ }
1043
+ blockTrackerListener(block) {
1044
+ this.configure({
1045
+ _currentBlock: block
1046
+ });
1047
+ this.refresh();
1048
+ }
1049
+ startPolling() {
1050
+ this.stopPolling();
1051
+ // Initiate block tracker internal tracking.
1052
+ if (Object.keys(this.state.accounts).length > 0) {
1053
+ // Adding this listener on block tracker triggers it to start polling.
1054
+ this.blockTracker.on("latest", this.blockTrackerListener);
1055
+ }
1056
+ }
1057
+ stopPolling() {
1058
+ this.blockTracker.removeListener("latest", this.blockTrackerListener);
1049
1059
  }
1050
1060
  syncAccounts() {
1051
1061
  const {
@@ -4023,7 +4033,6 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4023
4033
  config,
4024
4034
  state,
4025
4035
  provider,
4026
- blockTracker,
4027
4036
  signAuthMessage,
4028
4037
  getProviderConfig,
4029
4038
  setProviderConfig
@@ -4043,12 +4052,9 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4043
4052
  defineProperty_default()(this, "getProviderConfig", void 0);
4044
4053
  defineProperty_default()(this, "setProviderConfig", void 0);
4045
4054
  defineProperty_default()(this, "provider", void 0);
4046
- defineProperty_default()(this, "blockTracker", void 0);
4047
4055
  this.provider = provider;
4048
4056
  this.getProviderConfig = getProviderConfig;
4049
4057
  this.setProviderConfig = setProviderConfig;
4050
- this.blockTracker = blockTracker;
4051
- external_loglevel_default().info(this.blockTracker);
4052
4058
  }
4053
4059
  async poll(interval) {
4054
4060
  var _this$getAddressState;
@@ -4078,13 +4084,18 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4078
4084
  locale = "en-US",
4079
4085
  type,
4080
4086
  signatures,
4081
- network
4087
+ web3AuthClientId,
4088
+ web3AuthNetwork
4082
4089
  } = params;
4083
- await super.init(address, userInfo, jwtToken, {
4090
+ await super.init({
4091
+ address,
4092
+ userInfo,
4093
+ idToken: jwtToken,
4084
4094
  type,
4085
- email: userInfo.email,
4086
- signatures,
4087
- network
4095
+ metadata: {
4096
+ email: userInfo.email,
4097
+ signatures
4098
+ }
4088
4099
  });
4089
4100
  const {
4090
4101
  aggregateVerifier,
@@ -4100,17 +4111,21 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4100
4111
  verifier: aggregateVerifier || verifier,
4101
4112
  verifierId,
4102
4113
  locale,
4103
- address
4114
+ address,
4115
+ type,
4116
+ web3AuthNetwork
4104
4117
  });
4105
4118
  }
4106
- if (!rehydrate) await this.storeUserLogin({
4119
+ await this.storeUserLogin({
4107
4120
  verifier: aggregateVerifier || verifier,
4108
4121
  verifierId,
4109
4122
  options: {
4110
4123
  calledFromEmbed,
4111
4124
  rehydrate
4112
4125
  },
4113
- address
4126
+ address,
4127
+ web3AuthClientId,
4128
+ web3AuthNetwork
4114
4129
  });
4115
4130
  }
4116
4131
  getSelectedAddress() {
@@ -4129,7 +4144,8 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4129
4144
  default_public_address: defaultPublicAddress,
4130
4145
  customNetworks,
4131
4146
  customTokens,
4132
- customNfts
4147
+ customNfts,
4148
+ account_type: accountType
4133
4149
  } = user || {};
4134
4150
 
4135
4151
  // update latest data in state.
@@ -4141,7 +4157,8 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4141
4157
  defaultPublicAddress: defaultPublicAddress || userPublicAddress,
4142
4158
  customTokens,
4143
4159
  customNfts,
4144
- customNetworks
4160
+ customNetworks,
4161
+ accountType: accountType
4145
4162
  }, address);
4146
4163
  return true;
4147
4164
  }
@@ -4152,13 +4169,8 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4152
4169
  } finally {
4153
4170
  Promise.all([this.getWalletOrders(address).catch(error => {
4154
4171
  external_loglevel_default().error("unable to fetch wallet orders", error);
4155
- }), this.getTopUpOrders(address).catch(error => {
4156
- external_loglevel_default().error("unable to fetch top up orders", error);
4157
4172
  })]).then(data => {
4158
- const [walletTx, paymentTx] = data;
4159
- if (paymentTx) {
4160
- this.calculatePaymentTx(paymentTx, address);
4161
- }
4173
+ const [walletTx] = data;
4162
4174
  // eslint-disable-next-line promise/always-return
4163
4175
  if (walletTx && walletTx.length > 0) {
4164
4176
  this.updateState({
@@ -4207,17 +4219,20 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4207
4219
  var _this$getAddressState3;
4208
4220
  const selectedAddress = address || this.state.selectedAddress;
4209
4221
  if ((_this$getAddressState3 = this.getAddressState(selectedAddress)) !== null && _this$getAddressState3 !== void 0 && _this$getAddressState3.jwtToken) {
4210
- // const selectedNetwork = this.getProviderConfig().rpcTarget;
4211
- // if (ETHERSCAN_SUPPORTED_NETWORKS.has(selectedNetwork)) {
4212
- // const data = await this.fetchEtherscanTx({ selectedAddress, selectedNetwork });
4213
- // if (data.length) {
4214
- // this.emit("addEtherscanTransactions", data, selectedNetwork);
4215
- // }
4216
- // }
4222
+ const {
4223
+ chainId
4224
+ } = this.getProviderConfig();
4225
+ if (ETHERSCAN_SUPPORTED_CHAINS.includes(chainId)) {
4226
+ return this.fetchEtherscanTx({
4227
+ selectedAddress,
4228
+ chainId: this.getProviderConfig().chainId
4229
+ });
4230
+ }
4217
4231
  }
4218
4232
  }
4219
4233
  async fetchEtherscanTx(parameters) {
4220
4234
  try {
4235
+ // TODO: rewrite this api to use chainId
4221
4236
  const url = new URL(`${this.config.api}/etherscan`);
4222
4237
  Object.keys(parameters).forEach(key => url.searchParams.append(key, parameters[key]));
4223
4238
  const response = await (0,http_helpers_namespaceObject.get)(url.href, this.headers(parameters.selectedAddress));
@@ -4363,36 +4378,6 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4363
4378
  return false;
4364
4379
  }
4365
4380
  }
4366
- calculatePaymentTx(txs, address) {
4367
- const accumulator = [];
4368
- for (const x of txs) {
4369
- let action = "";
4370
- const lowerCaseAction = x.action.toLowerCase();
4371
- if (base_controllers_namespaceObject.ACTIVITY_ACTION_TOPUP.includes(lowerCaseAction)) action = base_controllers_namespaceObject.ACTIVITY_ACTION_TOPUP;else if (base_controllers_namespaceObject.ACTIVITY_ACTION_SEND.includes(lowerCaseAction)) action = base_controllers_namespaceObject.ACTIVITY_ACTION_SEND;else if (base_controllers_namespaceObject.ACTIVITY_ACTION_RECEIVE.includes(lowerCaseAction)) action = base_controllers_namespaceObject.ACTIVITY_ACTION_RECEIVE;
4372
- accumulator.push({
4373
- id: x.id,
4374
- date: new Date(x.date).toDateString(),
4375
- from: x.from,
4376
- slicedFrom: x.slicedFrom,
4377
- action,
4378
- to: x.to,
4379
- slicedTo: x.slicedTo,
4380
- totalAmount: x.totalAmount,
4381
- totalAmountString: x.totalAmountString,
4382
- currencyAmount: x.currencyAmount,
4383
- currencyAmountString: x.currencyAmountString,
4384
- amount: x.amount,
4385
- ethRate: x.ethRate,
4386
- status: x.status.toLowerCase(),
4387
- etherscanLink: x.etherscanLink || "",
4388
- blockExplorerLink: "",
4389
- currencyUsed: x.currencyUsed
4390
- });
4391
- }
4392
- this.updateState({
4393
- paymentTx: accumulator
4394
- }, address);
4395
- }
4396
4381
  getChainOptions() {
4397
4382
  var _identities$address$c, _identities$address;
4398
4383
  let address = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.state.selectedAddress;