Skip to content

Commit

Permalink
Merge pull request #571 from airgap-it/feat/transport-kukai-wc2
Browse files Browse the repository at this point in the history
feat(kukai): switch to wc2 transport
  • Loading branch information
AndreasGassmann authored Dec 6, 2023
2 parents cb8d10d + 2ae7031 commit de2248e
Show file tree
Hide file tree
Showing 18 changed files with 621 additions and 198 deletions.
49 changes: 30 additions & 19 deletions examples/dapp.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@

beacon.setLogger(x)

// WC no matching key/topic errors override
window.addEventListener('unhandledrejection', function (e) {
x.error('Error occurred: ' + e.reason.message)
})

// Initiate DAppClient
const client = beacon.getDAppClientInstance({
name: 'Example DApp', // Name of the DApp,
Expand All @@ -191,24 +196,23 @@
projectId: '97f804b46f0db632c52af0556586a5f3',
relayUrl: 'wss://relay.walletconnect.com'
},
// matrixNodes: {
// [beacon.Regions.EUROPE_WEST]: [
// 'beacon-node-1.diamond.papers.tech',
// 'beacon-node-1.sky.papers.tech',
// 'beacon-node-2.sky.papers.tech',
// 'beacon-node-1.hope.papers.tech',
// 'beacon-node-1.hope-2.papers.tech',
// 'beacon-node-1.hope-3.papers.tech',
// 'beacon-node-1.hope-4.papers.tech',
// 'beacon-node-1.hope-5.papers.tech'
// ],
// [beacon.Regions.NORTH_AMERICA_EAST]: []
// },
preferredNetwork: beacon.NetworkType.GHOSTNET,
featuredWallets: ['airgap', 'metamask']
// network: {
// type: beacon.NetworkType.GHOSTNET
// }
matrixNodes: {
[beacon.Regions.EUROPE_WEST]: [
'beacon-node-1.diamond.papers.tech',
'beacon-node-1.sky.papers.tech',
'beacon-node-2.sky.papers.tech',
'beacon-node-1.hope.papers.tech',
'beacon-node-1.hope-2.papers.tech',
'beacon-node-1.hope-3.papers.tech',
'beacon-node-1.hope-4.papers.tech',
'beacon-node-1.hope-5.papers.tech'
],
[beacon.Regions.NORTH_AMERICA_EAST]: []
},
featuredWallets: ['kukai', 'metamask', 'airgap'],
network: {
type: beacon.NetworkType.GHOSTNET
}
// matrixNodes: ['test.papers.tech', 'test2.papers.tech', 'matrix.papers.tech']
// matrixNodes: ['beacon-node-0.papers.tech:8448']
// matrixNodes: ['matrix.papers.tech']
Expand Down Expand Up @@ -410,6 +414,13 @@

// Add event listener to the button
document.getElementById('reset').addEventListener('click', () => {
if (document.getElementById('reset').attributes.getNamedItem('disabled') === 'true') {
console.log('UI IS LOCKED')
return
}
document.getElementById('reset').innerText = 'Cleaning up and refreshing...'
document.getElementById('reset').setAttribute('disabled', 'true')

client.destroy().then(() => {
window.location.reload()
})
Expand Down Expand Up @@ -638,4 +649,4 @@
})
</script>
</body>
</html>
</html>
15 changes: 15 additions & 0 deletions packages/beacon-core/src/storage/ChromeStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,19 @@ export class ChromeStorage implements Storage {
})
})
}

public async subscribeToStorageChanged(
_callback: (arg: {
eventType: 'storageCleared' | 'entryModified'
key: string | null
oldValue: string | null
newValue: string | null
}) => {}
): Promise<void> {
// TODO
}

public getPrefixedKey(key: string): string {
return key
}
}
33 changes: 32 additions & 1 deletion packages/beacon-core/src/storage/LocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,38 @@ export class LocalStorage extends Storage {
return Promise.resolve(localStorage.removeItem(this.getPrefixedKey(key)))
}

private getPrefixedKey(key: string): string {
public async subscribeToStorageChanged(
callback: (arg: {
eventType: 'storageCleared' | 'entryModified'
key: string | null
oldValue: string | null
newValue: string | null
}) => {}
): Promise<void> {
window.addEventListener(
'storage',
(event) => {
if (!event.key) {
callback({
eventType: 'storageCleared',
key: null,
oldValue: null,
newValue: null
})
} else {
callback({
eventType: 'entryModified',
key: this.getPrefixedKey(event.key),
oldValue: event.oldValue,
newValue: event.newValue
})
}
},
false
)
}

public getPrefixedKey(key: string): string {
return this.prefix ? `${this.prefix}-${key}` : key
}
}
3 changes: 2 additions & 1 deletion packages/beacon-core/src/transports/clients/ClientEvents.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const enum ClientEvents {
CLOSE_ALERT = 'CLOSE_ALERT',
RESET_STATE = 'RESET_STATE'
RESET_STATE = 'RESET_STATE',
WC_ACK_NOTIFICATION = 'WC_ACK_NOTIFICATION'
}
Loading

0 comments on commit de2248e

Please sign in to comment.