Skip to content

Commit

Permalink
Merge pull request #211 from airgap-it/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
AndreasGassmann authored May 16, 2021
2 parents 8d0dde3 + 13015b3 commit 170d0e8
Show file tree
Hide file tree
Showing 21 changed files with 254 additions and 132 deletions.
1 change: 1 addition & 0 deletions assets/toast/toast.css
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ hr {

.beacon-toast__action__item {
font-size: 14px;
max-width: 40ch;
}

.beacon-toast__action__item p {
Expand Down
11 changes: 8 additions & 3 deletions example-dapp.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<br /><br />
<button id="contractCall">Contract Call</button>
<br /><br />
<textarea id="beacon-textbox"></textarea>
<button id="deserializeData">Deserialize Data</button>
<br /><br />
---
Expand All @@ -97,9 +98,11 @@
<script>
// Initiate DAppClient
const client = new beacon.DAppClient({
name: 'Example DApp', // Name of the DApp,
name: 'Example DApp' // Name of the DApp,
// preferredNetwork: beacon.NetworkType.DELPHINET
matrixNodes: ['matrix.papers.tech']
// matrixNodes: ['test.papers.tech', 'test2.papers.tech', 'matrix.papers.tech']
// matrixNodes: ['beacon-node-0.papers.tech:8448']
// matrixNodes: ['matrix.papers.tech']
// matrixNodes: ['beacon.tztip.me']
})

Expand Down Expand Up @@ -355,7 +358,9 @@

// Add event listener to the button
document.getElementById('deserializeData').addEventListener('click', () => {
new beacon.Serializer().deserialize('').then(console.log).catch(console.error)
const value = document.getElementById('beacon-textbox').value
console.log('Deserializing:', value)
new beacon.Serializer().deserialize(value).then(console.log).catch(console.error)
})
</script>
</body>
Expand Down
5 changes: 3 additions & 2 deletions example-wallet.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
<script>
// Initiate DAppClient
const client = new beacon.WalletClient({
name: 'Example Wallet', // Name of the DApp
matrixNodes: ['matrix.papers.tech']
name: 'Example Wallet' // Name of the DApp
// matrixNodes: ['matrix.papers.tech']
// matrixNodes: ['beacon-node-0.papers.tech:8448']
// matrixNodes: ['beacon.tztip.me']
})

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airgap/beacon-sdk",
"version": "2.2.6",
"version": "2.2.7",
"description": "The beacon-sdk allows you to easily connect DApps with Wallets through P2P communication or a chrome extension.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down
3 changes: 2 additions & 1 deletion scripts/generate-wallet-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const webList: WebApp[] = [
[NetworkType.MAINNET]: 'https://wallet.kukai.app',
[NetworkType.DELPHINET]: 'https://testnet.kukai.app',
[NetworkType.EDONET]: 'https://edonet.kukai.app',
[NetworkType.FLORENCENET]: 'https://florencenet.kukai.app'
[NetworkType.FLORENCENET]: 'https://florencenet.kukai.app',
[NetworkType.GRANADANET]: 'https://granadanet.kukai.app'
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/clients/dapp-client/DAppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ export class DAppClient extends Client {
},
extraInfo: {
resetCallback: async () => {
await this.clearActiveAccount()
await Promise.all([this.clearActiveAccount(), (await this.transport).disconnect()])
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const SDK_VERSION: string = '2.2.6'
export const SDK_VERSION: string = '2.2.7'
export const BEACON_VERSION: string = '2'
7 changes: 4 additions & 3 deletions src/matrix-client/MatrixClientEventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ export class MatrixClientEventEmitter extends EventEmitter {
): void {
stateChange.rooms
.filter((room) => room.status === MatrixRoomStatus.INVITED)
.map((room) => room.id)
.forEach((id) => {
.map((room) => [room.id, room.members] as [string, string[]])
.forEach(([id, members]) => {
this.emitClientEvent(eventType, {
roomId: id
roomId: id,
members: members
})
})
}
Expand Down
1 change: 1 addition & 0 deletions src/matrix-client/models/MatrixClientEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type MatrixClientEventContent<T> = T extends MatrixClientEventType.INVITE

export interface MatrixClientEventInviteContent {
roomId: string
members: string[]
}

export interface MatrixClientEventMessageContent<T> {
Expand Down
19 changes: 17 additions & 2 deletions src/transports/Transport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Logger } from '../utils/Logger'
import { ConnectionContext } from '../types/ConnectionContext'
import { TransportType, TransportStatus, PeerInfo, StorageKey, StorageKeyReturnType } from '..'
import {
TransportType,
TransportStatus,
PeerInfo,
StorageKey,
StorageKeyReturnType,
P2PPairingRequest
} from '..'
import { PeerManager } from '../managers/PeerManager'
import { ArrayElem } from '../managers/StorageManager'
import { CommunicationClient } from './clients/CommunicationClient'
Expand Down Expand Up @@ -146,10 +153,18 @@ export abstract class Transport<
}

public async addPeer(newPeer: T): Promise<void> {
if (!(await this.peerManager.hasPeer(newPeer.publicKey))) {
const peer = await this.peerManager.getPeer(newPeer.publicKey)
if (!peer) {
logger.log('addPeer', 'adding peer', newPeer)
await this.peerManager.addPeer(newPeer as ArrayElem<StorageKeyReturnType[K]>) // TODO: Fix type
await this.listen(newPeer.publicKey) // TODO: Prevent channels from being opened multiple times
} else if (
((peer as any) as P2PPairingRequest).relayServer !==
((newPeer as any) as P2PPairingRequest).relayServer
) {
logger.log('addPeer', 'updating peer', newPeer)
await this.peerManager.addPeer(newPeer as ArrayElem<StorageKeyReturnType[K]>) // TODO: Fix type
await this.listen(newPeer.publicKey) // TODO: Prevent channels from being opened multiple times
} else {
logger.log('addPeer', 'peer already added, skipping', newPeer)
}
Expand Down
Loading

0 comments on commit 170d0e8

Please sign in to comment.