Skip to content

Commit 5919986

Browse files
authored
Merge pull request #1941 from AmbireTech/config/revert-87e5a81e75059ff2f8d7ccfdb667bcf4f3d37e12
Config / Revert 87e5a81 (that reverted merging the `v2` branch in the `release/v2.80` branch)
2 parents 1bfaf49 + baea60e commit 5919986

50 files changed

Lines changed: 869 additions & 877 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

contracts/compiled/BalanceGetter.json

Lines changed: 75 additions & 3 deletions
Large diffs are not rendered by default.

contracts/deployless/BalanceGetter.sol

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ contract BalanceGetter is Simulation {
2121
uint8 decimals;
2222
bytes error;
2323
}
24+
struct BalanceInfo {
25+
uint256 amount;
26+
bytes error;
27+
}
2428
struct BalancesAtNonce {
2529
TokenInfo[] balances;
2630
uint nonce;
@@ -36,6 +40,13 @@ contract BalanceGetter is Simulation {
3640
info.decimals = token.decimals();
3741
}
3842

43+
function getERC20TokenBalance(
44+
IAmbireAccount account,
45+
IERC20 token
46+
) external view returns (BalanceInfo memory info) {
47+
info.amount = token.balanceOf(address(account));
48+
}
49+
3950
function getBalances(
4051
IAmbireAccount account,
4152
address[] calldata tokenAddrs
@@ -64,6 +75,27 @@ contract BalanceGetter is Simulation {
6475
return (results, gasleft(), blockNumber);
6576
}
6677

78+
function getBalancesOf(
79+
IAmbireAccount account,
80+
address[] calldata tokenAddrs
81+
) public view returns (BalanceInfo[] memory) {
82+
uint len = tokenAddrs.length;
83+
BalanceInfo[] memory results = new BalanceInfo[](len);
84+
85+
for (uint256 i = 0; i < len; i++) {
86+
if (tokenAddrs[i] == address(0)) {
87+
results[i] = BalanceInfo(address(account).balance, bytes(''));
88+
} else {
89+
try this.getERC20TokenBalance(account, IERC20(tokenAddrs[i])) returns (BalanceInfo memory balanceInfo) {
90+
results[i] = balanceInfo;
91+
} catch (bytes memory e) {
92+
results[i].error = e.length > 0 ? e : bytes('unkn');
93+
}
94+
}
95+
}
96+
return results;
97+
}
98+
6799
// Compare the tokens balances before (balancesA) and after simulation (balancesB)
68100
// and return the delta (with simulation)
69101
function getDelta(

src/consts/intervals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export const ACTIVITY_REFRESH_INTERVAL = 5000 // 5 seconds
44
export const ACTIVE_EXTENSION_DEFI_POSITIONS_UPDATE_INTERVAL = 300000 // 5 minutes
55
export const ACTIVE_EXTENSION_PORTFOLIO_UPDATE_INTERVAL = 2 * 60 * 1000 // 2 minutes
66
export const INACTIVE_EXTENSION_PORTFOLIO_UPDATE_INTERVAL = 600000 // 10 minutes
7-
export const SMART_ACCOUNT_IDENTITY_RETRY_INTERVAL = 900000 // 15 minutes
8-
export const VIEW_ONLY_ACCOUNT_IDENTITY_GET_INTERVAL = 900000 // 15 minutes
7+
export const SMART_ACCOUNT_IDENTITY_RETRY_INTERVAL = 300000 // 5 minutes
8+
export const VIEW_ONLY_ACCOUNT_IDENTITY_GET_INTERVAL = 300000 // 5 minutes
99
export const ACCOUNT_STATE_PENDING_INTERVAL = 8000 // 8 seconds
1010
export const ACCOUNT_STATE_STAND_BY_INTERVAL = 300000 // 5 minutes
1111
export const NETWORKS_UPDATE_INTERVAL = 8 * 60 * 60 * 1000

src/controllers/accountPicker/accountPicker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ export class AccountPickerController extends EventEmitter implements IAccountPic
516516
// should never happen
517517
if (accountsOnPageWithThisAcc.length === 0) {
518518
const message = `accountPicker: account ${account.addr} was not found in the accountsOnPage.`
519-
this.emitError({ message, level: 'silent', sendCrashReport: true, error: new Error(message) })
519+
this.emitError({ message, level: 'silent', error: new Error(message) })
520520

521521
return []
522522
}
@@ -935,7 +935,7 @@ export class AccountPickerController extends EventEmitter implements IAccountPic
935935
// Should never happen
936936
if (!nextAccount) {
937937
const message = 'accountPicker: selectNextAccount called, but no next account found.'
938-
this.emitError({ message, level: 'silent', sendCrashReport: true, error: new Error(message) })
938+
this.emitError({ message, level: 'silent', error: new Error(message) })
939939
}
940940

941941
this.selectNextAccountStatus = 'SUCCESS'
@@ -989,7 +989,7 @@ export class AccountPickerController extends EventEmitter implements IAccountPic
989989
// called - there is a check if the keyIterator exists.
990990
if (!this.keyIterator) {
991991
const message = 'accountPicker: #deriveAccounts called, but keyIterator was missing'
992-
this.emitError({ message, level: 'silent', sendCrashReport: true, error: new Error(message) })
992+
this.emitError({ message, level: 'silent', error: new Error(message) })
993993

994994
return []
995995
}

src/controllers/accounts/accounts.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { IProvidersController } from '../../interfaces/provider'
2828
import { IStorageController } from '../../interfaces/storage'
2929
import {
3030
getUniqueAccountsArray,
31-
isAmbireV1LinkedAccount,
3231
isAmbireV2Account,
3332
isSmartAccount
3433
} from '../../libs/account/account'
@@ -53,8 +52,19 @@ export class AccountsController extends EventEmitter implements IAccountsControl
5352

5453
#callRelayer: Function
5554

55+
/**
56+
* Creating Ambire smart account identity is needed but not critical, user
57+
* is still able to interact and transfer funds with a smart account one.
58+
* So schedule an interval to retry after import, allowing the user
59+
* to import the account even if the first Relayer identity create call fails.
60+
*/
5661
#smartAccountIdentityCreateInterval: IRecurringTimeout
5762

63+
/**
64+
* Getting view-only accounts’ identity is needed but not critical,
65+
* so schedule an interval to retry after import, allowing the user
66+
* to import the account even if the first Relayer identity fetch fails.
67+
*/
5868
#viewOnlyAccountGetIdentityInterval: IRecurringTimeout
5969

6070
#accounts: Account[] = []
@@ -102,19 +112,12 @@ export class AccountsController extends EventEmitter implements IAccountsControl
102112
this.#onAccountStateUpdate = onAccountStateUpdate
103113
this.#callRelayer = relayerCall.bind({ url: relayerUrl, fetch })
104114

105-
// Getting view-only accounts’ identity is needed but not critical,
106-
// so schedule an interval to retry after import, allowing the user
107-
// to import the account even if the first Relayer identity fetch fails.
108115
this.#viewOnlyAccountGetIdentityInterval = new RecurringTimeout(
109116
this.setViewOnlyAccountIdentitiesIfNeeded.bind(this),
110117
VIEW_ONLY_ACCOUNT_IDENTITY_GET_INTERVAL,
111118
this.emitError.bind(this)
112119
)
113120

114-
// Creating Ambire smart account identity is needed but not critical, user
115-
// is still able to interact and transfer funds with a smart account one.
116-
// So schedule an interval to retry after import, allowing the user
117-
// to import the account even if the first Relayer identity create call fails.
118121
this.#smartAccountIdentityCreateInterval = new RecurringTimeout(
119122
this.createSmartAccountIdentitiesIfNeeded.bind(this),
120123
SMART_ACCOUNT_IDENTITY_RETRY_INTERVAL,

src/controllers/continuousUpdates/continuousUpdates.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ export class ContinuousUpdatesController extends EventEmitter {
168168
? this.#main.activity.broadcastedButNotConfirmed[this.#main.selectedAccount.account.addr]
169169
: []
170170
if (selectedAccountBroadcastedButNotConfirmed.length) return
171-
await this.#main.updateSelectedAccountPortfolio({ maxDataAgeMs: 60 * 1000 })
171+
await this.#main.updateSelectedAccountPortfolio({
172+
maxDataAgeMs: 60 * 1000,
173+
maxDataAgeMsUnused: 60 * 60 * 1000
174+
})
172175
}
173176

