@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.
- package/dist/ethereumControllers.cjs.js +50 -65
- package/dist/ethereumControllers.cjs.js.map +1 -1
- package/dist/ethereumControllers.esm.js +53 -60
- package/dist/ethereumControllers.esm.js.map +1 -1
- package/dist/ethereumControllers.umd.min.js +1 -1
- package/dist/ethereumControllers.umd.min.js.LICENSE.txt +2 -0
- package/dist/ethereumControllers.umd.min.js.map +1 -1
- package/dist/types/Account/AccountTrackerController.d.ts +3 -0
- package/dist/types/Preferences/PreferencesController.d.ts +5 -19
- package/package.json +6 -6
- package/src/Account/AccountTrackerController.ts +19 -6
- package/src/Preferences/PreferencesController.ts +26 -76
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
-
import { BaseController, formatSmallNumbers, addressSlicer, ACTIVITY_ACTION_RECEIVE, ACTIVITY_ACTION_SEND, significantDigits, TransactionStatus, BaseBlockTracker, timeout, BaseCurrencyController, BaseKeyringController, randomId, PROVIDER_JRPC_METHODS, createFetchMiddleware, createSwappableProxy, createEventEmitterProxy, BasePreferencesController,
|
|
3
|
+
import { BaseController, formatSmallNumbers, addressSlicer, ACTIVITY_ACTION_RECEIVE, ACTIVITY_ACTION_SEND, significantDigits, TransactionStatus, BaseBlockTracker, timeout, BaseCurrencyController, BaseKeyringController, randomId, PROVIDER_JRPC_METHODS, createFetchMiddleware, createSwappableProxy, createEventEmitterProxy, BasePreferencesController, TX_EVENTS, TRANSACTION_TYPES, BaseTransactionStateManager, transactionMatchesNetwork as transactionMatchesNetwork$1 } from '@toruslabs/base-controllers';
|
|
4
4
|
import { Mutex } from 'async-mutex';
|
|
5
5
|
import { BrowserProvider, toQuantity, Contract, SigningKey, Wallet, isHexString as isHexString$1, JsonRpcProvider, Interface, keccak256 } from 'ethers';
|
|
6
6
|
import log from 'loglevel';
|
|
@@ -851,14 +851,6 @@ class AccountTrackerController extends BaseController {
|
|
|
851
851
|
this.provider = provider;
|
|
852
852
|
this.blockTracker = blockTracker;
|
|
853
853
|
this.ethersProvider = new BrowserProvider(this.provider, "any");
|
|
854
|
-
|
|
855
|
-
// Initiate block tracker internal tracking.
|
|
856
|
-
this.blockTracker.on("latest", block => {
|
|
857
|
-
this.configure({
|
|
858
|
-
_currentBlock: block
|
|
859
|
-
});
|
|
860
|
-
this.refresh();
|
|
861
|
-
});
|
|
862
854
|
this.getIdentities = getIdentities;
|
|
863
855
|
this.getCurrentChainId = getCurrentChainId;
|
|
864
856
|
onPreferencesStateChange(() => {
|
|
@@ -866,6 +858,24 @@ class AccountTrackerController extends BaseController {
|
|
|
866
858
|
const refreshNeeded = this.syncAccounts();
|
|
867
859
|
if (refreshNeeded) this.refresh();
|
|
868
860
|
});
|
|
861
|
+
this.blockTrackerListener = this.blockTrackerListener.bind(this);
|
|
862
|
+
}
|
|
863
|
+
blockTrackerListener(block) {
|
|
864
|
+
this.configure({
|
|
865
|
+
_currentBlock: block
|
|
866
|
+
});
|
|
867
|
+
this.refresh();
|
|
868
|
+
}
|
|
869
|
+
startPolling() {
|
|
870
|
+
this.stopPolling();
|
|
871
|
+
// Initiate block tracker internal tracking.
|
|
872
|
+
if (Object.keys(this.state.accounts).length > 0) {
|
|
873
|
+
// Adding this listener on block tracker triggers it to start polling.
|
|
874
|
+
this.blockTracker.on("latest", this.blockTrackerListener);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
stopPolling() {
|
|
878
|
+
this.blockTracker.removeListener("latest", this.blockTrackerListener);
|
|
869
879
|
}
|
|
870
880
|
syncAccounts() {
|
|
871
881
|
const {
|
|
@@ -3549,7 +3559,6 @@ class PreferencesController extends BasePreferencesController {
|
|
|
3549
3559
|
config,
|
|
3550
3560
|
state,
|
|
3551
3561
|
provider,
|
|
3552
|
-
blockTracker,
|
|
3553
3562
|
signAuthMessage,
|
|
3554
3563
|
getProviderConfig,
|
|
3555
3564
|
setProviderConfig
|
|
@@ -3569,12 +3578,9 @@ class PreferencesController extends BasePreferencesController {
|
|
|
3569
3578
|
_defineProperty(this, "getProviderConfig", void 0);
|
|
3570
3579
|
_defineProperty(this, "setProviderConfig", void 0);
|
|
3571
3580
|
_defineProperty(this, "provider", void 0);
|
|
3572
|
-
_defineProperty(this, "blockTracker", void 0);
|
|
3573
3581
|
this.provider = provider;
|
|
3574
3582
|
this.getProviderConfig = getProviderConfig;
|
|
3575
3583
|
this.setProviderConfig = setProviderConfig;
|
|
3576
|
-
this.blockTracker = blockTracker;
|
|
3577
|
-
log.info(this.blockTracker);
|
|
3578
3584
|
}
|
|
3579
3585
|
async poll(interval) {
|
|
3580
3586
|
var _this$getAddressState;
|
|
@@ -3604,13 +3610,18 @@ class PreferencesController extends BasePreferencesController {
|
|
|
3604
3610
|
locale = "en-US",
|
|
3605
3611
|
type,
|
|
3606
3612
|
signatures,
|
|
3607
|
-
|
|
3613
|
+
web3AuthClientId,
|
|
3614
|
+
web3AuthNetwork
|
|
3608
3615
|
} = params;
|
|
3609
|
-
await super.init(
|
|
3616
|
+
await super.init({
|
|
3617
|
+
address,
|
|
3618
|
+
userInfo,
|
|
3619
|
+
idToken: jwtToken,
|
|
3610
3620
|
type,
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3621
|
+
metadata: {
|
|
3622
|
+
email: userInfo.email,
|
|
3623
|
+
signatures
|
|
3624
|
+
}
|
|
3614
3625
|
});
|
|
3615
3626
|
const {
|
|
3616
3627
|
aggregateVerifier,
|
|
@@ -3626,17 +3637,21 @@ class PreferencesController extends BasePreferencesController {
|
|
|
3626
3637
|
verifier: aggregateVerifier || verifier,
|
|
3627
3638
|
verifierId,
|
|
3628
3639
|
locale,
|
|
3629
|
-
address
|
|
3640
|
+
address,
|
|
3641
|
+
type,
|
|
3642
|
+
web3AuthNetwork
|
|
3630
3643
|
});
|
|
3631
3644
|
}
|
|
3632
|
-
|
|
3645
|
+
await this.storeUserLogin({
|
|
3633
3646
|
verifier: aggregateVerifier || verifier,
|
|
3634
3647
|
verifierId,
|
|
3635
3648
|
options: {
|
|
3636
3649
|
calledFromEmbed,
|
|
3637
3650
|
rehydrate
|
|
3638
3651
|
},
|
|
3639
|
-
address
|
|
3652
|
+
address,
|
|
3653
|
+
web3AuthClientId,
|
|
3654
|
+
web3AuthNetwork
|
|
3640
3655
|
});
|
|
3641
3656
|
}
|
|
3642
3657
|
getSelectedAddress() {
|
|
@@ -3655,7 +3670,8 @@ class PreferencesController extends BasePreferencesController {
|
|
|
3655
3670
|
default_public_address: defaultPublicAddress,
|
|
3656
3671
|
customNetworks,
|
|
3657
3672
|
customTokens,
|
|
3658
|
-
customNfts
|
|
3673
|
+
customNfts,
|
|
3674
|
+
account_type: accountType
|
|
3659
3675
|
} = user || {};
|
|
3660
3676
|
|
|
3661
3677
|
// update latest data in state.
|
|
@@ -3667,7 +3683,8 @@ class PreferencesController extends BasePreferencesController {
|
|
|
3667
3683
|
defaultPublicAddress: defaultPublicAddress || userPublicAddress,
|
|
3668
3684
|
customTokens,
|
|
3669
3685
|
customNfts,
|
|
3670
|
-
customNetworks
|
|
3686
|
+
customNetworks,
|
|
3687
|
+
accountType: accountType
|
|
3671
3688
|
}, address);
|
|
3672
3689
|
return true;
|
|
3673
3690
|
}
|
|
@@ -3678,13 +3695,8 @@ class PreferencesController extends BasePreferencesController {
|
|
|
3678
3695
|
} finally {
|
|
3679
3696
|
Promise.all([this.getWalletOrders(address).catch(error => {
|
|
3680
3697
|
log.error("unable to fetch wallet orders", error);
|
|
3681
|
-
}), this.getTopUpOrders(address).catch(error => {
|
|
3682
|
-
log.error("unable to fetch top up orders", error);
|
|
3683
3698
|
})]).then(data => {
|
|
3684
|
-
const [walletTx
|
|
3685
|
-
if (paymentTx) {
|
|
3686
|
-
this.calculatePaymentTx(paymentTx, address);
|
|
3687
|
-
}
|
|
3699
|
+
const [walletTx] = data;
|
|
3688
3700
|
// eslint-disable-next-line promise/always-return
|
|
3689
3701
|
if (walletTx && walletTx.length > 0) {
|
|
3690
3702
|
this.updateState({
|
|
@@ -3732,10 +3744,21 @@ class PreferencesController extends BasePreferencesController {
|
|
|
3732
3744
|
async refetchEtherscanTx(address) {
|
|
3733
3745
|
var _this$getAddressState3;
|
|
3734
3746
|
const selectedAddress = address || this.state.selectedAddress;
|
|
3735
|
-
if ((_this$getAddressState3 = this.getAddressState(selectedAddress)) !== null && _this$getAddressState3 !== void 0 && _this$getAddressState3.jwtToken)
|
|
3747
|
+
if ((_this$getAddressState3 = this.getAddressState(selectedAddress)) !== null && _this$getAddressState3 !== void 0 && _this$getAddressState3.jwtToken) {
|
|
3748
|
+
const {
|
|
3749
|
+
chainId
|
|
3750
|
+
} = this.getProviderConfig();
|
|
3751
|
+
if (ETHERSCAN_SUPPORTED_CHAINS.includes(chainId)) {
|
|
3752
|
+
return this.fetchEtherscanTx({
|
|
3753
|
+
selectedAddress,
|
|
3754
|
+
chainId: this.getProviderConfig().chainId
|
|
3755
|
+
});
|
|
3756
|
+
}
|
|
3757
|
+
}
|
|
3736
3758
|
}
|
|
3737
3759
|
async fetchEtherscanTx(parameters) {
|
|
3738
3760
|
try {
|
|
3761
|
+
// TODO: rewrite this api to use chainId
|
|
3739
3762
|
const url = new URL(`${this.config.api}/etherscan`);
|
|
3740
3763
|
Object.keys(parameters).forEach(key => url.searchParams.append(key, parameters[key]));
|
|
3741
3764
|
const response = await get(url.href, this.headers(parameters.selectedAddress));
|
|
@@ -3881,36 +3904,6 @@ class PreferencesController extends BasePreferencesController {
|
|
|
3881
3904
|
return false;
|
|
3882
3905
|
}
|
|
3883
3906
|
}
|
|
3884
|
-
calculatePaymentTx(txs, address) {
|
|
3885
|
-
const accumulator = [];
|
|
3886
|
-
for (const x of txs) {
|
|
3887
|
-
let action = "";
|
|
3888
|
-
const lowerCaseAction = x.action.toLowerCase();
|
|
3889
|
-
if (ACTIVITY_ACTION_TOPUP.includes(lowerCaseAction)) action = ACTIVITY_ACTION_TOPUP;else if (ACTIVITY_ACTION_SEND.includes(lowerCaseAction)) action = ACTIVITY_ACTION_SEND;else if (ACTIVITY_ACTION_RECEIVE.includes(lowerCaseAction)) action = ACTIVITY_ACTION_RECEIVE;
|
|
3890
|
-
accumulator.push({
|
|
3891
|
-
id: x.id,
|
|
3892
|
-
date: new Date(x.date).toDateString(),
|
|
3893
|
-
from: x.from,
|
|
3894
|
-
slicedFrom: x.slicedFrom,
|
|
3895
|
-
action,
|
|
3896
|
-
to: x.to,
|
|
3897
|
-
slicedTo: x.slicedTo,
|
|
3898
|
-
totalAmount: x.totalAmount,
|
|
3899
|
-
totalAmountString: x.totalAmountString,
|
|
3900
|
-
currencyAmount: x.currencyAmount,
|
|
3901
|
-
currencyAmountString: x.currencyAmountString,
|
|
3902
|
-
amount: x.amount,
|
|
3903
|
-
ethRate: x.ethRate,
|
|
3904
|
-
status: x.status.toLowerCase(),
|
|
3905
|
-
etherscanLink: x.etherscanLink || "",
|
|
3906
|
-
blockExplorerLink: "",
|
|
3907
|
-
currencyUsed: x.currencyUsed
|
|
3908
|
-
});
|
|
3909
|
-
}
|
|
3910
|
-
this.updateState({
|
|
3911
|
-
paymentTx: accumulator
|
|
3912
|
-
}, address);
|
|
3913
|
-
}
|
|
3914
3907
|
getChainOptions() {
|
|
3915
3908
|
var _identities$address$c, _identities$address;
|
|
3916
3909
|
let address = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.state.selectedAddress;
|