Skip to content

Commit 27c83b8

Browse files
committed
Merge branch 'v2' into refactor/performance-optimizations-mobile
2 parents e88ae72 + dbfbe62 commit 27c83b8

19 files changed

Lines changed: 108 additions & 124 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.90.4",
2+
"version": "2.91.0",
33
"name": "ambire-common",
44
"description": "Common ground for the Ambire apps",
55
"scripts": {

src/consts/gasTankFeeTokens.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,13 @@ export default [
337337
icon: 'https://assets.coingecko.com/coins/images/17266/small/amWETH_2x.png',
338338
hiddenOnError: true
339339
},
340+
{
341+
address: '0x6440f144b7e50D6a8439336510312d2F54beB01D',
342+
symbol: 'BOLD',
343+
chainId: 1n,
344+
decimals: 18,
345+
icon: 'https://assets.coingecko.com/coins/images/56069/standard/BOLD_logo.png?1748265087'
346+
},
340347
{
341348
address: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
342349
symbol: 'wmatic',

src/consts/safe.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* A non-exclusive list of networks that safe accounts are supported on.
3-
* We will use this list to know where to search for safe accounts
2+
* A non-exclusive list of networks that Safe accounts are supported on.
3+
* We will use this list to know where to search for Safe accounts
44
* and in accordance with the enabled user networks
55
*/
66
export const SAFE_NETWORKS = [
@@ -9,7 +9,7 @@ export const SAFE_NETWORKS = [
99
]
1010

1111
/**
12-
* Information about safe contract addresses by their versions
12+
* Information about Safe contract addresses by their versions
1313
*/
1414
const vOneThree = {
1515
singleton: '0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552'
@@ -25,14 +25,14 @@ export const execTransactionAbi = [
2525
'function execTransaction(address to,uint256 value,bytes calldata data,uint8 operation,uint256 safeTxGas,uint256 baseGas,uint256 gasPrice,address gasToken,address payable refundReceiver,bytes memory signatures)'
2626
]
2727
/**
28-
* In order to do batching, safe needs an extra contract helper called multisend
29-
* This is the latest contract and it's safe to use across versions
28+
* In order to do batching, Safe needs an extra contract helper called multisend
29+
* This is the latest contract and it's Safe to use across versions
3030
*/
3131
export const multiSendAddr = '0x9641d764fc13c8B624c04430C7356C1C7C8102e2'
3232

3333
/**
34-
* In order to do batching, safe needs an extra contract helper called multisend
35-
* This is the latest contract and it's safe to use across versions
34+
* In order to do batching, Safe needs an extra contract helper called multisend
35+
* This is the latest contract and it's Safe to use across versions
3636
*/
3737
export const safeNullOwner = '0x0000000000000000000000000000000000000002'
3838

src/controllers/activity/activity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ export class ActivityController extends EventEmitter implements IActivityControl
489489
const portfoliosToUpdate: PortfoliosToUpdate = {}
490490
const updatedAccountsOps: SubmittedAccountOp[] = []
491491

492-
// we should fetch safe txns again upon failure
492+
// we should fetch Safe txns again upon failure
493493
let shouldFetchSafeTxns = false
494494

495495
// Use this flag to make the auto-refresh slower with the passege of time.
@@ -632,7 +632,7 @@ export class ActivityController extends EventEmitter implements IActivityControl
632632
this.#portfolio.addTokensToBeLearned(foundTokens, accountOp.chainId)
633633
}
634634
} else {
635-
// if the txn resulted in a failure, unresolve all safe txns
635+
// if the txn resulted in a failure, unresolve all Safe txns
636636
// with the same nonce so that the user can retry
637637
const acc = this.#accounts.accounts.find(
638638
(a) => a.addr === accountOp.accountAddr

src/controllers/autoLogin/autoLogin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export class AutoLoginController extends EventEmitter implements IAutoLoginContr
296296
accountKeys: Key[],
297297
account: Account
298298
): 'no-policy' | 'expired' | 'valid-policy' | 'unsupported' {
299-
// disable the auto login for safe accounts
299+
// disable the auto login for Safe accounts
300300
if (account.safeCreation) return 'unsupported'
301301

302302
const accountPolicies = this.getAccountPolicies(parsedSiwe.address)

src/controllers/continuousUpdates/continuousUpdates.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ export class ContinuousUpdatesController extends EventEmitter {
361361
if (!this.#main.selectedAccount.account || !this.#main.selectedAccount.account.safeCreation)
362362
return
363363

364-
// do not make safe requests if the extension is locked
364+
// do not make Safe requests if the extension is locked
365365
if (!this.#main.keystore.isUnlocked) return
366366

367367
const pendingSafeTxns = this.#main.requests.userRequests
@@ -383,7 +383,7 @@ export class ContinuousUpdatesController extends EventEmitter {
383383
if (!pendingSafeTxns.length) return
384384

385385
const confirmed = await this.#main.safe.fetchExecuted(pendingSafeTxns).catch((e) => {
386-
console.log('failed to retrieve executed safe txns')
386+
console.log('failed to retrieve executed Safe txns')
387387
return []
388388
})
389389
if (!confirmed.length) return
@@ -419,14 +419,14 @@ export class ContinuousUpdatesController extends EventEmitter {
419419
fromRequestId: userR.id
420420
})
421421
.catch((e: Error) => {
422-
console.log('could not resolve safe global request')
422+
console.log('could not resolve Safe Global request')
423423
console.log(e)
424424
return e
425425
})
426426
if (commonSuccessHandler instanceof Error) continue
427427

428428
await this.#main.resolveAccountOpRequest(submittedAccountOp, userR.id, false).catch((e) => {
429-
console.log('could not resolve safe global request')
429+
console.log('could not resolve Safe Global request')
430430
console.log(e)
431431
})
432432

src/controllers/main/main.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ export class MainController extends EventEmitter implements IMainController {
10081008
// Error handling on the prev step will notify the user, it's fine to return here
10091009
if (!signedMessage) return
10101010

1011-
// some accounts may not resolve immediately, like a safe acc
1011+
// some accounts may not resolve immediately, like a Safe acc
10121012
if (this.signMessage.status === SignMessageStatus.Done) {
10131013
await this.#resolveSignMessage(signedMessage)
10141014
} else if (this.signMessage.status === SignMessageStatus.Partial) {
@@ -1339,7 +1339,7 @@ export class MainController extends EventEmitter implements IMainController {
13391339
}
13401340

13411341
/**
1342-
* Fetch safe txns from safe global and make them user requests
1342+
* Fetch Safe txns from Safe Global and make them user requests
13431343
* if the selected account is a safe
13441344
*/
13451345
async fetchSafeTxns(chainIds: bigint[] = [], forceRefetch = false) {
@@ -1379,7 +1379,7 @@ export class MainController extends EventEmitter implements IMainController {
13791379
.fetchPending(safeAddr, [firstBatch])
13801380
.catch((e) => {
13811381
console.log(e)
1382-
console.log('failed to retrieve pending safe txns')
1382+
console.log('failed to retrieve pending Safe txns')
13831383
return null
13841384
})
13851385

@@ -1568,7 +1568,7 @@ export class MainController extends EventEmitter implements IMainController {
15681568
})
15691569
}
15701570

1571-
// upon resolving an account op, check all same nonce safe requests and remove them
1571+
// upon resolving an account op, check all same nonce Safe requests and remove them
15721572
const safeRequests = this.requests.getSameNonceSafeRequests(requestId).map((r) => r.id)
15731573

15741574
if (safeRequests.length) {

src/controllers/requests/requests.test.ts

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { describe, expect, test } from '@jest/globals'
22

3-
import { relayerUrl } from '../../../test/config'
43
import { makeMainController } from '../../../test/helpers/mainController'
5-
import { mockUiManager } from '../../../test/helpers/ui'
64
import { Session } from '../../classes/session'
75
import {
86
BenzinUserRequest,
@@ -11,9 +9,7 @@ import {
119
UserRequest
1210
} from '../../interfaces/userRequest'
1311
import { generateUuid } from '../../utils/uuid'
14-
import { EventEmitterRegistryController } from '../eventEmitterRegistry/eventEmitterRegistry'
1512
import { SignAccountOpController } from '../signAccountOp/signAccountOp'
16-
import { RequestsController } from './requests'
1713

1814
const MOCK_SESSION = new Session({ tabId: 1, url: 'https://test-dApp.com' })
1915

@@ -66,12 +62,12 @@ const accounts = [
6662
]
6763

6864
const prepareTest = async () => {
69-
const { uiManager, getWindowId, eventEmitter: event } = mockUiManager()
70-
71-
const { mainCtrl } = await makeMainController(async (storageCtrl) => {
72-
await storageCtrl.set('accounts', accounts)
73-
await storageCtrl.set('selectedAccount', '0x77777777789A8BBEE6C64381e5E89E501fb0e4c8')
74-
})
65+
const { mainCtrl, eventEmitterRegistry, getWindowId, eventEmitter } = await makeMainController(
66+
async (storageCtrl) => {
67+
await storageCtrl.set('accounts', accounts)
68+
await storageCtrl.set('selectedAccount', '0x77777777789A8BBEE6C64381e5E89E501fb0e4c8')
69+
}
70+
)
7571

7672
// Mock account states for all accounts
7773
for (const account of mainCtrl.accounts.accounts) {
@@ -100,8 +96,6 @@ const prepareTest = async () => {
10096
}
10197
}
10298

103-
const eventEmitterRegistry = new EventEmitterRegistryController(() => null)
104-
10599
const getSignAccountOp = async ({
106100
addr,
107101
chainId,
@@ -185,40 +179,14 @@ const prepareTest = async () => {
185179
} as CallsUserRequest
186180
}
187181

188-
const requestsController = new RequestsController({
189-
relayerUrl,
190-
callRelayer: mainCtrl.callRelayer,
191-
portfolio: mainCtrl.portfolio,
192-
externalSignerControllers: {},
193-
activity: mainCtrl.activity,
194-
phishing: mainCtrl.phishing,
195-
accounts: mainCtrl.accounts,
196-
networks: mainCtrl.networks,
197-
providers: mainCtrl.providers,
198-
selectedAccount: mainCtrl.selectedAccount,
199-
keystore: mainCtrl.keystore,
200-
transfer: mainCtrl.transfer,
201-
swapAndBridge: mainCtrl.swapAndBridge,
202-
ui: uiManager as any, // eslint-disable-line @typescript-eslint/no-explicit-any
203-
safe: mainCtrl.safe,
204-
autoLogin: mainCtrl.autoLogin,
205-
getDapp: async () => undefined,
206-
updateSelectedAccountPortfolio: () => Promise.resolve(),
207-
addTokensToBeLearned: () => {},
208-
onSetCurrentUserRequest: () => {},
209-
onBroadcastSuccess: async () => {},
210-
onBroadcastFailed: () => {},
211-
eventEmitterRegistry,
212-
shouldSimulateAccountOps: false
213-
})
214-
215182
return {
216183
selectedAccountCtrl: mainCtrl.selectedAccount,
217-
controller: requestsController,
184+
controller: mainCtrl.requests,
218185
getSignAccountOp,
219186
getCallsRequest,
220-
event,
221-
getWindowId
187+
event: eventEmitter,
188+
getWindowId,
189+
uiCtrl: mainCtrl.ui
222190
}
223191
}
224192

@@ -241,11 +209,6 @@ describe('RequestsController ', () => {
241209
beforeEach(() => {
242210
jest.restoreAllMocks()
243211
})
244-
test('Init controller', async () => {
245-
const { controller } = await prepareTest()
246-
expect(controller.initialLoadPromise).toBeInstanceOf(Promise)
247-
await expect(controller.initialLoadPromise).resolves.toBeUndefined()
248-
})
249212

250213
test('Add and then remove a user request', async () => {
251214
const { controller, getCallsRequest } = await prepareTest()

src/controllers/requests/requests.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export class RequestsController extends EventEmitter implements IRequestsControl
181181

182182
#currentUserRequest: UserRequest | null = null
183183

184-
#shouldSimulateAccountOps = true
184+
private shouldSimulateAccountOps = true
185185

186186
get currentUserRequest() {
187187
return this.#currentUserRequest
@@ -281,7 +281,7 @@ export class RequestsController extends EventEmitter implements IRequestsControl
281281
this.#onSetCurrentUserRequest = onSetCurrentUserRequest
282282
this.#onBroadcastSuccess = onBroadcastSuccess
283283
this.#onBroadcastFailed = onBroadcastFailed
284-
this.#shouldSimulateAccountOps = shouldSimulateAccountOps
284+
this.shouldSimulateAccountOps = shouldSimulateAccountOps
285285

286286
this.#ui.window.event.on('windowRemoved', async (winId: number) => {
287287
// When windowManager.focus is called, it may close and reopen the request window as part of its fallback logic.
@@ -461,14 +461,15 @@ export class RequestsController extends EventEmitter implements IRequestsControl
461461

462462
// Even without an initialized SignAccountOpController or Screen, we should still update the portfolio and run the simulation.
463463
// It's necessary to continue operating with the token `amountPostSimulation` amount.
464-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
465-
this.#portfolio.simulateAccountOp(req.signAccountOp.accountOp)
464+
if (this.shouldSimulateAccountOps)
465+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
466+
this.#portfolio.simulateAccountOp(req.signAccountOp.accountOp)
466467
} else if (req.kind === 'typedMessage' || req.kind === 'message' || req.kind === 'siwe') {
467468
const existingMessageRequest = this.userRequests.find(
468469
(r) => r.kind === req.kind && r.meta.accountAddr === req.meta.accountAddr
469470
) as PlainTextMessageUserRequest | TypedMessageUserRequest | undefined
470471

471-
// remove the request only if it's not a safe req
472+
// remove the request only if it's not a Safe req
472473
if (existingMessageRequest && !this.#selectedAccount.account?.safeCreation) {
473474
existingMessageRequest.meta.accountAddr
474475
await this.rejectUserRequests('User rejected the message request', [
@@ -861,7 +862,7 @@ export class RequestsController extends EventEmitter implements IRequestsControl
861862
})
862863
}
863864

864-
// if it's a safe txn:
865+
// if it's a Safe txn:
865866
// - reject it upon a normal reject req;
866867
// - resolve it on accountOp resolve
867868

@@ -907,7 +908,7 @@ export class RequestsController extends EventEmitter implements IRequestsControl
907908
}
908909
})
909910

910-
// reject all safe txns so they do not appear by accident again
911+
// reject all Safe txns so they do not appear by accident again
911912
if (safeRejectIds.length) await this.#safe.rejectTxnId(safeRejectIds)
912913
if (safeResolveIds.length) await this.#safe.resolveTxnId(safeResolveIds)
913914

@@ -1450,7 +1451,7 @@ export class RequestsController extends EventEmitter implements IRequestsControl
14501451
dappPromises: [],
14511452
meta: {
14521453
// basically, it's the same eip-712 message but one is coming
1453-
// from safe with the safe typehints, and other is ethers
1454+
// from Safe with the Safe typehints, and other is ethers
14541455
params: typedData as {
14551456
domain: TypedDataDomain
14561457
types: Record<string, Array<TypedDataField>>
@@ -1749,7 +1750,7 @@ export class RequestsController extends EventEmitter implements IRequestsControl
17491750
if (existingUserRequest) {
17501751
// Prevent updating the signAccountOp if a signing or broadcasting process is already in progress for the same account and chain.
17511752
if (existingUserRequest.signAccountOp.signAndBroadcastPromise) {
1752-
// if the update is coming from safe global, just ignore it
1753+
// if the update is coming from Safe Global, just ignore it
17531754
if (meta.safeTxnProps) return
17541755

17551756
const errorMessage =
@@ -1841,7 +1842,7 @@ export class RequestsController extends EventEmitter implements IRequestsControl
18411842
: new Promise(() => {}) // Explicitly never-resolving promise
18421843
])) as any
18431844

1844-
// do not build requests for expired safe txns
1845+
// do not build requests for expired Safe txns
18451846
if (meta.safeTxnProps?.nonce && meta.safeTxnProps?.nonce < accountState.nonce) return
18461847

18471848
const network = this.#networks.networks.find((n) => n.chainId === meta.chainId)!
@@ -1888,7 +1889,7 @@ export class RequestsController extends EventEmitter implements IRequestsControl
18881889
safeTx: meta.safeTx,
18891890
meta
18901891
},
1891-
shouldSimulate: this.#shouldSimulateAccountOps,
1892+
shouldSimulate: this.shouldSimulateAccountOps,
18921893
onUpdateAfterTraceCallSuccess: async () => {
18931894
await this.#portfolio.updateSelectedAccount(account.addr, [network])
18941895
},

0 commit comments

Comments
 (0)