Skip to content

Commit

Permalink
Merge pull request #385 from airgap-it/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
AndreasGassmann authored Sep 1, 2022
2 parents 312226a + 90bc078 commit b784451
Show file tree
Hide file tree
Showing 23 changed files with 159 additions and 94 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"packages": ["packages/*"],
"version": "3.1.3"
"version": "3.1.4"
}
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": "3.1.3",
"version": "3.1.4",
"description": "> TODO: description",
"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": "^3.1.3",
"@airgap/beacon-ui": "^3.1.3"
"@airgap/beacon-types": "^3.1.4",
"@airgap/beacon-ui": "^3.1.4"
}
}
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": "3.1.3",
"version": "3.1.4",
"description": "> TODO: description",
"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": "^3.1.3",
"@airgap/beacon-ui": "^3.1.3"
"@airgap/beacon-types": "^3.1.4",
"@airgap/beacon-ui": "^3.1.4"
}
}
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": "3.1.3",
"version": "3.1.4",
"description": "> TODO: description",
"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": "^3.1.3",
"@airgap/beacon-ui": "^3.1.3"
"@airgap/beacon-types": "^3.1.4",
"@airgap/beacon-ui": "^3.1.4"
}
}
6 changes: 3 additions & 3 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": "3.1.3",
"version": "3.1.4",
"description": "> TODO: description",
"author": "Andreas Gassmann <[email protected]>",
"homepage": "https://walletbeacon.io",
Expand Down Expand Up @@ -34,8 +34,8 @@
"url": "https://github.com/airgap-it/beacon-sdk/issues"
},
"dependencies": {
"@airgap/beacon-types": "^3.1.3",
"@airgap/beacon-utils": "^3.1.2",
"@airgap/beacon-types": "^3.1.4",
"@airgap/beacon-utils": "^3.1.4",
"@types/libsodium-wrappers": "0.7.9",
"bs58check": "2.1.2",
"libsodium-wrappers": "0.7.9"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export abstract class BeaconClient {
this.appUrl = config.appUrl
this.storage = config.storage

// TODO: This is a temporary "fix" to prevent users from creating multiple Client instances
// TODO: This is a temporary "workaround" to prevent users from creating multiple Client instances
if ((windowRef as any).beaconCreatedClientInstance) {
console.warn(
console.error(
'[BEACON] It looks like you created multiple Beacon SDK Client instances. This can lead to problems. Only create one instance and re-use it everywhere.'
)
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-core/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const SDK_VERSION: string = '3.1.3'
export const SDK_VERSION: string = '3.1.4'
export const BEACON_VERSION: string = '3'
43 changes: 43 additions & 0 deletions packages/beacon-dapp/__tests__/tests/get-instance.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as chai from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
import 'mocha'
import * as sinon from 'sinon'

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

// use chai-as-promised plugin
chai.use(chaiAsPromised)
const expect = chai.expect

describe(`getDAppClientInstance`, () => {
beforeEach(async () => {
sinon.restore()
})

it(`should get an instance`, async () => {
const instance = getDAppClientInstance({ name: 'test' })

expect(instance).to.not.be.undefined
})

it(`should get the same instance`, async () => {
const instance1 = getDAppClientInstance({ name: 'test' })
const instance2 = getDAppClientInstance({ name: 'test' })

expect(instance1).to.equal(instance2)
})

it(`should get the same instance with different config`, async () => {
const instance1 = getDAppClientInstance({ name: 'test' })
const instance2 = getDAppClientInstance({ name: 'test1' })

expect(instance1).to.equal(instance2)
})

it(`should get a different instance if reset is set`, async () => {
const instance1 = getDAppClientInstance({ name: 'test' })
const instance2 = getDAppClientInstance({ name: 'test1' }, true)

expect(instance1).to.not.equal(instance2)
})
})
10 changes: 5 additions & 5 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": "3.1.3",
"version": "3.1.4",
"description": "> TODO: description",
"author": "Andreas Gassmann <[email protected]>",
"homepage": "https://walletbeacon.io",
Expand Down Expand Up @@ -35,10 +35,10 @@
"url": "https://github.com/airgap-it/beacon-sdk/issues"
},
"dependencies": {
"@airgap/beacon-core": "^3.1.3",
"@airgap/beacon-transport-matrix": "^3.1.3",
"@airgap/beacon-transport-postmessage": "^3.1.3",
"@airgap/beacon-ui": "^3.1.3",
"@airgap/beacon-core": "^3.1.4",
"@airgap/beacon-transport-matrix": "^3.1.4",
"@airgap/beacon-transport-postmessage": "^3.1.4",
"@airgap/beacon-ui": "^3.1.4",
"qrcode-generator": "1.4.4"
}
}
6 changes: 3 additions & 3 deletions packages/beacon-dapp/src/dapp-client/DAppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import {
import { getAddressFromPublicKey, ExposedPromise, generateGUID } from '@airgap/beacon-utils'
import { messageEvents } from '../beacon-message-events'
import { BlockExplorer } from '../utils/block-explorer'
import { TezblockBlockExplorer } from '../utils/tezblock-blockexplorer'
import { TzktBlockExplorer } from '../utils/tzkt-blockexplorer'

import { DAppClientOptions } from './DAppClientOptions'
import { AlertButton, closeToast } from '@airgap/beacon-ui'
Expand Down Expand Up @@ -162,7 +162,7 @@ export class DAppClient extends Client {
...config
})
this.events = new BeaconEventHandler(config.eventHandlers, config.disableDefaultEvents ?? false)
this.blockExplorer = config.blockExplorer ?? new TezblockBlockExplorer()
this.blockExplorer = config.blockExplorer ?? new TzktBlockExplorer()
this.preferredNetwork = config.preferredNetwork ?? NetworkType.MAINNET
setColorMode(config.colorMode ?? ColorMode.LIGHT)

Expand Down Expand Up @@ -1541,7 +1541,7 @@ export class DAppClient extends Client {
return exposed.promise as any // TODO: fix type
}

private async disconnect() {
public async disconnect() {
this.postMessageTransport = undefined
this.p2pTransport = undefined
await Promise.all([this.clearActiveAccount(), (await this.transport).disconnect()])
Expand Down
7 changes: 4 additions & 3 deletions packages/beacon-dapp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import { DAppClient } from './dapp-client/DAppClient'
import { DAppClientOptions } from './dapp-client/DAppClientOptions'
import { BeaconEvent, BeaconEventHandler, defaultEventCallbacks } from './events'
import { BlockExplorer } from './utils/block-explorer'
import { TezblockBlockExplorer } from './utils/tezblock-blockexplorer'
import { TzktBlockExplorer } from './utils/tzkt-blockexplorer'
import { getDAppClientInstance } from './utils/get-instance'

export { DAppClient, DAppClientOptions }
export { DAppClient, DAppClientOptions, getDAppClientInstance }

// Events
export { BeaconEvent, BeaconEventHandler, defaultEventCallbacks }

// BlockExplorer
export { BlockExplorer, TezblockBlockExplorer }
export { BlockExplorer, TzktBlockExplorer, TzktBlockExplorer as TezblockBlockExplorer }
21 changes: 21 additions & 0 deletions packages/beacon-dapp/src/utils/get-instance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { DAppClient, DAppClientOptions } from '..'

let _instance: DAppClient | undefined

/** Get a DAppClient instance. Will make sure only one dAppClient exists. After the first instance has been created, the config will be ignored, unless "reset" is set */
export const getDAppClientInstance = (config: DAppClientOptions, reset?: boolean): DAppClient => {
if (_instance && reset) {
_instance.disconnect()
_instance = undefined
}

if (_instance) {
return _instance
}

if (!_instance) {
_instance = new DAppClient(config)
}

return _instance
}
35 changes: 0 additions & 35 deletions packages/beacon-dapp/src/utils/tezblock-blockexplorer.ts

This file was deleted.

35 changes: 35 additions & 0 deletions packages/beacon-dapp/src/utils/tzkt-blockexplorer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Network, NetworkType } from '@airgap/beacon-types'
import { BlockExplorer } from './block-explorer'

export class TzktBlockExplorer extends BlockExplorer {
constructor(
public readonly rpcUrls: { [key in NetworkType]: string } = {
[NetworkType.MAINNET]: 'https://tzkt.io',
[NetworkType.GHOSTNET]: 'https://ghostnet.tzkt.io',
[NetworkType.MONDAYNET]: 'https://mondaynet.tzkt.io',
[NetworkType.DAILYNET]: 'https://dailynet.tzkt.io',
[NetworkType.DELPHINET]: 'https://delphinet.tzkt.io',
[NetworkType.EDONET]: 'https://edonet.tzkt.io',
[NetworkType.FLORENCENET]: 'https://florencenet.tzkt.io',
[NetworkType.GRANADANET]: 'https://granadanet.tzkt.io',
[NetworkType.HANGZHOUNET]: 'https://hangzhounet.tzkt.io',
[NetworkType.ITHACANET]: 'https://ithacanet.tzkt.io',
[NetworkType.JAKARTANET]: 'https://jakartanet.tzkt.io',
[NetworkType.KATHMANDUNET]: 'https://kathmandunet.tzkt.io',
[NetworkType.CUSTOM]: 'https://kathmandunet.tzkt.io'
}
) {
super(rpcUrls)
}

public async getAddressLink(address: string, network: Network): Promise<string> {
const blockExplorer = await this.getLinkForNetwork(network)

return `${blockExplorer}/${address}`
}
public async getTransactionLink(transactionId: string, network: Network): Promise<string> {
const blockExplorer = await this.getLinkForNetwork(network)

return `${blockExplorer}/${transactionId}`
}
}
22 changes: 11 additions & 11 deletions packages/beacon-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airgap/beacon-sdk",
"version": "3.1.3",
"version": "3.1.4",
"description": "> TODO: description",
"author": "Andreas Gassmann <[email protected]>",
"homepage": "https://walletbeacon.io",
Expand Down Expand Up @@ -35,15 +35,15 @@
"url": "https://github.com/airgap-it/beacon-sdk/issues"
},
"dependencies": {
"@airgap/beacon-blockchain-substrate": "^3.1.3",
"@airgap/beacon-blockchain-tezos": "^3.1.3",
"@airgap/beacon-core": "^3.1.3",
"@airgap/beacon-dapp": "^3.1.3",
"@airgap/beacon-transport-matrix": "^3.1.3",
"@airgap/beacon-transport-postmessage": "^3.1.3",
"@airgap/beacon-types": "^3.1.3",
"@airgap/beacon-ui": "^3.1.3",
"@airgap/beacon-utils": "^3.1.2",
"@airgap/beacon-wallet": "^3.1.3"
"@airgap/beacon-blockchain-substrate": "^3.1.4",
"@airgap/beacon-blockchain-tezos": "^3.1.4",
"@airgap/beacon-core": "^3.1.4",
"@airgap/beacon-dapp": "^3.1.4",
"@airgap/beacon-transport-matrix": "^3.1.4",
"@airgap/beacon-transport-postmessage": "^3.1.4",
"@airgap/beacon-types": "^3.1.4",
"@airgap/beacon-ui": "^3.1.4",
"@airgap/beacon-utils": "^3.1.4",
"@airgap/beacon-wallet": "^3.1.4"
}
}
6 changes: 3 additions & 3 deletions packages/beacon-transport-matrix/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airgap/beacon-transport-matrix",
"version": "3.1.3",
"version": "3.1.4",
"description": "> TODO: description",
"author": "Andreas Gassmann <[email protected]>",
"homepage": "https://walletbeacon.io",
Expand Down Expand Up @@ -34,8 +34,8 @@
"url": "https://github.com/airgap-it/beacon-sdk/issues"
},
"dependencies": {
"@airgap/beacon-core": "^3.1.3",
"@airgap/beacon-utils": "^3.1.2",
"@airgap/beacon-core": "^3.1.4",
"@airgap/beacon-utils": "^3.1.4",
"axios": "0.24.0"
}
}
8 changes: 4 additions & 4 deletions packages/beacon-transport-postmessage/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airgap/beacon-transport-postmessage",
"version": "3.1.3",
"version": "3.1.4",
"description": "> TODO: description",
"author": "Andreas Gassmann <[email protected]>",
"homepage": "https://walletbeacon.io",
Expand Down Expand Up @@ -34,9 +34,9 @@
"url": "https://github.com/airgap-it/beacon-sdk/issues"
},
"dependencies": {
"@airgap/beacon-core": "^3.1.3",
"@airgap/beacon-types": "^3.1.3",
"@airgap/beacon-utils": "^3.1.2",
"@airgap/beacon-core": "^3.1.4",
"@airgap/beacon-types": "^3.1.4",
"@airgap/beacon-utils": "^3.1.4",
"@types/libsodium-wrappers": "0.7.9",
"libsodium-wrappers": "0.7.9"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airgap/beacon-types",
"version": "3.1.3",
"version": "3.1.4",
"description": "> TODO: description",
"author": "Andreas Gassmann <[email protected]>",
"homepage": "https://walletbeacon.io",
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-types/src/types/beacon/NetworkType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export enum NetworkType {
MAINNET = 'mainnet',
GHOSTNET = 'ghostnet', // Long running testnet
MONDAYNET = 'mondaynet', // Testnet, resets every monday
DAILYNET = 'mondaynet', // Testnet, resets every day
DAILYNET = 'dailynet', // Testnet, resets every day
DELPHINET = 'delphinet',
EDONET = 'edonet',
FLORENCENET = 'florencenet',
Expand Down
Loading

0 comments on commit b784451

Please sign in to comment.