174177
async #updateAccountsOpsStatuses() {

src/controllers/estimation/estimation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class EstimationController extends EventEmitter {
122122
// NOTE: at some point we should check all the "?" signs below and if
123123
// an error pops out, we should notify the user about it
124124
let networkFeeTokens =
125-
this.#portfolio.getLatestPortfolioState(op.accountAddr)?.[op.chainId.toString()]?.result
125+
this.#portfolio.getAccountPortfolioState(op.accountAddr)?.[op.chainId.toString()]?.result
126126
?.feeTokens ?? []
127127

128128
// This could happen only in a race when a NOT currently selected account is
@@ -132,11 +132,11 @@ export class EstimationController extends EventEmitter {
132132
if (networkFeeTokens.length === 0) {
133133
await this.#portfolio.updateSelectedAccount(op.accountAddr, [network])
134134
networkFeeTokens =
135-
this.#portfolio.getLatestPortfolioState(op.accountAddr)?.[op.chainId.toString()]?.result
135+
this.#portfolio.getAccountPortfolioState(op.accountAddr)?.[op.chainId.toString()]?.result
136136
?.feeTokens ?? []
137137
}
138138

139-
const gasTankResult = this.#portfolio.getLatestPortfolioState(op.accountAddr)?.gasTank?.result
139+
const gasTankResult = this.#portfolio.getAccountPortfolioState(op.accountAddr)?.gasTank?.result
140140
const gasTankFeeTokens = isPortfolioGasTankResult(gasTankResult)
141141
? gasTankResult.gasTankTokens
142142
: []

src/controllers/main/main.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,14 @@ export class MainController extends EventEmitter implements IMainController {
557557

558558
if (selectedAccountAddr) {
559559
const FIVE_MINUTES = 1000 * 60 * 5
560+
const ONE_HOUR = 1000 * 60 * 60
560561
this.domains.batchReverseLookup(this.accounts.accounts.map((a) => a.addr))
561562

562563
if (!(this.activity.broadcastedButNotConfirmed[selectedAccountAddr] || []).length) {
563-
this.updateSelectedAccountPortfolio({ maxDataAgeMs: FIVE_MINUTES })
564+
this.updateSelectedAccountPortfolio({
565+
maxDataAgeMs: FIVE_MINUTES,
566+
maxDataAgeMsUnused: ONE_HOUR
567+
})
564568
this.defiPositions.updatePositions({ maxDataAgeMs: FIVE_MINUTES })
565569
}
566570

@@ -650,7 +654,8 @@ export class MainController extends EventEmitter implements IMainController {
650654
// will block the UI until these are resolved.
651655
// eslint-disable-next-line @typescript-eslint/no-floating-promises
652656
this.reloadSelectedAccount({
653-
maxDataAgeMs: 5 * 60 * 1000
657+
maxDataAgeMs: 5 * 60 * 1000,
658+
maxDataAgeMsUnused: 60 * 60 * 1000
654659
})
655660
}
656661

@@ -1357,9 +1362,10 @@ export class MainController extends EventEmitter implements IMainController {
13571362
async reloadSelectedAccount(options?: {
13581363
chainIds?: bigint[]
13591364
maxDataAgeMs?: number
1365+
maxDataAgeMsUnused?: number
13601366
isManualReload?: boolean
13611367
}) {
1362-
const { chainIds, isManualReload = false, maxDataAgeMs } = options || {}
1368+
const { chainIds, isManualReload = false, maxDataAgeMsUnused, maxDataAgeMs } = options || {}
13631369
const networksToUpdate = chainIds
13641370
? this.networks.networks.filter((n) => chainIds.includes(n.chainId))
13651371
: undefined
@@ -1385,6 +1391,7 @@ export class MainController extends EventEmitter implements IMainController {
13851391
this.updateSelectedAccountPortfolio({
13861392
networks: networksToUpdate,
13871393
isManualUpdate: isManualReload,
1394+
maxDataAgeMsUnused,
13881395
maxDataAgeMs
13891396
}),
13901397
this.defiPositions.updatePositions({ chainIds, maxDataAgeMs, forceUpdate: isManualReload })
@@ -1401,15 +1408,15 @@ export class MainController extends EventEmitter implements IMainController {
14011408
// and not the selected account portfolio the flag isOffline
14021409
// and the errors of the selected account portfolio should
14031410
// come in the same tick. Otherwise the UI may flash the wrong error.
1404-
const latestState = this.portfolio.getLatestPortfolioState(accountAddr)
1405-
const latestStateKeys = Object.keys(latestState)
1406-
const isAllLoaded = latestStateKeys.every((chainId) => {
1407-
return isNetworkReady(latestState[chainId]) && !latestState[chainId]?.isLoading
1411+
const portfolioState = this.portfolio.getAccountPortfolioState(accountAddr)
1412+
const portfolioStateKeys = Object.keys(portfolioState)
1413+
const isAllLoaded = portfolioStateKeys.every((chainId) => {
1414+
return isNetworkReady(portfolioState[chainId]) && !portfolioState[chainId]?.isLoading
14081415
})
14091416

14101417
// Set isOffline back to false if the portfolio is loading.
14111418
// This is done to prevent the UI from flashing the offline error
1412-
if (!latestStateKeys.length || !isAllLoaded) {
1419+
if (!portfolioStateKeys.length || !isAllLoaded) {
14131420
// Skip unnecessary updates
14141421
if (!this.isOffline) return
14151422

@@ -1418,8 +1425,8 @@ export class MainController extends EventEmitter implements IMainController {
14181425
return
14191426
}
14201427

1421-
const allPortfolioNetworksHaveErrors = latestStateKeys.every((chainId) => {
1422-
const state = latestState[chainId]
1428+
const allPortfolioNetworksHaveErrors = portfolioStateKeys.every((chainId) => {
1429+
const state = portfolioState[chainId]
14231430

14241431
return !!state?.criticalError
14251432
})
@@ -1444,8 +1451,9 @@ export class MainController extends EventEmitter implements IMainController {
14441451
networks?: Network[]
14451452
isManualUpdate?: boolean
14461453
maxDataAgeMs?: number
1454+
maxDataAgeMsUnused?: number
14471455
}) {
1448-
const { networks, maxDataAgeMs, isManualUpdate } = opts || {}
1456+
const { networks, maxDataAgeMs, maxDataAgeMsUnused, isManualUpdate } = opts || {}
14491457

14501458
await this.initialLoadPromise
14511459
if (!this.selectedAccount.account) return
@@ -1467,7 +1475,7 @@ export class MainController extends EventEmitter implements IMainController {
14671475
states: await this.accounts.getOrFetchAccountStates(this.selectedAccount.account.addr)
14681476
}
14691477
: undefined,
1470-
{ maxDataAgeMs, isManualUpdate }
1478+
{ maxDataAgeMs, maxDataAgeMsUnused, isManualUpdate }
14711479
)
14721480
this.#updateIsOffline()
14731481
}

0 commit comments

Comments
 (0)