Skip to content

Commit

Permalink
Merge pull request #814 from airgap-it/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
IsaccoSordo authored Sep 4, 2024
2 parents 82a6778 + 8674705 commit 8e91d90
Show file tree
Hide file tree
Showing 44 changed files with 2,425 additions and 2,401 deletions.
2 changes: 1 addition & 1 deletion examples/dapp.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
},
featuredWallets: ['kukai', 'metamask', 'airgap'],
network: {
type: beacon.NetworkType.MAINNET
type: beacon.NetworkType.GHOSTNET
},
enableMetrics: true
// matrixNodes: ['test.papers.tech', 'test2.papers.tech', 'matrix.papers.tech']
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "4.2.2",
"version": "4.3.0",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
3,521 changes: 1,609 additions & 1,912 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
"@airgap/beacon-ui": "file:packages/beacon-ui",
"@airgap/beacon-utils": "file:packages/beacon-utils",
"@airgap/beacon-wallet": "file:packages/beacon-wallet",
"@walletconnect/sign-client": "2.11.2",
"@walletconnect/types": "2.11.2",
"@walletconnect/utils": "2.11.2",
"@walletconnect/sign-client": "2.14.0",
"@walletconnect/types": "2.14.0",
"@walletconnect/utils": "2.14.0",
"@web3modal/standalone": "2.0.0",
"stream-browserify": "^3.0.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/beacon-blockchain-substrate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airgap/beacon-blockchain-substrate",
"version": "4.2.2",
"version": "4.3.0",
"description": "This package adds support for `substrate` based blockchains. It can be used in combination with the `@airgap/beacon-dapp` or `@airgap/beacon-wallet` packages.",
"author": "Andreas Gassmann <[email protected]>",
"homepage": "https://walletbeacon.io",
Expand Down Expand Up @@ -34,7 +34,7 @@
"url": "https://github.com/airgap-it/beacon-sdk/issues"
},
"dependencies": {
"@airgap/beacon-types": "4.2.2",
"@airgap/beacon-ui": "4.2.2"
"@airgap/beacon-types": "4.3.0",
"@airgap/beacon-ui": "4.3.0"
}
}
6 changes: 3 additions & 3 deletions packages/beacon-blockchain-tezos-sapling/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airgap/beacon-blockchain-tezos-sapling",
"version": "4.2.2",
"version": "4.3.0",
"description": "This package adds support for `tezos-sapling`, the sapling integration on the Tezos blockchain. It can be used in combination with the `@airgap/beacon-dapp` or `@airgap/beacon-wallet` packages.",
"author": "Andreas Gassmann <[email protected]>",
"homepage": "https://walletbeacon.io",
Expand Down Expand Up @@ -34,7 +34,7 @@
"url": "https://github.com/airgap-it/beacon-sdk/issues"
},
"dependencies": {
"@airgap/beacon-types": "4.2.2",
"@airgap/beacon-ui": "4.2.2"
"@airgap/beacon-types": "4.3.0",
"@airgap/beacon-ui": "4.3.0"
}
}
6 changes: 3 additions & 3 deletions packages/beacon-blockchain-tezos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airgap/beacon-blockchain-tezos",
"version": "4.2.2",
"version": "4.3.0",
"description": "This package adds support for the `tezos` blockchain. It can be used in combination with the `@airgap/beacon-dapp` or `@airgap/beacon-wallet` packages.",
"author": "Andreas Gassmann <[email protected]>",
"homepage": "https://walletbeacon.io",
Expand Down Expand Up @@ -34,7 +34,7 @@
"url": "https://github.com/airgap-it/beacon-sdk/issues"
},
"dependencies": {
"@airgap/beacon-types": "4.2.2",
"@airgap/beacon-ui": "4.2.2"
"@airgap/beacon-types": "4.3.0",
"@airgap/beacon-ui": "4.3.0"
}
}
9 changes: 5 additions & 4 deletions packages/beacon-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airgap/beacon-core",
"version": "4.2.2",
"version": "4.3.0",
"description": "This package contains internal methods that are used by both the dApp and wallet client.",
"author": "Andreas Gassmann <[email protected]>",
"homepage": "https://walletbeacon.io",
Expand Down Expand Up @@ -34,12 +34,13 @@
"url": "https://github.com/airgap-it/beacon-sdk/issues"
},
"dependencies": {
"@airgap/beacon-types": "4.2.2",
"@airgap/beacon-utils": "4.2.2",
"@airgap/beacon-types": "4.3.0",
"@airgap/beacon-utils": "4.3.0",
"@stablelib/ed25519": "^1.0.3",
"@stablelib/nacl": "^1.0.4",
"@stablelib/utf8": "^1.0.1",
"@stablelib/x25519-session": "^1.0.4",
"bs58check": "2.1.2"
"bs58check": "2.1.2",
"broadcast-channel": "^7.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/beacon-core/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const SDK_VERSION: string = '4.2.2'
export const SDK_VERSION: string = '4.3.0'
export const BEACON_VERSION: string = '3'

export const NOTIFICATION_ORACLE_URL: string =
Expand Down
3 changes: 2 additions & 1 deletion packages/beacon-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { ClientEvents } from './transports/clients/ClientEvents'
import { WCStorage } from './storage/WCStorage'
import { IndexedDBStorage } from './storage/IndexedDBStorage'
import { StorageValidator } from './storage/StorageValidator'
import { MultiTabChannel } from './utils/multi-tab-channel'
// import { EncryptionType } from './types/EncryptionType'
// import { EncryptionOperation } from './types/EncryptionOperation'

Expand Down Expand Up @@ -79,7 +80,7 @@ export { PeerManager, AccountManager, AppMetadataManager, PermissionManager }
export { SDK_VERSION, BEACON_VERSION }

// Utils
export { getSenderId, getAccountIdentifier, windowRef }
export { getSenderId, getAccountIdentifier, windowRef, MultiTabChannel }

// Others
export { Serializer, Logger, setLogger, getLogger }
Expand Down
85 changes: 85 additions & 0 deletions packages/beacon-core/src/utils/multi-tab-channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Logger } from '@airgap/beacon-core'
import { createLeaderElection, BroadcastChannel, LeaderElector } from 'broadcast-channel'

