@toruslabs/ethereum-controllers 5.6.5 → 5.7.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 +193 -42
- package/dist/ethereumControllers.esm.js +190 -43
- package/dist/ethereumControllers.umd.min.js +1 -1
- package/dist/types/Network/cacheIdentifier.d.ts +22 -0
- package/dist/types/Preferences/PreferencesController.d.ts +1 -0
- package/dist/types/utils/helpers.d.ts +12 -2
- package/package.json +8 -7
|
@@ -1560,43 +1560,48 @@ function getEtherScanHashLink(txHash, chainId) {
|
|
|
1560
1560
|
if (!SUPPORTED_NETWORKS[chainId]) return "";
|
|
1561
1561
|
return `${SUPPORTED_NETWORKS[chainId].blockExplorerUrl}/tx/${txHash}`;
|
|
1562
1562
|
}
|
|
1563
|
-
const formatPastTx =
|
|
1564
|
-
var
|
|
1563
|
+
const formatPastTx = params => {
|
|
1564
|
+
var _transaction$to;
|
|
1565
|
+
const {
|
|
1566
|
+
transaction,
|
|
1567
|
+
lowerCaseSelectedAddress,
|
|
1568
|
+
blockExplorerUrl
|
|
1569
|
+
} = params;
|
|
1565
1570
|
let totalAmountString = "";
|
|
1566
|
-
if (
|
|
1567
|
-
const currencyAmountString =
|
|
1571
|
+
if (transaction.type === CONTRACT_TYPE_ERC721 || transaction.type === CONTRACT_TYPE_ERC1155) totalAmountString = transaction.symbol;else if (transaction.type === CONTRACT_TYPE_ERC20) totalAmountString = (0,base_controllers_namespaceObject.formatSmallNumbers)(Number.parseFloat(transaction.total_amount), transaction.symbol, true);else totalAmountString = (0,base_controllers_namespaceObject.formatSmallNumbers)(Number.parseFloat(transaction.total_amount), transaction.type_name, true);
|
|
1572
|
+
const currencyAmountString = transaction.type === CONTRACT_TYPE_ERC721 || transaction.type === CONTRACT_TYPE_ERC1155 || transaction.isEtherscan ? "" : (0,base_controllers_namespaceObject.formatSmallNumbers)(Number.parseFloat(transaction.currency_amount), transaction.selected_currency, true);
|
|
1568
1573
|
const finalObject = {
|
|
1569
|
-
id:
|
|
1570
|
-
date: new Date(
|
|
1571
|
-
from:
|
|
1572
|
-
from_aa_address:
|
|
1573
|
-
slicedFrom: typeof
|
|
1574
|
-
to:
|
|
1575
|
-
slicedTo: typeof
|
|
1576
|
-
action: lowerCaseSelectedAddress === ((
|
|
1577
|
-
totalAmount:
|
|
1574
|
+
id: transaction.created_at.toString(),
|
|
1575
|
+
date: new Date(transaction.created_at).toString(),
|
|
1576
|
+
from: transaction.from,
|
|
1577
|
+
from_aa_address: transaction.from_aa_address,
|
|
1578
|
+
slicedFrom: typeof transaction.from === "string" ? (0,base_controllers_namespaceObject.addressSlicer)(transaction.from) : "",
|
|
1579
|
+
to: transaction.to,
|
|
1580
|
+
slicedTo: typeof transaction.to === "string" ? (0,base_controllers_namespaceObject.addressSlicer)(transaction.to) : "",
|
|
1581
|
+
action: lowerCaseSelectedAddress === ((_transaction$to = transaction.to) === null || _transaction$to === void 0 ? void 0 : _transaction$to.toLowerCase()) || "" ? base_controllers_namespaceObject.ACTIVITY_ACTION_RECEIVE : base_controllers_namespaceObject.ACTIVITY_ACTION_SEND,
|
|
1582
|
+
totalAmount: transaction.total_amount,
|
|
1578
1583
|
totalAmountString,
|
|
1579
|
-
currencyAmount:
|
|
1584
|
+
currencyAmount: transaction.currency_amount,
|
|
1580
1585
|
currencyAmountString,
|
|
1581
1586
|
amount: `${totalAmountString} / ${currencyAmountString}`,
|
|
1582
|
-
status:
|
|
1583
|
-
etherscanLink:
|
|
1584
|
-
chainId:
|
|
1585
|
-
ethRate: Number.parseFloat(
|
|
1586
|
-
currencyUsed:
|
|
1587
|
-
type:
|
|
1588
|
-
type_name:
|
|
1589
|
-
type_image_link:
|
|
1590
|
-
transaction_hash:
|
|
1591
|
-
transaction_category:
|
|
1592
|
-
isEtherscan:
|
|
1593
|
-
input:
|
|
1594
|
-
token_id:
|
|
1595
|
-
contract_address:
|
|
1596
|
-
nonce:
|
|
1597
|
-
is_cancel: !!
|
|
1598
|
-
gas:
|
|
1599
|
-
gasPrice:
|
|
1587
|
+
status: transaction.status,
|
|
1588
|
+
etherscanLink: blockExplorerUrl ? `${blockExplorerUrl}/tx/${transaction.transaction_hash}` : "",
|
|
1589
|
+
chainId: transaction.chain_id,
|
|
1590
|
+
ethRate: Number.parseFloat(transaction === null || transaction === void 0 ? void 0 : transaction.total_amount) && Number.parseFloat(transaction === null || transaction === void 0 ? void 0 : transaction.currency_amount) ? `1 ${transaction.symbol} = ${(0,base_controllers_namespaceObject.significantDigits)(Number.parseFloat(transaction.currency_amount) / Number.parseFloat(transaction.total_amount))}` : "",
|
|
1591
|
+
currencyUsed: transaction.selected_currency,
|
|
1592
|
+
type: transaction.type,
|
|
1593
|
+
type_name: transaction.type_name,
|
|
1594
|
+
type_image_link: transaction.type_image_link,
|
|
1595
|
+
transaction_hash: transaction.transaction_hash,
|
|
1596
|
+
transaction_category: transaction.transaction_category,
|
|
1597
|
+
isEtherscan: transaction.isEtherscan,
|
|
1598
|
+
input: transaction.input || "",
|
|
1599
|
+
token_id: transaction.token_id || "",
|
|
1600
|
+
contract_address: transaction.contract_address || "",
|
|
1601
|
+
nonce: transaction.nonce || "",
|
|
1602
|
+
is_cancel: !!transaction.is_cancel || false,
|
|
1603
|
+
gas: transaction.gas || "",
|
|
1604
|
+
gasPrice: transaction.gasPrice || ""
|
|
1600
1605
|
};
|
|
1601
1606
|
return finalObject;
|
|
1602
1607
|
};
|
|
@@ -1692,7 +1697,14 @@ function getChainType(chainId) {
|
|
|
1692
1697
|
}
|
|
1693
1698
|
return "custom";
|
|
1694
1699
|
}
|
|
1695
|
-
const addEtherscanTransactions = async
|
|
1700
|
+
const addEtherscanTransactions = async params => {
|
|
1701
|
+
const {
|
|
1702
|
+
txn,
|
|
1703
|
+
lowerCaseSelectedAddress,
|
|
1704
|
+
provider,
|
|
1705
|
+
chainId,
|
|
1706
|
+
blockExplorerUrl
|
|
1707
|
+
} = params;
|
|
1696
1708
|
const transactionPromises = await Promise.all(txn.map(async tx => {
|
|
1697
1709
|
var _SUPPORTED_NETWORKS$c, _SUPPORTED_NETWORKS$c2;
|
|
1698
1710
|
const {
|
|
@@ -1722,7 +1734,6 @@ const addEtherscanTransactions = async (txn, lowerCaseSelectedAddress, provider,
|
|
|
1722
1734
|
totalAmountString = x.tokenValue;
|
|
1723
1735
|
}
|
|
1724
1736
|
const etherscanTransaction = {
|
|
1725
|
-
etherscanLink: getEtherScanHashLink(x.hash, chainId),
|
|
1726
1737
|
type,
|
|
1727
1738
|
type_image_link: x.type_image_link || "n/a",
|
|
1728
1739
|
type_name: x.tokenName || ((_SUPPORTED_NETWORKS$c3 = SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c3 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c3.ticker) || "n/a",
|
|
@@ -1747,7 +1758,11 @@ const addEtherscanTransactions = async (txn, lowerCaseSelectedAddress, provider,
|
|
|
1747
1758
|
is_cancel: false,
|
|
1748
1759
|
selected_currency: ""
|
|
1749
1760
|
};
|
|
1750
|
-
accumulator.push(formatPastTx(
|
|
1761
|
+
accumulator.push(formatPastTx({
|
|
1762
|
+
transaction: etherscanTransaction,
|
|
1763
|
+
lowerCaseSelectedAddress,
|
|
1764
|
+
blockExplorerUrl
|
|
1765
|
+
}));
|
|
1751
1766
|
return accumulator;
|
|
1752
1767
|
}, []);
|
|
1753
1768
|
return finalTxs;
|
|
@@ -2425,7 +2440,7 @@ class GasFeeController extends base_controllers_namespaceObject.BaseController {
|
|
|
2425
2440
|
const newChainId = this.getNetworkIdentifier();
|
|
2426
2441
|
if (this.currentChainId !== newChainId) {
|
|
2427
2442
|
this.currentChainId = newChainId;
|
|
2428
|
-
await this.
|
|
2443
|
+
await this.fetchGasFeeEstimates();
|
|
2429
2444
|
}
|
|
2430
2445
|
}
|
|
2431
2446
|
async resetPolling() {
|
|
@@ -3847,11 +3862,120 @@ function createEthereumMiddleware(providerHandlers) {
|
|
|
3847
3862
|
processAddEthereumChain
|
|
3848
3863
|
})]);
|
|
3849
3864
|
}
|
|
3865
|
+
;// CONCATENATED MODULE: external "fast-safe-stringify"
|
|
3866
|
+
const external_fast_safe_stringify_namespaceObject = require("fast-safe-stringify");
|
|
3867
|
+
var external_fast_safe_stringify_default = /*#__PURE__*/__webpack_require__.n(external_fast_safe_stringify_namespaceObject);
|
|
3868
|
+
;// CONCATENATED MODULE: ./src/Network/cacheIdentifier.ts
|
|
3869
|
+
|
|
3870
|
+
let CacheStrategy = /*#__PURE__*/function (CacheStrategy) {
|
|
3871
|
+
CacheStrategy["Block"] = "block";
|
|
3872
|
+
CacheStrategy["Fork"] = "fork";
|
|
3873
|
+
CacheStrategy["Never"] = "never";
|
|
3874
|
+
CacheStrategy["Permanent"] = "perma";
|
|
3875
|
+
return CacheStrategy;
|
|
3876
|
+
}({});
|
|
3877
|
+
function blockTagParamIndex(method) {
|
|
3878
|
+
switch (method) {
|
|
3879
|
+
// blockTag is at index 2
|
|
3880
|
+
case "eth_getStorageAt":
|
|
3881
|
+
return 2;
|
|
3882
|
+
// blockTag is at index 1
|
|
3883
|
+
case "eth_getBalance":
|
|
3884
|
+
case "eth_getCode":
|
|
3885
|
+
case "eth_getTransactionCount":
|
|
3886
|
+
case "eth_call":
|
|
3887
|
+
return 1;
|
|
3888
|
+
// blockTag is at index 0
|
|
3889
|
+
case "eth_getBlockByNumber":
|
|
3890
|
+
return 0;
|
|
3891
|
+
// there is no blockTag
|
|
3892
|
+
default:
|
|
3893
|
+
return undefined;
|
|
3894
|
+
}
|
|
3895
|
+
}
|
|
3896
|
+
function cacheTypeForMethod(method) {
|
|
3897
|
+
switch (method) {
|
|
3898
|
+
// cache permanently
|
|
3899
|
+
case "web3_clientVersion":
|
|
3900
|
+
case "web3_sha3":
|
|
3901
|
+
case "eth_protocolVersion":
|
|
3902
|
+
case "eth_getBlockTransactionCountByHash":
|
|
3903
|
+
case "eth_getUncleCountByBlockHash":
|
|
3904
|
+
case "eth_getCode":
|
|
3905
|
+
case "eth_getBlockByHash":
|
|
3906
|
+
case "eth_getTransactionByHash":
|
|
3907
|
+
case "eth_getTransactionByBlockHashAndIndex":
|
|
3908
|
+
case "eth_getTransactionReceipt":
|
|
3909
|
+
case "eth_getUncleByBlockHashAndIndex":
|
|
3910
|
+
case "eth_getCompilers":
|
|
3911
|
+
case "eth_compileLLL":
|
|
3912
|
+
case "eth_compileSolidity":
|
|
3913
|
+
case "eth_compileSerpent":
|
|
3914
|
+
case "shh_version":
|
|
3915
|
+
case "test_permaCache":
|
|
3916
|
+
return CacheStrategy.Permanent;
|
|
3917
|
+
|
|
3918
|
+
// cache until fork
|
|
3919
|
+
case "eth_getBlockByNumber":
|
|
3920
|
+
case "eth_getBlockTransactionCountByNumber":
|
|
3921
|
+
case "eth_getUncleCountByBlockNumber":
|
|
3922
|
+
case "eth_getTransactionByBlockNumberAndIndex":
|
|
3923
|
+
case "eth_getUncleByBlockNumberAndIndex":
|
|
3924
|
+
case "test_forkCache":
|
|
3925
|
+
return CacheStrategy.Fork;
|
|
3926
|
+
|
|
3927
|
+
// cache for block
|
|
3928
|
+
case "eth_gasPrice":
|
|
3929
|
+
case "eth_blockNumber":
|
|
3930
|
+
case "eth_getBalance":
|
|
3931
|
+
case "eth_getStorageAt":
|
|
3932
|
+
case "eth_getTransactionCount":
|
|
3933
|
+
case "eth_call":
|
|
3934
|
+
case "eth_estimateGas":
|
|
3935
|
+
case "eth_getFilterLogs":
|
|
3936
|
+
case "eth_getLogs":
|
|
3937
|
+
case "test_blockCache":
|
|
3938
|
+
return CacheStrategy.Block;
|
|
3939
|
+
|
|
3940
|
+
// never cache
|
|
3941
|
+
default:
|
|
3942
|
+
return CacheStrategy.Never;
|
|
3943
|
+
}
|
|
3944
|
+
}
|
|
3945
|
+
function canCache(method) {
|
|
3946
|
+
return cacheTypeForMethod(method) !== CacheStrategy.Never;
|
|
3947
|
+
}
|
|
3948
|
+
function paramsWithoutBlockTag(request) {
|
|
3949
|
+
if (!request.params) {
|
|
3950
|
+
return [];
|
|
3951
|
+
}
|
|
3952
|
+
const index = blockTagParamIndex(request.method);
|
|
3953
|
+
|
|
3954
|
+
// Block tag param not passed.
|
|
3955
|
+
if (index === undefined || !Array.isArray(request.params) || index >= request.params.length) {
|
|
3956
|
+
return request.params;
|
|
3957
|
+
}
|
|
3958
|
+
|
|
3959
|
+
// eth_getBlockByNumber has the block tag first, then the optional includeTx? param
|
|
3960
|
+
if (request.method === "eth_getBlockByNumber") {
|
|
3961
|
+
return request.params.slice(1);
|
|
3962
|
+
}
|
|
3963
|
+
return request.params.slice(0, index);
|
|
3964
|
+
}
|
|
3965
|
+
function cacheIdentifierForRequest(request, skipBlockRef) {
|
|
3966
|
+
var _request$params;
|
|
3967
|
+
const simpleParams = skipBlockRef ? paramsWithoutBlockTag(request) : (_request$params = request.params) !== null && _request$params !== void 0 ? _request$params : [];
|
|
3968
|
+
if (canCache(request.method)) {
|
|
3969
|
+
return `${request.method}:${external_fast_safe_stringify_default()(simpleParams)}`;
|
|
3970
|
+
}
|
|
3971
|
+
return null;
|
|
3972
|
+
}
|
|
3850
3973
|
;// CONCATENATED MODULE: ./src/Network/createJsonRpcClient.ts
|
|
3851
3974
|
|
|
3852
3975
|
|
|
3853
3976
|
|
|
3854
3977
|
|
|
3978
|
+
|
|
3855
3979
|
function createChainIdMiddleware(chainId) {
|
|
3856
3980
|
return (req, res, next, end) => {
|
|
3857
3981
|
if (req.method === "eth_chainId") {
|
|
@@ -3894,7 +4018,9 @@ function createJsonRpcClient(providerConfig, networkConfig) {
|
|
|
3894
4018
|
// No need for the following middlewares for web because all browser sessions are quite short lived and each session is limited to scope of a window/tab
|
|
3895
4019
|
// createBlockRefRewriteMiddleware({ blockTracker }),
|
|
3896
4020
|
// createBlockCacheMiddleware({ blockTracker }),
|
|
3897
|
-
|
|
4021
|
+
(0,base_controllers_namespaceObject.createInflightCacheMiddleware)({
|
|
4022
|
+
cacheIdentifierForRequest: cacheIdentifierForRequest
|
|
4023
|
+
}),
|
|
3898
4024
|
// createBlockTrackerInspectorMiddleware({ blockTracker }),
|
|
3899
4025
|
fetchMiddleware]);
|
|
3900
4026
|
return {
|
|
@@ -4663,7 +4789,10 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
|
|
|
4663
4789
|
}
|
|
4664
4790
|
async patchNewTx(tx, address) {
|
|
4665
4791
|
var _this$getAddressState2;
|
|
4666
|
-
const formattedTx = formatPastTx(
|
|
4792
|
+
const formattedTx = formatPastTx({
|
|
4793
|
+
transaction: tx,
|
|
4794
|
+
blockExplorerUrl: this.getBlockExplorerUrl()
|
|
4795
|
+
});
|
|
4667
4796
|
const storePastTx = ((_this$getAddressState2 = this.getAddressState(address)) === null || _this$getAddressState2 === void 0 ? void 0 : _this$getAddressState2.formattedPastTransactions) || [];
|
|
4668
4797
|
const duplicateIndex = storePastTx.findIndex(x => x.transaction_hash === tx.transaction_hash && x.chainId === tx.chain_id);
|
|
4669
4798
|
if (tx.status === base_controllers_namespaceObject.TransactionStatus.submitted || tx.status === base_controllers_namespaceObject.TransactionStatus.confirmed) {
|
|
@@ -4709,7 +4838,13 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
|
|
|
4709
4838
|
selectedAddress,
|
|
4710
4839
|
chainId: this.getProviderConfig().chainId
|
|
4711
4840
|
});
|
|
4712
|
-
const finalEthScanTxn = await addEtherscanTransactions(
|
|
4841
|
+
const finalEthScanTxn = await addEtherscanTransactions({
|
|
4842
|
+
txn: etherscanTxn,
|
|
4843
|
+
lowerCaseSelectedAddress,
|
|
4844
|
+
provider: this.provider,
|
|
4845
|
+
chainId,
|
|
4846
|
+
blockExplorerUrl: this.getBlockExplorerUrl()
|
|
4847
|
+
});
|
|
4713
4848
|
external_loglevel_default().info("Formatted Etherscan Response", finalEthScanTxn);
|
|
4714
4849
|
this.updateState({
|
|
4715
4850
|
etherscanTransactions: finalEthScanTxn
|
|
@@ -4897,17 +5032,29 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
|
|
|
4897
5032
|
}, []);
|
|
4898
5033
|
return [...supported, ...custom];
|
|
4899
5034
|
}
|
|
5035
|
+
getBlockExplorerUrl() {
|
|
5036
|
+
const supportedNetworks = this.getChainOptions();
|
|
5037
|
+
const network = supportedNetworks.find(x => x.chainId === this.getProviderConfig().chainId);
|
|
5038
|
+
if (!network) return "";
|
|
5039
|
+
return `${network.blockExplorerUrl}`;
|
|
5040
|
+
}
|
|
4900
5041
|
async calculatePastTx(txs, address) {
|
|
4901
5042
|
const pastTx = [];
|
|
4902
5043
|
const pendingTx = [];
|
|
4903
5044
|
const lowerCaseSelectedAddress = address.toLowerCase();
|
|
5045
|
+
const supportedNetworks = this.getChainOptions(address);
|
|
5046
|
+
const supportedNetwork = supportedNetworks.find(x => x.chainId === this.getProviderConfig().chainId);
|
|
4904
5047
|
for (const x of txs) {
|
|
4905
5048
|
var _x$to;
|
|
4906
|
-
if (
|
|
5049
|
+
if ((supportedNetwork === null || supportedNetwork === void 0 ? void 0 : supportedNetwork.chainId) === x.chain_id && x.to && x.from && (lowerCaseSelectedAddress === x.from.toLowerCase() || lowerCaseSelectedAddress === ((_x$to = x.to) === null || _x$to === void 0 ? void 0 : _x$to.toLowerCase()))) {
|
|
4907
5050
|
if (x.status !== "confirmed") {
|
|
4908
5051
|
pendingTx.push(x);
|
|
4909
5052
|
} else {
|
|
4910
|
-
const finalObject = formatPastTx(
|
|
5053
|
+
const finalObject = formatPastTx({
|
|
5054
|
+
transaction: x,
|
|
5055
|
+
lowerCaseSelectedAddress,
|
|
5056
|
+
blockExplorerUrl: this.getBlockExplorerUrl()
|
|
5057
|
+
});
|
|
4911
5058
|
pastTx.push(finalObject);
|
|
4912
5059
|
}
|
|
4913
5060
|
}
|
|
@@ -4915,7 +5062,11 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
|
|
|
4915
5062
|
const pendingTxPromises = pendingTx.map(x => getEthTxStatus(x.transaction_hash, this.provider).catch(error => external_loglevel_default().error(error)));
|
|
4916
5063
|
const resolvedTxStatuses = await Promise.all(pendingTxPromises);
|
|
4917
5064
|
for (const [index, element] of pendingTx.entries()) {
|
|
4918
|
-
const finalObject = formatPastTx(
|
|
5065
|
+
const finalObject = formatPastTx({
|
|
5066
|
+
transaction: element,
|
|
5067
|
+
lowerCaseSelectedAddress,
|
|
5068
|
+
blockExplorerUrl: this.getBlockExplorerUrl()
|
|
5069
|
+
});
|
|
4919
5070
|
finalObject.status = resolvedTxStatuses[index] || base_controllers_namespaceObject.TransactionStatus.submitted;
|
|
4920
5071
|
pastTx.push(finalObject);
|
|
4921
5072
|
if (lowerCaseSelectedAddress === element.from.toLowerCase() && finalObject.status && finalObject.status !== element.status) this.patchPastTx({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
-
import { CHAIN_NAMESPACES, BaseController, randomId, TransactionStatus, TRANSACTION_TYPES, formatSmallNumbers, addressSlicer, ACTIVITY_ACTION_RECEIVE, ACTIVITY_ACTION_SEND, significantDigits, BaseBlockTracker, timeout, BaseCurrencyController, BaseKeyringController, PROVIDER_JRPC_METHODS, createFetchMiddleware, createSwappableProxy, createEventEmitterProxy, BasePreferencesController, TX_EVENTS, BaseTransactionStateManager, transactionMatchesNetwork as transactionMatchesNetwork$1 } from '@toruslabs/base-controllers';
|
|
3
|
+
import { CHAIN_NAMESPACES, BaseController, randomId, TransactionStatus, TRANSACTION_TYPES, formatSmallNumbers, addressSlicer, ACTIVITY_ACTION_RECEIVE, ACTIVITY_ACTION_SEND, significantDigits, BaseBlockTracker, timeout, BaseCurrencyController, BaseKeyringController, PROVIDER_JRPC_METHODS, createFetchMiddleware, createInflightCacheMiddleware, createSwappableProxy, createEventEmitterProxy, BasePreferencesController, TX_EVENTS, BaseTransactionStateManager, transactionMatchesNetwork as transactionMatchesNetwork$1 } from '@toruslabs/base-controllers';
|
|
4
4
|
import { Mutex } from 'async-mutex';
|
|
5
5
|
import { BrowserProvider, toQuantity, Contract, Interface, isHexString as isHexString$1, JsonRpcProvider, keccak256 } from 'ethers';
|
|
6
6
|
import log from 'loglevel';
|
|
@@ -15,6 +15,7 @@ import BN, { BN as BN$1 } from 'bn.js';
|
|
|
15
15
|
import { concatSig, personalSign, signTypedData, getEncryptionPublicKey, decrypt, typedSignatureHash, TYPED_MESSAGE_SCHEMA, SignTypedDataVersion } from '@metamask/eth-sig-util';
|
|
16
16
|
import { validate } from 'jsonschema';
|
|
17
17
|
import { createAsyncMiddleware, mergeMiddleware, createScaffoldMiddleware, providerFromMiddleware, JRPCEngine, providerFromEngine, SafeEventEmitter } from '@toruslabs/openlogin-jrpc';
|
|
18
|
+
import stringify from 'fast-safe-stringify';
|
|
18
19
|
import { Hardfork, Common } from '@ethereumjs/common';
|
|
19
20
|
import { TransactionFactory } from '@ethereumjs/tx';
|
|
20
21
|
import jsonDiffer from 'fast-json-patch';
|
|
@@ -1338,43 +1339,48 @@ function getEtherScanHashLink(txHash, chainId) {
|
|
|
1338
1339
|
if (!SUPPORTED_NETWORKS[chainId]) return "";
|
|
1339
1340
|
return `${SUPPORTED_NETWORKS[chainId].blockExplorerUrl}/tx/${txHash}`;
|
|
1340
1341
|
}
|
|
1341
|
-
const formatPastTx =
|
|
1342
|
-
var
|
|
1342
|
+
const formatPastTx = params => {
|
|
1343
|
+
var _transaction$to;
|
|
1344
|
+
const {
|
|
1345
|
+
transaction,
|
|
1346
|
+
lowerCaseSelectedAddress,
|
|
1347
|
+
blockExplorerUrl
|
|
1348
|
+
} = params;
|
|
1343
1349
|
let totalAmountString = "";
|
|
1344
|
-
if (
|
|
1345
|
-
const currencyAmountString =
|
|
1350
|
+
if (transaction.type === CONTRACT_TYPE_ERC721 || transaction.type === CONTRACT_TYPE_ERC1155) totalAmountString = transaction.symbol;else if (transaction.type === CONTRACT_TYPE_ERC20) totalAmountString = formatSmallNumbers(Number.parseFloat(transaction.total_amount), transaction.symbol, true);else totalAmountString = formatSmallNumbers(Number.parseFloat(transaction.total_amount), transaction.type_name, true);
|
|
1351
|
+
const currencyAmountString = transaction.type === CONTRACT_TYPE_ERC721 || transaction.type === CONTRACT_TYPE_ERC1155 || transaction.isEtherscan ? "" : formatSmallNumbers(Number.parseFloat(transaction.currency_amount), transaction.selected_currency, true);
|
|
1346
1352
|
const finalObject = {
|
|
1347
|
-
id:
|
|
1348
|
-
date: new Date(
|
|
1349
|
-
from:
|
|
1350
|
-
from_aa_address:
|
|
1351
|
-
slicedFrom: typeof
|
|
1352
|
-
to:
|
|
1353
|
-
slicedTo: typeof
|
|
1354
|
-
action: lowerCaseSelectedAddress === ((
|
|
1355
|
-
totalAmount:
|
|
1353
|
+
id: transaction.created_at.toString(),
|
|
1354
|
+
date: new Date(transaction.created_at).toString(),
|
|
1355
|
+
from: transaction.from,
|
|
1356
|
+
from_aa_address: transaction.from_aa_address,
|
|
1357
|
+
slicedFrom: typeof transaction.from === "string" ? addressSlicer(transaction.from) : "",
|
|
1358
|
+
to: transaction.to,
|
|
1359
|
+
slicedTo: typeof transaction.to === "string" ? addressSlicer(transaction.to) : "",
|
|
1360
|
+
action: lowerCaseSelectedAddress === ((_transaction$to = transaction.to) === null || _transaction$to === void 0 ? void 0 : _transaction$to.toLowerCase()) || "" ? ACTIVITY_ACTION_RECEIVE : ACTIVITY_ACTION_SEND,
|
|
1361
|
+
totalAmount: transaction.total_amount,
|
|
1356
1362
|
totalAmountString,
|
|
1357
|
-
currencyAmount:
|
|
1363
|
+
currencyAmount: transaction.currency_amount,
|
|
1358
1364
|
currencyAmountString,
|
|
1359
1365
|
amount: `${totalAmountString} / ${currencyAmountString}`,
|
|
1360
|
-
status:
|
|
1361
|
-
etherscanLink:
|
|
1362
|
-
chainId:
|
|
1363
|
-
ethRate: Number.parseFloat(
|
|
1364
|
-
currencyUsed:
|
|
1365
|
-
type:
|
|
1366
|
-
type_name:
|
|
1367
|
-
type_image_link:
|
|
1368
|
-
transaction_hash:
|
|
1369
|
-
transaction_category:
|
|
1370
|
-
isEtherscan:
|
|
1371
|
-
input:
|
|
1372
|
-
token_id:
|
|
1373
|
-
contract_address:
|
|
1374
|
-
nonce:
|
|
1375
|
-
is_cancel: !!
|
|
1376
|
-
gas:
|
|
1377
|
-
gasPrice:
|
|
1366
|
+
status: transaction.status,
|
|
1367
|
+
etherscanLink: blockExplorerUrl ? `${blockExplorerUrl}/tx/${transaction.transaction_hash}` : "",
|
|
1368
|
+
chainId: transaction.chain_id,
|
|
1369
|
+
ethRate: Number.parseFloat(transaction === null || transaction === void 0 ? void 0 : transaction.total_amount) && Number.parseFloat(transaction === null || transaction === void 0 ? void 0 : transaction.currency_amount) ? `1 ${transaction.symbol} = ${significantDigits(Number.parseFloat(transaction.currency_amount) / Number.parseFloat(transaction.total_amount))}` : "",
|
|
1370
|
+
currencyUsed: transaction.selected_currency,
|
|
1371
|
+
type: transaction.type,
|
|
1372
|
+
type_name: transaction.type_name,
|
|
1373
|
+
type_image_link: transaction.type_image_link,
|
|
1374
|
+
transaction_hash: transaction.transaction_hash,
|
|
1375
|
+
transaction_category: transaction.transaction_category,
|
|
1376
|
+
isEtherscan: transaction.isEtherscan,
|
|
1377
|
+
input: transaction.input || "",
|
|
1378
|
+
token_id: transaction.token_id || "",
|
|
1379
|
+
contract_address: transaction.contract_address || "",
|
|
1380
|
+
nonce: transaction.nonce || "",
|
|
1381
|
+
is_cancel: !!transaction.is_cancel || false,
|
|
1382
|
+
gas: transaction.gas || "",
|
|
1383
|
+
gasPrice: transaction.gasPrice || ""
|
|
1378
1384
|
};
|
|
1379
1385
|
return finalObject;
|
|
1380
1386
|
};
|
|
@@ -1470,7 +1476,14 @@ function getChainType(chainId) {
|
|
|
1470
1476
|
}
|
|
1471
1477
|
return "custom";
|
|
1472
1478
|
}
|
|
1473
|
-
const addEtherscanTransactions = async
|
|
1479
|
+
const addEtherscanTransactions = async params => {
|
|
1480
|
+
const {
|
|
1481
|
+
txn,
|
|
1482
|
+
lowerCaseSelectedAddress,
|
|
1483
|
+
provider,
|
|
1484
|
+
chainId,
|
|
1485
|
+
blockExplorerUrl
|
|
1486
|
+
} = params;
|
|
1474
1487
|
const transactionPromises = await Promise.all(txn.map(async tx => {
|
|
1475
1488
|
var _SUPPORTED_NETWORKS$c, _SUPPORTED_NETWORKS$c2;
|
|
1476
1489
|
const {
|
|
@@ -1500,7 +1513,6 @@ const addEtherscanTransactions = async (txn, lowerCaseSelectedAddress, provider,
|
|
|
1500
1513
|
totalAmountString = x.tokenValue;
|
|
1501
1514
|
}
|
|
1502
1515
|
const etherscanTransaction = {
|
|
1503
|
-
etherscanLink: getEtherScanHashLink(x.hash, chainId),
|
|
1504
1516
|
type,
|
|
1505
1517
|
type_image_link: x.type_image_link || "n/a",
|
|
1506
1518
|
type_name: x.tokenName || ((_SUPPORTED_NETWORKS$c3 = SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c3 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c3.ticker) || "n/a",
|
|
@@ -1525,7 +1537,11 @@ const addEtherscanTransactions = async (txn, lowerCaseSelectedAddress, provider,
|
|
|
1525
1537
|
is_cancel: false,
|
|
1526
1538
|
selected_currency: ""
|
|
1527
1539
|
};
|
|
1528
|
-
accumulator.push(formatPastTx(
|
|
1540
|
+
accumulator.push(formatPastTx({
|
|
1541
|
+
transaction: etherscanTransaction,
|
|
1542
|
+
lowerCaseSelectedAddress,
|
|
1543
|
+
blockExplorerUrl
|
|
1544
|
+
}));
|
|
1529
1545
|
return accumulator;
|
|
1530
1546
|
}, []);
|
|
1531
1547
|
return finalTxs;
|
|
@@ -2136,7 +2152,7 @@ class GasFeeController extends BaseController {
|
|
|
2136
2152
|
const newChainId = this.getNetworkIdentifier();
|
|
2137
2153
|
if (this.currentChainId !== newChainId) {
|
|
2138
2154
|
this.currentChainId = newChainId;
|
|
2139
|
-
await this.
|
|
2155
|
+
await this.fetchGasFeeEstimates();
|
|
2140
2156
|
}
|
|
2141
2157
|
}
|
|
2142
2158
|
async resetPolling() {
|
|
@@ -3486,6 +3502,110 @@ function createEthereumMiddleware(providerHandlers) {
|
|
|
3486
3502
|
})]);
|
|
3487
3503
|
}
|
|
3488
3504
|
|
|
3505
|
+
let CacheStrategy = /*#__PURE__*/function (CacheStrategy) {
|
|
3506
|
+
CacheStrategy["Block"] = "block";
|
|
3507
|
+
CacheStrategy["Fork"] = "fork";
|
|
3508
|
+
CacheStrategy["Never"] = "never";
|
|
3509
|
+
CacheStrategy["Permanent"] = "perma";
|
|
3510
|
+
return CacheStrategy;
|
|
3511
|
+
}({});
|
|
3512
|
+
function blockTagParamIndex(method) {
|
|
3513
|
+
switch (method) {
|
|
3514
|
+
// blockTag is at index 2
|
|
3515
|
+
case "eth_getStorageAt":
|
|
3516
|
+
return 2;
|
|
3517
|
+
// blockTag is at index 1
|
|
3518
|
+
case "eth_getBalance":
|
|
3519
|
+
case "eth_getCode":
|
|
3520
|
+
case "eth_getTransactionCount":
|
|
3521
|
+
case "eth_call":
|
|
3522
|
+
return 1;
|
|
3523
|
+
// blockTag is at index 0
|
|
3524
|
+
case "eth_getBlockByNumber":
|
|
3525
|
+
return 0;
|
|
3526
|
+
// there is no blockTag
|
|
3527
|
+
default:
|
|
3528
|
+
return undefined;
|
|
3529
|
+
}
|
|
3530
|
+
}
|
|
3531
|
+
function cacheTypeForMethod(method) {
|
|
3532
|
+
switch (method) {
|
|
3533
|
+
// cache permanently
|
|
3534
|
+
case "web3_clientVersion":
|
|
3535
|
+
case "web3_sha3":
|
|
3536
|
+
case "eth_protocolVersion":
|
|
3537
|
+
case "eth_getBlockTransactionCountByHash":
|
|
3538
|
+
case "eth_getUncleCountByBlockHash":
|
|
3539
|
+
case "eth_getCode":
|
|
3540
|
+
case "eth_getBlockByHash":
|
|
3541
|
+
case "eth_getTransactionByHash":
|
|
3542
|
+
case "eth_getTransactionByBlockHashAndIndex":
|
|
3543
|
+
case "eth_getTransactionReceipt":
|
|
3544
|
+
case "eth_getUncleByBlockHashAndIndex":
|
|
3545
|
+
case "eth_getCompilers":
|
|
3546
|
+
case "eth_compileLLL":
|
|
3547
|
+
case "eth_compileSolidity":
|
|
3548
|
+
case "eth_compileSerpent":
|
|
3549
|
+
case "shh_version":
|
|
3550
|
+
case "test_permaCache":
|
|
3551
|
+
return CacheStrategy.Permanent;
|
|
3552
|
+
|
|
3553
|
+
// cache until fork
|
|
3554
|
+
case "eth_getBlockByNumber":
|
|
3555
|
+
case "eth_getBlockTransactionCountByNumber":
|
|
3556
|
+
case "eth_getUncleCountByBlockNumber":
|
|
3557
|
+
case "eth_getTransactionByBlockNumberAndIndex":
|
|
3558
|
+
case "eth_getUncleByBlockNumberAndIndex":
|
|
3559
|
+
case "test_forkCache":
|
|
3560
|
+
return CacheStrategy.Fork;
|
|
3561
|
+
|
|
3562
|
+
// cache for block
|
|
3563
|
+
case "eth_gasPrice":
|
|
3564
|
+
case "eth_blockNumber":
|
|
3565
|
+
case "eth_getBalance":
|
|
3566
|
+
case "eth_getStorageAt":
|
|
3567
|
+
case "eth_getTransactionCount":
|
|
3568
|
+
case "eth_call":
|
|
3569
|
+
case "eth_estimateGas":
|
|
3570
|
+
case "eth_getFilterLogs":
|
|
3571
|
+
case "eth_getLogs":
|
|
3572
|
+
case "test_blockCache":
|
|
3573
|
+
return CacheStrategy.Block;
|
|
3574
|
+
|
|
3575
|
+
// never cache
|
|
3576
|
+
default:
|
|
3577
|
+
return CacheStrategy.Never;
|
|
3578
|
+
}
|
|
3579
|
+
}
|
|
3580
|
+
function canCache(method) {
|
|
3581
|
+
return cacheTypeForMethod(method) !== CacheStrategy.Never;
|
|
3582
|
+
}
|
|
3583
|
+
function paramsWithoutBlockTag(request) {
|
|
3584
|
+
if (!request.params) {
|
|
3585
|
+
return [];
|
|
3586
|
+
}
|
|
3587
|
+
const index = blockTagParamIndex(request.method);
|
|
3588
|
+
|
|
3589
|
+
// Block tag param not passed.
|
|
3590
|
+
if (index === undefined || !Array.isArray(request.params) || index >= request.params.length) {
|
|
3591
|
+
return request.params;
|
|
3592
|
+
}
|
|
3593
|
+
|
|
3594
|
+
// eth_getBlockByNumber has the block tag first, then the optional includeTx? param
|
|
3595
|
+
if (request.method === "eth_getBlockByNumber") {
|
|
3596
|
+
return request.params.slice(1);
|
|
3597
|
+
}
|
|
3598
|
+
return request.params.slice(0, index);
|
|
3599
|
+
}
|
|
3600
|
+
function cacheIdentifierForRequest(request, skipBlockRef) {
|
|
3601
|
+
var _request$params;
|
|
3602
|
+
const simpleParams = skipBlockRef ? paramsWithoutBlockTag(request) : (_request$params = request.params) !== null && _request$params !== void 0 ? _request$params : [];
|
|
3603
|
+
if (canCache(request.method)) {
|
|
3604
|
+
return `${request.method}:${stringify(simpleParams)}`;
|
|
3605
|
+
}
|
|
3606
|
+
return null;
|
|
3607
|
+
}
|
|
3608
|
+
|
|
3489
3609
|
function createChainIdMiddleware(chainId) {
|
|
3490
3610
|
return (req, res, next, end) => {
|
|
3491
3611
|
if (req.method === "eth_chainId") {
|
|
@@ -3528,7 +3648,9 @@ function createJsonRpcClient(providerConfig, networkConfig) {
|
|
|
3528
3648
|
// No need for the following middlewares for web because all browser sessions are quite short lived and each session is limited to scope of a window/tab
|
|
3529
3649
|
// createBlockRefRewriteMiddleware({ blockTracker }),
|
|
3530
3650
|
// createBlockCacheMiddleware({ blockTracker }),
|
|
3531
|
-
|
|
3651
|
+
createInflightCacheMiddleware({
|
|
3652
|
+
cacheIdentifierForRequest
|
|
3653
|
+
}),
|
|
3532
3654
|
// createBlockTrackerInspectorMiddleware({ blockTracker }),
|
|
3533
3655
|
fetchMiddleware]);
|
|
3534
3656
|
return {
|
|
@@ -4262,7 +4384,10 @@ class PreferencesController extends BasePreferencesController {
|
|
|
4262
4384
|
}
|
|
4263
4385
|
async patchNewTx(tx, address) {
|
|
4264
4386
|
var _this$getAddressState2;
|
|
4265
|
-
const formattedTx = formatPastTx(
|
|
4387
|
+
const formattedTx = formatPastTx({
|
|
4388
|
+
transaction: tx,
|
|
4389
|
+
blockExplorerUrl: this.getBlockExplorerUrl()
|
|
4390
|
+
});
|
|
4266
4391
|
const storePastTx = ((_this$getAddressState2 = this.getAddressState(address)) === null || _this$getAddressState2 === void 0 ? void 0 : _this$getAddressState2.formattedPastTransactions) || [];
|
|
4267
4392
|
const duplicateIndex = storePastTx.findIndex(x => x.transaction_hash === tx.transaction_hash && x.chainId === tx.chain_id);
|
|
4268
4393
|
if (tx.status === TransactionStatus.submitted || tx.status === TransactionStatus.confirmed) {
|
|
@@ -4308,7 +4433,13 @@ class PreferencesController extends BasePreferencesController {
|
|
|
4308
4433
|
selectedAddress,
|
|
4309
4434
|
chainId: this.getProviderConfig().chainId
|
|
4310
4435
|
});
|
|
4311
|
-
const finalEthScanTxn = await addEtherscanTransactions(
|
|
4436
|
+
const finalEthScanTxn = await addEtherscanTransactions({
|
|
4437
|
+
txn: etherscanTxn,
|
|
4438
|
+
lowerCaseSelectedAddress,
|
|
4439
|
+
provider: this.provider,
|
|
4440
|
+
chainId,
|
|
4441
|
+
blockExplorerUrl: this.getBlockExplorerUrl()
|
|
4442
|
+
});
|
|
4312
4443
|
log.info("Formatted Etherscan Response", finalEthScanTxn);
|
|
4313
4444
|
this.updateState({
|
|
4314
4445
|
etherscanTransactions: finalEthScanTxn
|
|
@@ -4496,17 +4627,29 @@ class PreferencesController extends BasePreferencesController {
|
|
|
4496
4627
|
}, []);
|
|
4497
4628
|
return [...supported, ...custom];
|
|
4498
4629
|
}
|
|
4630
|
+
getBlockExplorerUrl() {
|
|
4631
|
+
const supportedNetworks = this.getChainOptions();
|
|
4632
|
+
const network = supportedNetworks.find(x => x.chainId === this.getProviderConfig().chainId);
|
|
4633
|
+
if (!network) return "";
|
|
4634
|
+
return `${network.blockExplorerUrl}`;
|
|
4635
|
+
}
|
|
4499
4636
|
async calculatePastTx(txs, address) {
|
|
4500
4637
|
const pastTx = [];
|
|
4501
4638
|
const pendingTx = [];
|
|
4502
4639
|
const lowerCaseSelectedAddress = address.toLowerCase();
|
|
4640
|
+
const supportedNetworks = this.getChainOptions(address);
|
|
4641
|
+
const supportedNetwork = supportedNetworks.find(x => x.chainId === this.getProviderConfig().chainId);
|
|
4503
4642
|
for (const x of txs) {
|
|
4504
4643
|
var _x$to;
|
|
4505
|
-
if (
|
|
4644
|
+
if ((supportedNetwork === null || supportedNetwork === void 0 ? void 0 : supportedNetwork.chainId) === x.chain_id && x.to && x.from && (lowerCaseSelectedAddress === x.from.toLowerCase() || lowerCaseSelectedAddress === ((_x$to = x.to) === null || _x$to === void 0 ? void 0 : _x$to.toLowerCase()))) {
|
|
4506
4645
|
if (x.status !== "confirmed") {
|
|
4507
4646
|
pendingTx.push(x);
|
|
4508
4647
|
} else {
|
|
4509
|
-
const finalObject = formatPastTx(
|
|
4648
|
+
const finalObject = formatPastTx({
|
|
4649
|
+
transaction: x,
|
|
4650
|
+
lowerCaseSelectedAddress,
|
|
4651
|
+
blockExplorerUrl: this.getBlockExplorerUrl()
|
|
4652
|
+
});
|
|
4510
4653
|
pastTx.push(finalObject);
|
|
4511
4654
|
}
|
|
4512
4655
|
}
|
|
@@ -4514,7 +4657,11 @@ class PreferencesController extends BasePreferencesController {
|
|
|
4514
4657
|
const pendingTxPromises = pendingTx.map(x => getEthTxStatus(x.transaction_hash, this.provider).catch(error => log.error(error)));
|
|
4515
4658
|
const resolvedTxStatuses = await Promise.all(pendingTxPromises);
|
|
4516
4659
|
for (const [index, element] of pendingTx.entries()) {
|
|
4517
|
-
const finalObject = formatPastTx(
|
|
4660
|
+
const finalObject = formatPastTx({
|
|
4661
|
+
transaction: element,
|
|
4662
|
+
lowerCaseSelectedAddress,
|
|
4663
|
+
blockExplorerUrl: this.getBlockExplorerUrl()
|
|
4664
|
+
});
|
|
4518
4665
|
finalObject.status = resolvedTxStatuses[index] || TransactionStatus.submitted;
|
|
4519
4666
|
pastTx.push(finalObject);
|
|
4520
4667
|
if (lowerCaseSelectedAddress === element.from.toLowerCase() && finalObject.status && finalObject.status !== element.status) this.patchPastTx({
|