-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #814 from airgap-it/develop
Develop
- Loading branch information
Showing
44 changed files
with
2,425 additions
and
2,401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
|
@@ -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" | ||
} | ||
} |
Oops, something went wrong.