type Message = {
type: string
id: string
data: any
}

const logger = new Logger('MultiTabChannel')

export class MultiTabChannel {
private channel: BroadcastChannel
private elector: LeaderElector
private eventListeners = [
() => this.onBeforeUnloadHandler(),
(message: any) => this.onMessageHandler(message)
]
private onBCMessageHandler: Function
private onElectedLeaderHandler: Function
// Auxiliary variable needed for handling beforeUnload.
// Closing a tab causes the elector to be killed immediately
private wasLeader: boolean = false

constructor(name: string, onBCMessageHandler: Function, onElectedLeaderHandler: Function) {
this.onBCMessageHandler = onBCMessageHandler
this.onElectedLeaderHandler = onElectedLeaderHandler
this.channel = new BroadcastChannel(name)
this.elector = createLeaderElection(this.channel)
this.init().then(() => logger.debug('MultiTabChannel', 'constructor', 'init', 'done'))
}

private async init() {
const hasLeader = await this.elector.hasLeader()

if (!hasLeader) {
await this.elector.awaitLeadership()
this.wasLeader = this.isLeader()
}

this.channel.onmessage = this.eventListeners[1]
window?.addEventListener('beforeunload', this.eventListeners[0])
}

private async onBeforeUnloadHandler() {
if (this.wasLeader) {
await this.elector.die()
this.postMessage({ type: 'LEADER_DEAD' })
}

window?.removeEventListener('beforeunload', this.eventListeners[0])
this.channel.removeEventListener('message', this.eventListeners[1])
}

private async onMessageHandler(message: Message) {
if (message.type === 'LEADER_DEAD') {
await this.elector.awaitLeadership()

this.wasLeader = this.isLeader()

if (this.isLeader()) {
this.onElectedLeaderHandler()
}
return
}

this.onBCMessageHandler(message)
}

isLeader(): boolean {
return this.elector.isLeader
}

async getLeadership() {
return this.elector.awaitLeadership()
}

async hasLeader(): Promise<boolean> {
return this.elector.hasLeader()
}

postMessage(message: any): void {
this.channel.postMessage(message)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as chaiAsPromised from 'chai-as-promised'
import 'mocha'
import * as sinon from 'sinon'

import { getDAppClientInstance } from '../../src/utils/get-instance'
import { getDAppClientInstance } from '../src/utils/get-instance'

// use chai-as-promised plugin
chai.use(chaiAsPromised)
Expand Down
13 changes: 7 additions & 6 deletions packages/beacon-dapp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airgap/beacon-dapp",
"version": "4.2.2",
"version": "4.3.0",
"description": "Use this package on your dApp to instanciate a DAppClient object and communicate to wallets.",
"author": "Andreas Gassmann <[email protected]>",
"homepage": "https://walletbeacon.io",
Expand Down Expand Up @@ -35,10 +35,11 @@
"url": "https://github.com/airgap-it/beacon-sdk/issues"
},
"dependencies": {
"@airgap/beacon-core": "4.2.2",
"@airgap/beacon-transport-matrix": "4.2.2",
"@airgap/beacon-transport-postmessage": "4.2.2",
"@airgap/beacon-transport-walletconnect": "4.2.2",
"@airgap/beacon-ui": "4.2.2"
"@airgap/beacon-core": "4.3.0",
"@airgap/beacon-transport-matrix": "4.3.0",
"@airgap/beacon-transport-postmessage": "4.3.0",
"@airgap/beacon-transport-walletconnect": "4.3.0",
"@airgap/beacon-ui": "4.3.0",
"broadcast-channel": "^7.0.0"
}
}
Loading

0 comments on commit 8e91d90

Please sign in to comment.