Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
b83717a
impl trending tokens
sonytooo Jun 23, 2026
0ee2c23
remove redundnat comments
sonytooo Jun 24, 2026
52fdd1d
fix: conflicts
sonytooo Jul 7, 2026
a75a77b
fix: conflicts
sonytooo Jul 7, 2026
99fe2e6
fixes
sonytooo Jul 7, 2026
1ef0747
revert temp url
sonytooo Jul 8, 2026
60427b8
refacotr(trending): remove duplicate properties
JIOjosBG Jul 8, 2026
6f9abfa
fix(trending): update test url
JIOjosBG Jul 8, 2026
a6c96bf
refactor(trending): image field
JIOjosBG Jul 8, 2026
984637b
Merge pull request #2529 from AmbireTech/feature/trending-tokens-trim…
sonytooo Jul 13, 2026
76b121c
Merge branch 'v2' into feature/trending-tokens
sonytooo Jul 22, 2026
ca3c83e
feedback fixes
sonytooo Jul 22, 2026
6168628
Merge branch 'v2' into feature/trending-tokens
sonytooo Jul 22, 2026
d395ae1
refactor: resolvers to handle normalization, stored names to be norma…
PetromirDev Jul 24, 2026
3981cb0
Merge branch 'v2' into feature/trending-tokens
sonytooo Jul 27, 2026
e508b83
feedback fixes
sonytooo Jul 27, 2026
46830d6
preselect toToken on swap and bridge
sonytooo Jul 27, 2026
aa24769
refactor the create new seed phrase flow to allow backing it up later
sonytooo Jul 29, 2026
3994fe1
Merge branch 'v2' into feature/trending-tokens
sonytooo Jul 30, 2026
1b173f2
add: an option to import safe accounts by owner
Oxbobby Jul 30, 2026
61ed8e8
persist toToken if not selected by the user
sonytooo Jul 30, 2026
28f376e
Fixed: owner mismatch now tries the remaining deployed chains before …
Oxbobby Jul 30, 2026
b07fd09
Merge remote-tracking branch 'origin/v2' into improve/name-resolution…
PetromirDev Jul 30, 2026
b4dbb33
Merge pull request #2570 from AmbireTech/improve/name-resolution-norm…
PetromirDev Jul 30, 2026
4e6a6f0
Merge branch 'v2' into feature/trending-tokens
sonytooo Jul 30, 2026
09e3901
Merge pull request #2505 from AmbireTech/feature/trending-tokens
sonytooo Jul 30, 2026
251449f
Merge branch 'v2' into refactoring/create-new-account-flow
sonytooo Jul 30, 2026
d16b24e
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
Oxbobby Jul 30, 2026
b40004a
move getSafeAccountByOwner to the safe lib instead of the controller
Oxbobby Jul 30, 2026
5f360b5
remove resetFindSafesByOwner as we can query for new safes by checkin…
Oxbobby Jul 30, 2026
dde2ae0
when importing account from hardware, first display the EOAs, then st…
Oxbobby Jul 31, 2026
d176ea5
start searching for usedOn networks quicker - after the initial accou…
Oxbobby Jul 31, 2026
5e6f8ff
fix: if smart accounts have failed to be downloaded, allow the user t…
Oxbobby Jul 31, 2026
a77cffe
Merge remote-tracking branch 'origin/release/v2.106' into v2
PetromirDev Jul 31, 2026
8b40723
change(banners): requests and swap+bridge banners have meta.accountAddr
JIOjosBG Jul 31, 2026
1b5f1c4
add: incorporate quicker UI updates when importing safe accounts by o…
Oxbobby Aug 2, 2026
d7e787b
add a resetFindSafesByOwner method to reset the state and prevent fla…
Oxbobby Aug 3, 2026
4c1a09f
on import, always select the newly imported account, if any
Oxbobby Aug 3, 2026
d7acd7f
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
Oxbobby Aug 3, 2026
ce80c96
test(humanizer): enhance test to actually catch regression
JIOjosBG Aug 3, 2026
e636029
Merge pull request #2591 from AmbireTech/fix-humanizer-test-unrecogni…
JIOjosBG Aug 3, 2026
e2b3a72
add: support for NFC keycard
sonytooo Aug 3, 2026
815bd18
Merge pull request #2587 from AmbireTech/fix/banner-flashing-other-acc
JIOjosBG Aug 3, 2026
0446952
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
Oxbobby Aug 4, 2026
2b2552f
migate to being able to do multiple SafeOwnerSearch and keep the cach…
Oxbobby Aug 4, 2026
607e24f
Fx: Trailing-dot hostnames bypassed the dapp phishing checks.
jordan-enev Aug 4, 2026
2055934
Merge branch 'release/v2.106' of github.com:AmbireTech/ambire-common …
superKalo Aug 4, 2026
14455a8
refactor(add-safe-by-owner): current selected owner guard
JIOjosBG Aug 4, 2026
f97233e
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
Oxbobby Aug 4, 2026
092a0ac
fix: common tests + the same-owner debounce never activated so a fixe…
Oxbobby Aug 4, 2026
07c8746
allow upgrading the paymaster sponsorship to erc7677 after the bundle…
Oxbobby Aug 5, 2026
9230f60
fix: a bug where erc7677 was overriden
Oxbobby Aug 5, 2026
058653f
add: gas price estimations to the final userOp for upgrading
Oxbobby Aug 5, 2026
21dbb43
Merge branch 'v2' into refactoring/create-new-account-flow
sonytooo Aug 5, 2026
8c71a1f
Merge pull request #2595 from AmbireTech/feature/nfc-wallets-on-mobile
sonytooo Aug 5, 2026
7e7afbf
Merge pull request #2582 from AmbireTech/feature/import-safe-by-owner
Oxbobby Aug 5, 2026
b58cc0e
feedback fixes
sonytooo Aug 5, 2026
4101235
Merge branch 'v2' into refactoring/create-new-account-flow
sonytooo Aug 5, 2026
9deef1b
Merge pull request #2585 from AmbireTech/refactoring/create-new-accou…
sonytooo Aug 5, 2026
0c6005b
Change: Update session origin docs and dapp url under the tests.
jordan-enev Aug 5, 2026
bb261c6
Merge remote-tracking branch 'origin/v2' into fix/dapp-phishing-prote…
jordan-enev Aug 5, 2026
aead802
Merge pull request #2596 from AmbireTech/fix/dapp-phishing-protection…
superKalo Aug 5, 2026
c4a3be7
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
Oxbobby Aug 6, 2026
02b446b
improve paymaster code by clearing timeouts, placing comments and fix…
Oxbobby Aug 6, 2026
4d9ba31
fix: a wrongly put comment
Oxbobby Aug 6, 2026
1b0877c
Merge pull request #2597 from AmbireTech/feature/paymaster-sponsorshi…
Oxbobby Aug 6, 2026
5bfcdf2
pending tx banner fixes
sonytooo Aug 6, 2026
79e3c60
Merge branch 'main' of github.com:AmbireTech/ambire-common into v2
superKalo Aug 6, 2026
f936763
Changed: bump up the v
superKalo Aug 6, 2026
dad0ceb
add throttled(delayed emits) and implement them in portfolio and acco…
PetromirDev Aug 6, 2026
4489929
refactor: portfolio lookups and reduce formatting
PetromirDev Aug 6, 2026
557fd18
simply fee token index and fix nested loop in portfolio library
PetromirDev Aug 7, 2026
da28f0a
Merge pull request #2601 from AmbireTech/feature/delayed-emits
PetromirDev Aug 7, 2026
d1ebb20
fix tokenProcessing unit tests
PetromirDev Aug 7, 2026
886e9e9
update: agents.md - add rule for comments and setTimeout used to reje…
PetromirDev Aug 7, 2026
7fff2c0
make the default fee speed per-network and staged until broadcast
sonytooo Aug 6, 2026
6528890
fixes
sonytooo Aug 7, 2026
e894b28
nfc card sign multiple txs fixed
sonytooo Aug 7, 2026
93de111
Merge pull request #2604 from AmbireTech/update-agents-md
PetromirDev Aug 7, 2026
e94aaa3
Merge pull request #2602 from AmbireTech/refactor-portfolio-lookups
PetromirDev Aug 7, 2026
8a40150
Merge pull request #2605 from AmbireTech/fee-defaults/v2.107
superKalo Aug 7, 2026
6a739a0
Changed: bump up the v
superKalo Aug 7, 2026
93e7031
Merge branch 'release/v2.107' of github.com:AmbireTech/ambire-common …
superKalo Aug 7, 2026
b9cb54a
fix: WC disconnect issues
sonytooo Aug 10, 2026
b0504f7
Merge pull request #2610 from AmbireTech/fixes/wallet-connect
sonytooo Aug 10, 2026
5400231
merge origin/release/v2.106.4 into release/v2.107
PetromirDev Aug 10, 2026
198a30e
Merge remote-tracking branch 'origin/release/v2.107' into v2
PetromirDev Aug 10, 2026
659ff1b
make the balance decrease warning a banner; refactor all other banner…
Oxbobby Aug 11, 2026
5b9d784
Merge branch 'release/v2.107' of github.com:AmbireTech/ambire-common …
Oxbobby Aug 11, 2026
819544b
fix: calculate correctly the hasSignificantBalanceDecrease
Oxbobby Aug 11, 2026
3d1ef36
fix: a failing signAccountOp test because of changed text
Oxbobby Aug 11, 2026
91f86c3
remove TraceCallDiscoveryStatus.SlowPendingResponse as we don't use i…
Oxbobby Aug 11, 2026
6d49a31
fix: signAccountOp tests because of changed text
Oxbobby Aug 11, 2026
7b6149d
add: a privacy opt out for EIP-7702
Oxbobby Aug 11, 2026
dc7868c
rename erc7702 to eip7702; add an extra canOrHasBecomeSmarter method …
Oxbobby Aug 11, 2026
32823f2
Merge branch 'release/v2.107' of github.com:AmbireTech/ambire-common …
Oxbobby Aug 11, 2026
58aa053
fix: revoking eip-7702 after disabling eip-7702 didn't work - fixed i…
Oxbobby Aug 12, 2026
ca954b9
Merge branch 'v2' of github.com:AmbireTech/ambire-common into fix/fas…
Oxbobby Aug 12, 2026
ca4fd2c
change text from 'Searching for smart accounts' to 'Loading smart acc…
Oxbobby Aug 12, 2026
40d3e0c
Merge pull request #2584 from AmbireTech/fix/faster-hardware-import-u…
Oxbobby Aug 12, 2026
b2f5698
Merge pull request #2614 from AmbireTech/feature/opt-out-7702
Oxbobby Aug 12, 2026
430950f
Merge branch 'release/v2.107' of github.com:AmbireTech/ambire-common …
Oxbobby Aug 12, 2026
f5dfb75
use WARNINGS.significantBalanceDecrease.id instead of a hardcoded nam…
Oxbobby Aug 12, 2026
22bc1ea
Merge pull request #2613 from AmbireTech/fix/refactor-significant-acc…
Oxbobby Aug 12, 2026
133c003
merge release/v2.106.5 into release/v2.107 and bump v to 2.107.3
PetromirDev Aug 12, 2026
811d8bb
exclude the arc operator address from balance calculations as an erro…
Oxbobby Aug 17, 2026
5082ae1
fix: broken balance check test for hyper evm because of missing const
Oxbobby Aug 17, 2026
5e716e9
Merge pull request #2623 from AmbireTech/fix/exclude-operator-address…
superKalo Aug 17, 2026
764de4d
fix(humanizer): 7730 interpolated intent formatting
JIOjosBG Aug 17, 2026
8fc4df0
cahnge(humanizer): no more interpolated text as string
JIOjosBG Aug 17, 2026
91eac2e
merge conflicts from the release branch
Oxbobby Aug 17, 2026
981bcff
fix: show interpolated intent only if available
Oxbobby Aug 17, 2026
4964dd9
Merge pull request #2627 from AmbireTech/fix/7730-show-interpolated-i…
Oxbobby Aug 18, 2026
9642ba5
fix: new Date().getTime() ids are not reliable and conflict in reques…
PetromirDev Aug 18, 2026
794c581
Merge pull request #2629 from AmbireTech/hotfix/conflicting-ids
Oxbobby Aug 18, 2026
9f6a2e9
Merge pull request #2626 from AmbireTech/fix/7730-interpolated-intent
JIOjosBG Aug 18, 2026
d91ab34
Changed: bump up the v
superKalo Aug 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Note: This package does not include compiled JS and TS output in the repository.

