@toruslabs/ethereum-controllers 5.6.0 → 5.6.2

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.
@@ -1930,7 +1930,6 @@ class CurrencyController extends base_controllers_namespaceObject.BaseCurrencyCo
1930
1930
  }
1931
1931
  async retrieveConversionRate(fromCurrency, toCurrency, commonDenomination) {
1932
1932
  try {
1933
- // query cryptocompare
1934
1933
  let apiUrl = `${this.config.api}/currency?fsym=${fromCurrency.toUpperCase()}&tsyms=${toCurrency.toUpperCase()}`;
1935
1934
  if (commonDenomination && commonDenomination.toUpperCase() !== toCurrency.toUpperCase()) {
1936
1935
  apiUrl += `,${commonDenomination.toUpperCase()}`;
@@ -2939,8 +2938,8 @@ class AddChainController extends AbstractMessageController {
2939
2938
  this.initialize();
2940
2939
  }
2941
2940
  async processAddChain(messageId) {
2941
+ const msgObject = this.getMessage(messageId);
2942
2942
  try {
2943
- const msgObject = this.getMessage(messageId);
2944
2943
  await this.approveMessage(messageId, msgObject.messageParams);
2945
2944
  await this.addChain(msgObject.messageParams);
2946
2945
  this.updateMessage(objectSpread2_default()(objectSpread2_default()({}, msgObject), {}, {
@@ -2950,6 +2949,7 @@ class AddChainController extends AbstractMessageController {
2950
2949
  return null;
2951
2950
  } catch (error) {
2952
2951
  external_loglevel_default().error(error);
2952
+ msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
2953
2953
  this.setMessageStatus(messageId, MessageStatus.FAILED);
2954
2954
  }
2955
2955
  }
@@ -3009,8 +3009,8 @@ class DecryptMessageController extends AbstractMessageController {
3009
3009
  this.initialize();
3010
3010
  }
3011
3011
  async processDecryptMessage(messageId) {
3012
+ const msgObject = this.getMessage(messageId);
3012
3013
  try {
3013
- const msgObject = this.getMessage(messageId);
3014
3014
  const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
3015
3015
  const parsedData = parseDecryptMessageData(cleanMsgParams.data);
3016
3016
  const rawSig = this.decryptMessage(parsedData, cleanMsgParams.from);
@@ -3021,6 +3021,7 @@ class DecryptMessageController extends AbstractMessageController {
3021
3021
  return rawSig;
3022
3022
  } catch (error) {
3023
3023
  external_loglevel_default().error(error);
3024
+ msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
3024
3025
  this.setMessageStatus(messageId, MessageStatus.FAILED);
3025
3026
  }
3026
3027
  }
@@ -3081,8 +3082,8 @@ class EncryptionPublicKeyController extends AbstractMessageController {
3081
3082
  this.initialize();
3082
3083
  }
3083
3084
  async processGetEncryptionPublicKey(messageId) {
3085
+ const msgObject = this.getMessage(messageId);
3084
3086
  try {
3085
- const msgObject = this.getMessage(messageId);
3086
3087
  const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
3087
3088
  const publicKey = this.signEncryptionPublicKey(cleanMsgParams.from);
3088
3089
  this.updateMessage(objectSpread2_default()(objectSpread2_default()({}, msgObject), {}, {
@@ -3092,6 +3093,7 @@ class EncryptionPublicKeyController extends AbstractMessageController {
3092
3093
  return publicKey;
3093
3094
  } catch (error) {
3094
3095
  external_loglevel_default().error(error);
3096
+ msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
3095
3097
  this.setMessageStatus(messageId, MessageStatus.FAILED);
3096
3098
  }
3097
3099
  }
@@ -3153,8 +3155,8 @@ class MessageController extends AbstractMessageController {
3153
3155
  this.initialize();
3154
3156
  }
3155
3157
  async processSignMessage(messageId) {
3158
+ const msgObject = this.getMessage(messageId);
3156
3159
  try {
3157
- const msgObject = this.getMessage(messageId);
3158
3160
  const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
3159
3161
  const rawSig = await this.signMessage(cleanMsgParams.data, cleanMsgParams.from);
3160
3162
  this.updateMessage(objectSpread2_default()(objectSpread2_default()({}, msgObject), {}, {
@@ -3164,6 +3166,7 @@ class MessageController extends AbstractMessageController {
3164
3166
  return rawSig;
3165
3167
  } catch (error) {
3166
3168
  external_loglevel_default().error(error);
3169
+ msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
3167
3170
  this.setMessageStatus(messageId, MessageStatus.FAILED);
3168
3171
  }
3169
3172
  }
@@ -3223,8 +3226,8 @@ class PersonalMessageController extends AbstractMessageController {
3223
3226
  this.initialize();
3224
3227
  }
3225
3228
  async processSignPersonalMessage(messageId) {
3229
+ const msgObject = this.getMessage(messageId);
3226
3230
  try {
3227
- const msgObject = this.getMessage(messageId);
3228
3231
  const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
3229
3232
  const rawSig = await this.signPersonalMessage(cleanMsgParams.data, cleanMsgParams.from);
3230
3233
  this.updateMessage(objectSpread2_default()(objectSpread2_default()({}, msgObject), {}, {
@@ -3234,6 +3237,7 @@ class PersonalMessageController extends AbstractMessageController {
3234
3237
  return rawSig;
3235
3238
  } catch (error) {
3236
3239
  external_loglevel_default().error(error);
3240
+ msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
3237
3241
  this.setMessageStatus(messageId, MessageStatus.FAILED);
3238
3242
  }
3239
3243
  }
@@ -3293,8 +3297,8 @@ class SwitchChainController extends AbstractMessageController {
3293
3297
  this.initialize();
3294
3298
  }
3295
3299
  async processSwitchChain(messageId) {
3300
+ const msgObject = this.getMessage(messageId);
3296
3301
  try {
3297
- const msgObject = this.getMessage(messageId);
3298
3302
  await this.approveMessage(messageId, msgObject.messageParams);
3299
3303
  this.switchChain({
3300
3304
  chainId: msgObject.messageParams.chainId
@@ -3306,6 +3310,7 @@ class SwitchChainController extends AbstractMessageController {
3306
3310
  return null;
3307
3311
  } catch (error) {
3308
3312
  external_loglevel_default().error(error);
3313
+ msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
3309
3314
  this.setMessageStatus(messageId, MessageStatus.FAILED);
3310
3315
  }
3311
3316
  }
@@ -3377,8 +3382,8 @@ class TypedMessageController extends AbstractMessageController {
3377
3382
  this.initialize();
3378
3383
  }
3379
3384
  async processSignTypedMessage(messageId) {
3385
+ const msgObject = this.getMessage(messageId);
3380
3386
  try {
3381
- const msgObject = this.getMessage(messageId);
3382
3387
  const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
3383
3388
  const msgData = cleanMsgParams.version === eth_sig_util_namespaceObject.SignTypedDataVersion.V1 ? cleanMsgParams.data : JSON.parse(cleanMsgParams.data);
3384
3389
  const rawSig = await this.signTypedData(msgData, cleanMsgParams.from, cleanMsgParams.version);
@@ -3389,6 +3394,7 @@ class TypedMessageController extends AbstractMessageController {
3389
3394
  return rawSig;
3390
3395
  } catch (error) {
3391
3396
  external_loglevel_default().error(error);
3397
+ msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
3392
3398
  this.setMessageStatus(messageId, MessageStatus.FAILED);
3393
3399
  }
3394
3400
  }
@@ -4682,6 +4688,7 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4682
4688
  async refetchEtherscanTx(address) {
4683
4689
  var _this$getAddressState3;
4684
4690
  const selectedAddress = address || this.state.selectedAddress;
4691
+ const lowerCaseSelectedAddress = selectedAddress.toLowerCase();
4685
4692
  if ((_this$getAddressState3 = this.getAddressState(selectedAddress)) !== null && _this$getAddressState3 !== void 0 && _this$getAddressState3.jwtToken) {
4686
4693
  const {
4687
4694
  chainId
@@ -4691,7 +4698,7 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4691
4698
  selectedAddress,
4692
4699
  chainId: this.getProviderConfig().chainId
4693
4700
  });
4694
- const finalEthScanTxn = await addEtherscanTransactions(etherscanTxn, selectedAddress, this.provider, chainId);
4701
+ const finalEthScanTxn = await addEtherscanTransactions(etherscanTxn, lowerCaseSelectedAddress, this.provider, chainId);
4695
4702
  external_loglevel_default().info("Formatted Etherscan Response", finalEthScanTxn);
4696
4703
  this.updateState({
4697
4704
  etherscanTransactions: finalEthScanTxn
@@ -5083,14 +5090,14 @@ class TokenRatesController extends base_controllers_namespaceObject.BaseControll
5083
5090
  const contractAddresses = this.config.tokens.map(token => token.tokenAddress);
5084
5091
  const isNativeCurrencySupported = COINGECKO_SUPPORTED_CURRENCIES.has(nativeCurrency.toLowerCase());
5085
5092
  if (isNativeCurrencySupported) {
5086
- const response = await (0,http_helpers_namespaceObject.get)(`${this.config.api}/simple/token_price/${chainCodes.platform}?contract_addresses=${contractAddresses.join(",")}&vs_currencies=${nativeCurrency.toLowerCase()}&include_market_cap=false&include_24hr_vol=false&include_24hr_change=false&include_last_updated_at=false`);
5093
+ const response = await (0,http_helpers_namespaceObject.get)(`${this.config.currencyApi}/currency/exchange-rates?platform=${chainCodes.platform}&contract_addresses=${contractAddresses.join(",")}&vs_currencies=${nativeCurrency.toLowerCase()}`);
5087
5094
  const newContractExchangeRates = {};
5088
5095
  Object.keys(response).forEach(contractAddress => {
5089
5096
  newContractExchangeRates[contractAddress] = response[contractAddress][nativeCurrency.toLowerCase()] || 0;
5090
5097
  });
5091
5098
  return newContractExchangeRates;
5092
5099
  }
5093
- const [response, currencyResponse] = await Promise.all([(0,http_helpers_namespaceObject.get)(`${this.config.api}/simple/token_price/${chainCodes.platform}?contract_addresses=${contractAddresses.join(",")}&vs_currencies=${DEFAULT_CURRENCY}&include_market_cap=false&include_24hr_vol=false&include_24hr_change=false&include_last_updated_at=false`), (0,http_helpers_namespaceObject.get)(`${this.config.currencyApi}/currency?fsym=${nativeCurrency.toUpperCase()}&tsyms=${DEFAULT_CURRENCY.toUpperCase()}`)]);
5100
+ const [response, currencyResponse] = await Promise.all([(0,http_helpers_namespaceObject.get)(`${this.config.currencyApi}/currency/exchange-rates?platform=${chainCodes.platform}&contract_addresses=${contractAddresses.join(",")}&vs_currencies=${DEFAULT_CURRENCY}`), (0,http_helpers_namespaceObject.get)(`${this.config.currencyApi}/currency?fsym=${nativeCurrency.toUpperCase()}&tsyms=${DEFAULT_CURRENCY.toUpperCase()}`)]);
5094
5101
  const newContractExchangeRates = {};
5095
5102
  Object.keys(response).forEach(contractAddress => {
5096
5103
  newContractExchangeRates[contractAddress] = response[contractAddress][DEFAULT_CURRENCY] * Number.parseFloat(currencyResponse[DEFAULT_CURRENCY]) || 0;
@@ -1696,7 +1696,6 @@ class CurrencyController extends BaseCurrencyController {
1696
1696
  }
1697
1697
  async retrieveConversionRate(fromCurrency, toCurrency, commonDenomination) {
1698
1698
  try {
1699
- // query cryptocompare
1700
1699
  let apiUrl = `${this.config.api}/currency?fsym=${fromCurrency.toUpperCase()}&tsyms=${toCurrency.toUpperCase()}`;
1701
1700
  if (commonDenomination && commonDenomination.toUpperCase() !== toCurrency.toUpperCase()) {
1702
1701
  apiUrl += `,${commonDenomination.toUpperCase()}`;
@@ -2628,8 +2627,8 @@ class AddChainController extends AbstractMessageController {
2628
2627
  this.initialize();
2629
2628
  }
2630
2629
  async processAddChain(messageId) {
2630
+ const msgObject = this.getMessage(messageId);
2631
2631
  try {
2632
- const msgObject = this.getMessage(messageId);
2633
2632
  await this.approveMessage(messageId, msgObject.messageParams);
2634
2633
  await this.addChain(msgObject.messageParams);
2635
2634
  this.updateMessage(_objectSpread(_objectSpread({}, msgObject), {}, {
@@ -2639,6 +2638,7 @@ class AddChainController extends AbstractMessageController {
2639
2638
  return null;
2640
2639
  } catch (error) {
2641
2640
  log.error(error);
2641
+ msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
2642
2642
  this.setMessageStatus(messageId, MessageStatus.FAILED);
2643
2643
  }
2644
2644
  }
@@ -2690,8 +2690,8 @@ class DecryptMessageController extends AbstractMessageController {
2690
2690
  this.initialize();
2691
2691
  }
2692
2692
  async processDecryptMessage(messageId) {
2693
+ const msgObject = this.getMessage(messageId);
2693
2694
  try {
2694
- const msgObject = this.getMessage(messageId);
2695
2695
  const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
2696
2696
  const parsedData = parseDecryptMessageData(cleanMsgParams.data);
2697
2697
  const rawSig = this.decryptMessage(parsedData, cleanMsgParams.from);
@@ -2702,6 +2702,7 @@ class DecryptMessageController extends AbstractMessageController {
2702
2702
  return rawSig;
2703
2703
  } catch (error) {
2704
2704
  log.error(error);
2705
+ msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
2705
2706
  this.setMessageStatus(messageId, MessageStatus.FAILED);
2706
2707
  }
2707
2708
  }
@@ -2754,8 +2755,8 @@ class EncryptionPublicKeyController extends AbstractMessageController {
2754
2755
  this.initialize();
2755
2756
  }
2756
2757
  async processGetEncryptionPublicKey(messageId) {
2758
+ const msgObject = this.getMessage(messageId);
2757
2759
  try {
2758
- const msgObject = this.getMessage(messageId);
2759
2760
  const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
2760
2761
  const publicKey = this.signEncryptionPublicKey(cleanMsgParams.from);
2761
2762
  this.updateMessage(_objectSpread(_objectSpread({}, msgObject), {}, {
@@ -2765,6 +2766,7 @@ class EncryptionPublicKeyController extends AbstractMessageController {
2765
2766
  return publicKey;
2766
2767
  } catch (error) {
2767
2768
  log.error(error);
2769
+ msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
2768
2770
  this.setMessageStatus(messageId, MessageStatus.FAILED);
2769
2771
  }
2770
2772
  }
@@ -2819,8 +2821,8 @@ class MessageController extends AbstractMessageController {
2819
2821
  this.initialize();
2820
2822
  }
2821
2823
  async processSignMessage(messageId) {
2824
+ const msgObject = this.getMessage(messageId);
2822
2825
  try {
2823
- const msgObject = this.getMessage(messageId);
2824
2826
  const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
2825
2827
  const rawSig = await this.signMessage(cleanMsgParams.data, cleanMsgParams.from);
2826
2828
  this.updateMessage(_objectSpread(_objectSpread({}, msgObject), {}, {
@@ -2830,6 +2832,7 @@ class MessageController extends AbstractMessageController {
2830
2832
  return rawSig;
2831
2833
  } catch (error) {
2832
2834
  log.error(error);
2835
+ msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
2833
2836
  this.setMessageStatus(messageId, MessageStatus.FAILED);
2834
2837
  }
2835
2838
  }
@@ -2882,8 +2885,8 @@ class PersonalMessageController extends AbstractMessageController {
2882
2885
  this.initialize();
2883
2886
  }
2884
2887
  async processSignPersonalMessage(messageId) {
2888
+ const msgObject = this.getMessage(messageId);
2885
2889
  try {
2886
- const msgObject = this.getMessage(messageId);
2887
2890
  const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
2888
2891
  const rawSig = await this.signPersonalMessage(cleanMsgParams.data, cleanMsgParams.from);
2889
2892
  this.updateMessage(_objectSpread(_objectSpread({}, msgObject), {}, {
@@ -2893,6 +2896,7 @@ class PersonalMessageController extends AbstractMessageController {
2893
2896
  return rawSig;
2894
2897
  } catch (error) {
2895
2898
  log.error(error);
2899
+ msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
2896
2900
  this.setMessageStatus(messageId, MessageStatus.FAILED);
2897
2901
  }
2898
2902
  }
@@ -2945,8 +2949,8 @@ class SwitchChainController extends AbstractMessageController {
2945
2949
  this.initialize();
2946
2950
  }
2947
2951
  async processSwitchChain(messageId) {
2952
+ const msgObject = this.getMessage(messageId);
2948
2953
  try {
2949
- const msgObject = this.getMessage(messageId);
2950
2954
  await this.approveMessage(messageId, msgObject.messageParams);
2951
2955
  this.switchChain({
2952
2956
  chainId: msgObject.messageParams.chainId
@@ -2958,6 +2962,7 @@ class SwitchChainController extends AbstractMessageController {
2958
2962
  return null;
2959
2963
  } catch (error) {
2960
2964
  log.error(error);
2965
+ msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
2961
2966
  this.setMessageStatus(messageId, MessageStatus.FAILED);
2962
2967
  }
2963
2968
  }
@@ -3021,8 +3026,8 @@ class TypedMessageController extends AbstractMessageController {
3021
3026
  this.initialize();
3022
3027
  }
3023
3028
  async processSignTypedMessage(messageId) {
3029
+ const msgObject = this.getMessage(messageId);
3024
3030
  try {
3025
- const msgObject = this.getMessage(messageId);
3026
3031
  const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
3027
3032
  const msgData = cleanMsgParams.version === SignTypedDataVersion.V1 ? cleanMsgParams.data : JSON.parse(cleanMsgParams.data);
3028
3033
  const rawSig = await this.signTypedData(msgData, cleanMsgParams.from, cleanMsgParams.version);
@@ -3033,6 +3038,7 @@ class TypedMessageController extends AbstractMessageController {
3033
3038
  return rawSig;
3034
3039
  } catch (error) {
3035
3040
  log.error(error);
3041
+ msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
3036
3042
  this.setMessageStatus(messageId, MessageStatus.FAILED);
3037
3043
  }
3038
3044
  }
@@ -4281,6 +4287,7 @@ class PreferencesController extends BasePreferencesController {
4281
4287
  async refetchEtherscanTx(address) {
4282
4288
  var _this$getAddressState3;
4283
4289
  const selectedAddress = address || this.state.selectedAddress;
4290
+ const lowerCaseSelectedAddress = selectedAddress.toLowerCase();
4284
4291
  if ((_this$getAddressState3 = this.getAddressState(selectedAddress)) !== null && _this$getAddressState3 !== void 0 && _this$getAddressState3.jwtToken) {
4285
4292
  const {
4286
4293
  chainId
@@ -4290,7 +4297,7 @@ class PreferencesController extends BasePreferencesController {
4290
4297
  selectedAddress,
4291
4298
  chainId: this.getProviderConfig().chainId
4292
4299
  });
4293
- const finalEthScanTxn = await addEtherscanTransactions(etherscanTxn, selectedAddress, this.provider, chainId);
4300
+ const finalEthScanTxn = await addEtherscanTransactions(etherscanTxn, lowerCaseSelectedAddress, this.provider, chainId);
4294
4301
  log.info("Formatted Etherscan Response", finalEthScanTxn);
4295
4302
  this.updateState({
4296
4303
  etherscanTransactions: finalEthScanTxn
@@ -4670,14 +4677,14 @@ class TokenRatesController extends BaseController {
4670
4677
  const contractAddresses = this.config.tokens.map(token => token.tokenAddress);
4671
4678
  const isNativeCurrencySupported = COINGECKO_SUPPORTED_CURRENCIES.has(nativeCurrency.toLowerCase());
4672
4679
  if (isNativeCurrencySupported) {
4673
- const response = await get(`${this.config.api}/simple/token_price/${chainCodes.platform}?contract_addresses=${contractAddresses.join(",")}&vs_currencies=${nativeCurrency.toLowerCase()}&include_market_cap=false&include_24hr_vol=false&include_24hr_change=false&include_last_updated_at=false`);
4680
+ const response = await get(`${this.config.currencyApi}/currency/exchange-rates?platform=${chainCodes.platform}&contract_addresses=${contractAddresses.join(",")}&vs_currencies=${nativeCurrency.toLowerCase()}`);
4674
4681
  const newContractExchangeRates = {};
4675
4682
  Object.keys(response).forEach(contractAddress => {
4676
4683
  newContractExchangeRates[contractAddress] = response[contractAddress][nativeCurrency.toLowerCase()] || 0;
4677
4684
  });
4678
4685
  return newContractExchangeRates;
4679
4686
  }
4680
- const [response, currencyResponse] = await Promise.all([get(`${this.config.api}/simple/token_price/${chainCodes.platform}?contract_addresses=${contractAddresses.join(",")}&vs_currencies=${DEFAULT_CURRENCY}&include_market_cap=false&include_24hr_vol=false&include_24hr_change=false&include_last_updated_at=false`), get(`${this.config.currencyApi}/currency?fsym=${nativeCurrency.toUpperCase()}&tsyms=${DEFAULT_CURRENCY.toUpperCase()}`)]);
4687
+ const [response, currencyResponse] = await Promise.all([get(`${this.config.currencyApi}/currency/exchange-rates?platform=${chainCodes.platform}&contract_addresses=${contractAddresses.join(",")}&vs_currencies=${DEFAULT_CURRENCY}`), get(`${this.config.currencyApi}/currency?fsym=${nativeCurrency.toUpperCase()}&tsyms=${DEFAULT_CURRENCY.toUpperCase()}`)]);
4681
4688
  const newContractExchangeRates = {};
4682
4689
  Object.keys(response).forEach(contractAddress => {
4683
4690
  newContractExchangeRates[contractAddress] = response[contractAddress][DEFAULT_CURRENCY] * Number.parseFloat(currencyResponse[DEFAULT_CURRENCY]) || 0;