Skip to content

Commit dd14fb9

Browse files
authored
Merge pull request #2504 from AmbireTech/release/v2.101.4
Release / v2.101.4 (Hotfix)
2 parents b6455d6 + 3ab88b6 commit dd14fb9

6 files changed

Lines changed: 100 additions & 21 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.101.3",
2+
"version": "2.101.4",
33
"name": "ambire-common",
44
"description": "Common ground for the Ambire apps",
55
"scripts": {

src/controllers/dapps/dapps.test.ts

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,35 @@ describe('DappsController', () => {
9191
expect(lido.chainIds).toEqual([1]) // other networks should be excluded because the are not in our networks list
9292
expect(lido.blacklisted).toEqual('VERIFIED')
9393
})
94+
test('should preserve account preferences while fetching and updating dapps', async () => {
95+
const accountPreferences = {
96+
enabled: true,
97+
selectedAccount: '0x16c81367c30c71d6B712355255A07FCe8fd3b5bB',
98+
accounts: ['0x16c81367c30c71d6B712355255A07FCe8fd3b5bB']
99+
}
100+
const storedAave = makeDapp({
101+
id: 'aave.com',
102+
name: 'Aave',
103+
url: 'https://aave.com',
104+
isConnected: true,
105+
connectedSources: ['injected'],
106+
accountPreferences
107+
})
108+
109+
const { controller, mainCtrl } = await prepareTest(async (storageCtrl) => {
110+
await storageCtrl.set('dappsV2', [storedAave])
111+
await storageCtrl.set('lastDappsUpdateVersion', 'test-version')
112+
})
113+
114+
await controller.fetchAndUpdatePromise
115+
116+
expect(controller.getDapp('aave.com')!.accountPreferences).toEqual(accountPreferences)
117+
118+
const stored = await mainCtrl.storage.get('dappsV2', [])
119+
expect(stored.find((dapp) => dapp.id === 'aave.com')!.accountPreferences).toEqual(
120+
accountPreferences
121+
)
122+
})
94123
test('should skip fetch and update', async () => {
95124
const { controller } = await prepareTest(async (storageCtrl) => {
96125
await storageCtrl.set('dappsV2', predefinedDapps)
@@ -938,9 +967,9 @@ describe('DappsController', () => {
938967
describe('connection sources', () => {
939968
const baseDapp = (): Dapp =>
940969
makeDapp({
941-
id: 'sources-dapp.com',
942-
name: 'Sources Dapp',
943-
url: 'https://sources-dapp.com',
970+
id: 'aave.com',
971+
name: 'Aave',
972+
url: 'https://aave.com',
944973
isCustom: true,
945974
isConnected: true,
946975
chainId: 1,
@@ -955,7 +984,7 @@ describe('DappsController', () => {
955984

956985
await controller.addDapp(baseDapp())
957986

958-
const stored = controller.getDapp('sources-dapp.com')!
987+
const stored = controller.getDapp('aave.com')!
959988
expect(stored.connectedSources).toEqual(['injected'])
960989
expect(stored.isConnected).toBe(true)
961990
})
@@ -970,8 +999,34 @@ describe('DappsController', () => {
970999
await controller.addDapp(baseDapp(), 'wc')
9711000
await controller.addDapp(baseDapp(), 'wc') // duplicate
9721001

973-
const stored = controller.getDapp('sources-dapp.com')!
1002+
const stored = controller.getDapp('aave.com')!
1003+
expect(stored.connectedSources).toEqual(['injected', 'wc'])
1004+
})
1005+
1006+
test('addDapp preserves existing account preferences when merging a source', async () => {
1007+
const accountPreferences = {
1008+
enabled: true,
1009+
selectedAccount: '0x16c81367c30c71d6B712355255A07FCe8fd3b5bB',
1010+
accounts: ['0x16c81367c30c71d6B712355255A07FCe8fd3b5bB']
1011+
}
1012+
const { controller } = await prepareTest(async (storageCtrl) => {
1013+
await storageCtrl.set('dappsV2', [
1014+
{
1015+
...baseDapp(),
1016+
connectedSources: ['injected'],
1017+
accountPreferences
1018+
}
1019+
])
1020+
await storageCtrl.set('lastDappsUpdateVersion', 'force-dapp-refetch')
1021+
})
1022+
1023+
await controller.fetchAndUpdatePromise
1024+
1025+
await controller.addDapp(baseDapp(), 'wc')
1026+
1027+
const stored = controller.getDapp('aave.com')!
9741028
expect(stored.connectedSources).toEqual(['injected', 'wc'])
1029+
expect(stored.accountPreferences).toEqual(accountPreferences)
9751030
})
9761031

9771032
test('hasPermission(id, source) is source-scoped; hasPermission(id) is any-source', async () => {
@@ -982,10 +1037,10 @@ describe('DappsController', () => {
9821037

9831038
await controller.addDapp(baseDapp(), 'wc')
9841039

985-
expect(controller.hasPermission('sources-dapp.com')).toBe(true)
986-
expect(controller.hasPermission('sources-dapp.com', 'wc')).toBe(true)
1040+
expect(controller.hasPermission('aave.com')).toBe(true)
1041+
expect(controller.hasPermission('aave.com', 'wc')).toBe(true)
9871042
// Core behavior change: an injected request must still re-prompt even when WC is connected.
988-
expect(controller.hasPermission('sources-dapp.com', 'injected')).toBe(false)
1043+
expect(controller.hasPermission('aave.com', 'injected')).toBe(false)
9891044
})
9901045

9911046
// BUG: a stored dapp whose isConnected and connectedSources had drifted (isConnected: true
@@ -1078,12 +1133,12 @@ describe('DappsController', () => {
10781133
})
10791134

10801135
await controller.addDapp(baseDapp(), 'wc')
1081-
expect(controller.getDapp('sources-dapp.com')).toBeDefined()
1136+
expect(controller.getDapp('aave.com')).toBeDefined()
10821137

1083-
await controller.disconnectDappSource('sources-dapp.com', 'wc')
1138+
await controller.disconnectDappSource('aave.com', 'wc')
10841139

10851140
// Custom dapps that lose their last source are removed from the catalog.
1086-
expect(controller.getDapp('sources-dapp.com')).toBeUndefined()
1141+
expect(controller.getDapp('aave.com')).toBeUndefined()
10871142
})
10881143
})
10891144

src/controllers/dapps/dapps.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ export class DappsController extends EventEmitter implements IDappsController {
390390
blacklisted: 'LOADING',
391391
twitter: dapp.twitter,
392392
geckoId: dapp.gecko_id,
393+
accountPreferences: prevStoredDapp?.accountPreferences,
393394
grantedPermissionId: prevStoredDapp?.grantedPermissionId,
394395
grantedPermissionAt: prevStoredDapp?.grantedPermissionAt
395396
}
@@ -428,7 +429,8 @@ export class DappsController extends EventEmitter implements IDappsController {
428429
favorite: prevStoredDapp?.favorite ?? false,
429430
blacklisted: 'LOADING',
430431
twitter: pd.twitter || null,
431-
geckoId: null
432+
geckoId: null,
433+
accountPreferences: prevStoredDapp?.accountPreferences
432434
})
433435
}
434436
}
@@ -746,12 +748,15 @@ export class DappsController extends EventEmitter implements IDappsController {
746748

747749
if (existing) {
748750
const mergedSources = mergeSource(existing.connectedSources, source)
749-
this.updateDapp(dapp.id, {
751+
const dappUpdate: Partial<Dapp> = {
750752
chainId: dapp.chainId,
751753
connectedSources: mergedSources,
752-
isConnected: mergedSources.length > 0,
753-
accountPreferences: dapp.accountPreferences
754-
})
754+
isConnected: mergedSources.length > 0
755+
}
756+
757+
if (dapp.accountPreferences) dappUpdate.accountPreferences = dapp.accountPreferences
758+
759+
this.updateDapp(dapp.id, dappUpdate)
755760
return
756761
}
757762

src/libs/humanizer/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,16 @@ const humanizeMessage = (_message: Message, options?: HumanizeMessageOptions): I
178178

179179
// runs all modules and takes the first non empty array
180180
const { fullVisualization, warnings, canHideDropdownArrow } =
181-
humanizerTMModules.map((m) => m(message)).filter((p) => p.fullVisualization?.length)[0] || {}
181+
humanizerTMModules
182+
.map((m) => {
183+
try {
184+
return m(message)
185+
} catch (error) {
186+
console.error(error)
187+
return {}
188+
}
189+
})
190+
.filter((p) => p.fullVisualization?.length)[0] || {}
182191

183192
return { ...message, fullVisualization, warnings, canHideDropdownArrow }
184193
} catch (error) {
@@ -187,6 +196,6 @@ const humanizeMessage = (_message: Message, options?: HumanizeMessageOptions): I
187196
}
188197
}
189198

190-
export { humanizeAccountOp, humanizeMessage }
191199
export * from './erc7730'
200+
export { humanizeAccountOp, humanizeMessage }
192201
export type { HumanizeAccountOpOptions, HumanizeMessageOptions }

src/libs/humanizer/messageModules/openseaModule.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ export const openseaMessageModule: HumanizerTypedMessageModule = (message: Messa
2222
if (message.content.kind === 'message' && typeof message.content.message === 'string') {
2323
let messageAsText: string = message.content.message
2424
if (isHexString(message.content.message) && message.content.message.length % 2 === 0) {
25-
messageAsText = toUtf8String(message.content.message)
25+
try {
26+
messageAsText = toUtf8String(message.content.message)
27+
} catch (e) {
28+
console.log("open sea module: couldn't do toUtf8String on message")
29+
return { fullVisualization: [] }
30+
}
2631
}
2732
const OPENSEA_LOGIN_MESSAGE_PREFIX = 'Welcome to OpenSea!'
2833
if (

src/libs/humanizer/messageModules/zealyModule.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ export const zealyMessageModule: HumanizerTypedMessageModule = (message: Message
1010
return { fullVisualization: [] }
1111
let messageAsText: Hex | string = message.content.message
1212
if (isHexString(message.content.message) && message.content.message.length % 2 === 0) {
13-
messageAsText = toUtf8String(message.content.message)
13+
try {
14+
messageAsText = toUtf8String(message.content.message)
15+
} catch (e) {
16+
console.log("zealy module: couldn't do toUtf8String on message")
17+
return { fullVisualization: [] }
18+
}
1419
}
1520

1621
if (messageAsText.startsWith('zealy.io wants you to sign in with your Ethereum account'))

0 commit comments

Comments
 (0)