### Code quality:
- Code usually runs continuously for long periods of time (especially in browser extension environments), so memory leaks, listeners, and orphaned async processes can accumulate and cause performance, stability, or reliability issues over time.
- Always ensure subscriptions, event listeners, timers and other side effects are properly cleaned up
- Always ensure subscriptions, event listeners, timers and other side effects are properly cleaned up. Even if it's a simple `setTimeout` used to reject a promise, it should be cleared.
- NEVER delete existing comments when updating a code block; update inaccurate comments instead. Delete a comment only if the logic it describes is completely removed or the new logic is entirely self-explanatory
- NEVER swallow errors; log them and handle appropriately.
- NEVER modify git config or run destructive git operations
Expand All @@ -38,6 +38,7 @@ Note: This package does not include compiled JS and TS output in the repository.
- Avoid TypeScript casts when possible. Prefer narrowing with if statements, discriminated unions, assertion functions, and type guards. Cast only at trusted boundaries, and keep it local
- Avoid regex for parsing strings or business logic. Prefer explicit parsing, small helper functions, existing parsers or available library functions.
- All warnings, errors, and other user-facing strings (controller `errors`/banners, e.g. `signAccountOp.ts`, `swapAndBridge.ts`; humanized strings in `src/libs/humanizer`, `src/libs/errorHumanizer`) must be phrased in plain language a non-technical user can understand. NEVER assume Web3/blockchain knowledge — avoid unexplained jargon (e.g. "RPC", "nonce", "gas limit", "Paymaster", "Bundler", "EOA", "Smart Account", "delegatecall", "calldata", "simulation failed") and instead describe the real-world action, cause, or risk in plain terms (e.g. "a pending transaction" instead of "nonce too low", "insufficient funds to cover the fee" instead of "low gas")
- Comments of reusable functions, types and constants should be public to allow reading them on hover (but don't edit existing comments that are outside of the scope of the task).

## Tests:
- ALWAYS write test cases that cover positive, negative, edge cases and security implications of the code you change or add.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.106.5",
"version": "2.107.4",
"name": "ambire-common",
"description": "Common ground for the Ambire apps",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions src/classes/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ export class Session {

constructor({ tabId, windowId, url, wcTopic, frameId, topFrameUrl }: SessionInitProps = {}) {
if (url) {
// SECURITY: `origin` must stay exactly what the browser/WebView reports, trailing dot and
// all - it is later compared byte-for-byte against the page's own read-only `location.origin`
// before a response or broadcast is delivered to it (see the mobile WebView's origin gate).
// A live, unmodified page cannot be "canonicalized" - only our copy of its origin could be -
// so normalizing it here would make that comparison fail for a legitimate page and silently
// drop data meant for it. `id` (below) is the canonicalized identity that every phishing and
// permission check resolves against; do not canonicalize `origin` to "fix" that too.
this.origin = new URL(url).origin
} else {
this.origin = 'internal'
Expand Down
6 changes: 6 additions & 0 deletions src/consts/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export interface FeatureFlags {
* will need an EOA account just like using a Safe)
*/
erc4337: boolean
/**
* Allow the user to opt out of upgrading EOA accounts through ERC-7702.
* Existing onchain delegations are not revoked when this is disabled.
*/
eip7702: boolean
/**
* Off by default for privacy: passively bulk-resolving ENS/Namoshi for all
* accounts links them together. When enabled, the wallet keeps every account's
Expand All @@ -32,6 +37,7 @@ export const defaultFeatureFlags: FeatureFlags = {
tokenAndDefiAutoDiscovery: true,
apiForFunctionSelectors: true,
erc4337: true,
eip7702: true,
keepEnsProfilesUpToDate: false,
// @TODO: Introduce a setting and flip to false
namoshiDomains: true,
Expand Down
3 changes: 2 additions & 1 deletion src/consts/hardwareWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const HARDWARE_WALLET_DEVICE_NAMES: { [key in ExternalKey['type']]: strin
ledger: 'Ledger',
trezor: 'Trezor',
lattice: 'GridPlus',
qr: 'QR-based'
qr: 'QR-based',
nfc: 'NFC-based'
}
3 changes: 3 additions & 0 deletions src/consts/intervals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export const BLACKLIST_UPDATE_INTERVAL = 8 * 60 * 60 * 1000 // 8 hrs
export const PHISHING_INACTIVE_UPDATE_INTERVAL = 6 * 60 * 60 * 1000 // 6 hrs
export const PHISHING_ACTIVE_UPDATE_INTERVAL = 15 * 60 * 1000 // 15 minutes
export const PHISHING_FAILED_TO_GET_UPDATE_INTERVAL = 600000 // 10 minutes
export const TRENDING_TOKENS_ACTIVE_UPDATE_INTERVAL = 10 * 60 * 1000 // 10 minutes
export const TRENDING_TOKENS_INACTIVE_UPDATE_INTERVAL = 4 * 60 * 60 * 1000 // 4 hours
export const TRENDING_TOKENS_FAILED_UPDATE_INTERVAL = 60 * 1000 // 1 minute
export const ESTIMATE_UPDATE_INTERVAL = 30000
export const GAS_PRICE_UPDATE_INTERVAL = 12000
export const FETCH_SAFE_TXNS = 3 * 60 * 1000 // 3 minutes
3 changes: 3 additions & 0 deletions src/consts/safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export const SAFE_NETWORKS = [

export const SAFE_API_TIMEOUT_MS = 15000

// Keep Safe Transaction Service requests below its bulk request limits.
export const SAFE_API_BATCH_SIZE = 4

/**
* SimulateTxAccessor addresses by Safe version.
*/
Expand Down
13 changes: 3 additions & 10 deletions src/consts/signAccountOp/errorHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,23 @@ const ERRORS = {
const WARNINGS: Record<
| 'significantBalanceDecrease'
| 'unknownToken'
| 'possibleBalanceDecrease'
| 'feeTokenPriceUnavailable'
| 'v1Acc'
| 'safeDelegateCall',
Warning
> = {
significantBalanceDecrease: {
id: 'significantBalanceDecrease',
title: 'Significant Account Balance Decrease',
text: 'The transaction you are about to sign will significantly decrease your account balance. Please review the transaction details carefully.',
promptBefore: ['sign']
title: 'Significant balance decrease detected',
text: 'Our checks indicate this transaction may significantly reduce your account balance.',
secondaryText: 'May be inaccurate when moving funds to another network or providing liquidity.'
},
unknownToken: {
id: 'unknownToken',
title: 'Unknown token detected',
text: 'The transaction you are about to sign contains an unknown token. Please review carefully, as this token may be misleading.',
promptBefore: ['sign']
},
possibleBalanceDecrease: {
id: 'possibleBalanceDecrease',
title: 'Significant Account Balance Decrease (Possibly Inaccurate)',
text: 'The transaction you are about to sign may significantly decrease your account balance. However, due to temporary issues in discovering new portfolio tokens, this information might not be fully accurate. Please review the transaction details carefully.',
promptBefore: ['sign']
},
feeTokenPriceUnavailable: {
id: 'feeTokenPriceUnavailable',
title: 'Unable to estimate the transaction fee in USD.'
Expand Down
134 changes: 132 additions & 2 deletions src/controllers/accountPicker/accountPicker.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Wallet } from 'ethers'

import { describe, expect, test } from '@jest/globals'
import { describe, expect, jest, test } from '@jest/globals'

import { suppressConsoleBeforeEach } from '../../../test/helpers/console'
import { suppressConsole, suppressConsoleBeforeEach } from '../../../test/helpers/console'
import { makeMainController } from '../../../test/helpers/mainController'
import { DEFAULT_ACCOUNT_LABEL } from '../../consts/account'
import {
Expand Down Expand Up @@ -149,6 +149,136 @@ describe('AccountPicker', () => {
expect(controller.accountsOnPage.filter((a) => !isSmartAccount(a.account))).toHaveLength(5)
})

test('should update basic account usage while smart accounts are still loading', async () => {
const { controller } = await prepareTest()
const pageSize = 5
const keyIterator = new KeyIterator(process.env.SEED)
const retrieve = keyIterator.retrieve.bind(keyIterator)
let resolveSmartAccountKeys: (keys: string[]) => void = () => {}
const smartAccountKeysPromise = new Promise<string[]>((resolve) => {
resolveSmartAccountKeys = resolve
})

jest.spyOn(keyIterator, 'retrieve').mockImplementation((indices, hdPathTemplate) => {
if ((indices[0]?.from || 0) >= SMART_ACCOUNT_SIGNER_KEY_DERIVATION_OFFSET) {
return smartAccountKeysPromise
}

return retrieve(indices, hdPathTemplate)
})

controller.setInitParams({
keyIterator,
pageSize,
hdPathTemplate: BIP44_STANDARD_DERIVATION_TEMPLATE,
shouldGetAccountsUsedOnNetworks: false,
shouldSearchForLinkedAccounts: false,
shouldAddNextAccountAutomatically: false
})
await controller.init()

const setPagePromise = controller.setPage({ page: 1 })

while (!controller.smartAccountsLoading) await wait(0)
await wait(0)

expect(controller.accountsLoading).toBe(false)
expect(controller.accountsOnPage).toHaveLength(pageSize)
expect(controller.accountsOnPage.every((a) => !isSmartAccount(a.account))).toBe(true)
expect(controller.accountsOnPage.every((a) => a.account.usedOnNetworks === null)).toBe(true)

controller.selectAccount(controller.accountsOnPage[0]!.account)
expect(controller.selectedAccounts).toHaveLength(1)

resolveSmartAccountKeys(
key1to11BasicAccUsedForSmartAccKeysOnlyPublicAddresses.slice(0, pageSize)
)
await setPagePromise

expect(controller.smartAccountsLoading).toBe(false)
expect(controller.accountsOnPage).toHaveLength(pageSize + 1)
expect(controller.selectedAccounts).toHaveLength(1)
})

test('should keep basic accounts available when smart account retrieval fails', async () => {
const { controller } = await prepareTest()
const pageSize = 5
const keyIterator = new KeyIterator(process.env.SEED)
const retrieve = keyIterator.retrieve.bind(keyIterator)

jest.spyOn(keyIterator, 'retrieve').mockImplementation((indices, hdPathTemplate) => {
if ((indices[0]?.from || 0) >= SMART_ACCOUNT_SIGNER_KEY_DERIVATION_OFFSET) {
return Promise.reject(new Error('Smart account key retrieval failed'))
}

return retrieve(indices, hdPathTemplate)
})

controller.setInitParams({
keyIterator,
pageSize,
hdPathTemplate: BIP44_STANDARD_DERIVATION_TEMPLATE,
shouldGetAccountsUsedOnNetworks: false,
shouldSearchForLinkedAccounts: false,
shouldAddNextAccountAutomatically: false
})
await controller.init()
const { restore } = suppressConsole()
await controller.setPage({ page: 1 })
restore()

expect(controller.accountsLoading).toBe(false)
expect(controller.smartAccountsLoading).toBe(false)
expect(controller.accountsOnPage).toHaveLength(pageSize)
expect(controller.pageError).toBeNull()
expect(controller.emittedErrors.at(-1)?.level).toBe('minor')
expect(controller.emittedErrors.at(-1)?.message).toBe(
'We could not finish loading smart accounts. You can still import the accounts already shown.'
)

controller.selectAccount(controller.accountsOnPage[0]!.account)
expect(controller.selectedAccounts).toHaveLength(1)
})

test('should ignore smart accounts retrieved after the account picker is reset', async () => {
const { controller } = await prepareTest()
const keyIterator = new KeyIterator(process.env.SEED)
const retrieve = keyIterator.retrieve.bind(keyIterator)
let resolveSmartAccountKeys: (keys: string[]) => void = () => {}
const smartAccountKeysPromise = new Promise<string[]>((resolve) => {
resolveSmartAccountKeys = resolve
})

jest.spyOn(keyIterator, 'retrieve').mockImplementation((indices, hdPathTemplate) => {
if ((indices[0]?.from || 0) >= SMART_ACCOUNT_SIGNER_KEY_DERIVATION_OFFSET) {
return smartAccountKeysPromise
}

return retrieve(indices, hdPathTemplate)
})

controller.setInitParams({
keyIterator,
pageSize: 5,
hdPathTemplate: BIP44_STANDARD_DERIVATION_TEMPLATE,
shouldGetAccountsUsedOnNetworks: false,
shouldSearchForLinkedAccounts: false,
shouldAddNextAccountAutomatically: false
})
await controller.init()

const setPagePromise = controller.setPage({ page: 1 })
while (!controller.smartAccountsLoading) await wait(0)

await controller.reset()
resolveSmartAccountKeys(key1to11BasicAccUsedForSmartAccKeysOnlyPublicAddresses.slice(0, 5))
await setPagePromise

expect(controller.isInitialized).toBe(false)
expect(controller.smartAccountsLoading).toBe(false)
expect(controller.accountsOnPage).toHaveLength(0)
})

test('should find linked accounts', async () => {
const { controller } = await prepareTest()
const keyIterator = new KeyIterator(process.env.SEED)
Expand Down
Loading
Loading