From 70d31e5cf88e82f2597ace761d175b92842c5264 Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Tue, 10 Sep 2024 15:58:47 +0200 Subject: [PATCH] fix: conversion issue --- .../beacon-dapp/src/dapp-client/DAppClient.ts | 18 ++++++++---- packages/beacon-dapp/src/events.ts | 9 ++---- packages/beacon-ui/src/ui/alert/common.ts | 14 +++------- .../alert/components/pairing-alert/index.tsx | 28 ++++--------------- .../src/ui/alert/hooks/useConnect.tsx | 25 +++++------------ 5 files changed, 31 insertions(+), 63 deletions(-) diff --git a/packages/beacon-dapp/src/dapp-client/DAppClient.ts b/packages/beacon-dapp/src/dapp-client/DAppClient.ts index 5028b77b1..0ad73ccff 100644 --- a/packages/beacon-dapp/src/dapp-client/DAppClient.ts +++ b/packages/beacon-dapp/src/dapp-client/DAppClient.ts @@ -784,14 +784,20 @@ export class DAppClient extends Client { console.error(error) }) + await p2pTransport.connect() + + const serializer = new Serializer() + const p2pPeerInfo = await serializer.serialize(await p2pTransport.getPairingRequestInfo()) + const walletConnectPeerInfo = (await walletConnectTransport.getPairingRequestInfo()).uri + const postmessagePeerInfo = await serializer.serialize( + await postMessageTransport.getPairingRequestInfo() + ) + this.events .emit(BeaconEvent.PAIR_INIT, { - p2pPeerInfo: () => { - p2pTransport.connect().then().catch(console.error) - return p2pTransport.getPairingRequestInfo() - }, - postmessagePeerInfo: () => postMessageTransport.getPairingRequestInfo(), - walletConnectPeerInfo: () => walletConnectTransport.getPairingRequestInfo(), + p2pPeerInfo, + postmessagePeerInfo, + walletConnectPeerInfo, networkType: this.network.type, abortedHandler: async () => { logger.log('init', 'ABORTED') diff --git a/packages/beacon-dapp/src/events.ts b/packages/beacon-dapp/src/events.ts index 6de228c79..3a305d474 100644 --- a/packages/beacon-dapp/src/events.ts +++ b/packages/beacon-dapp/src/events.ts @@ -11,9 +11,7 @@ import { import { BeaconErrorType, ExtendedPostMessagePairingResponse, - PostMessagePairingRequest, ExtendedP2PPairingResponse, - P2PPairingRequest, AccountInfo, ErrorResponse, PermissionResponseOutput, @@ -26,7 +24,6 @@ import { AcknowledgeResponse, WalletInfo, ExtendedWalletConnectPairingResponse, - WalletConnectPairingRequest, AnalyticsInterface, ProofOfEventChallengeResponseOutput, SimulatedProofOfEventChallengeResponseOutput @@ -199,9 +196,9 @@ export interface BeaconEventType { [BeaconEvent.SHOW_PREPARE]: { walletInfo?: WalletInfo } [BeaconEvent.HIDE_UI]: ('alert' | 'toast')[] | undefined [BeaconEvent.PAIR_INIT]: { - p2pPeerInfo: () => Promise - postmessagePeerInfo: () => Promise - walletConnectPeerInfo: () => Promise + p2pPeerInfo: string + postmessagePeerInfo: string + walletConnectPeerInfo: string networkType: NetworkType abortedHandler?(): void disclaimerText?: string diff --git a/packages/beacon-ui/src/ui/alert/common.ts b/packages/beacon-ui/src/ui/alert/common.ts index 72b497371..b84d9acd1 100644 --- a/packages/beacon-ui/src/ui/alert/common.ts +++ b/packages/beacon-ui/src/ui/alert/common.ts @@ -1,10 +1,4 @@ -import { - P2PPairingRequest, - PostMessagePairingRequest, - WalletConnectPairingRequest, - NetworkType, - AnalyticsInterface -} from '@airgap/beacon-types' +import { NetworkType, AnalyticsInterface } from '@airgap/beacon-types' import { MergedWallet } from '../../utils/wallets' export interface AlertButton { @@ -20,9 +14,9 @@ export interface AlertConfig { timer?: number buttons?: AlertButton[] pairingPayload?: { - p2pSyncCode: () => Promise - postmessageSyncCode: () => Promise - walletConnectSyncCode: () => Promise + p2pSyncCode: string + postmessageSyncCode: string + walletConnectSyncCode: string networkType: NetworkType } closeButtonCallback?: () => void diff --git a/packages/beacon-ui/src/ui/alert/components/pairing-alert/index.tsx b/packages/beacon-ui/src/ui/alert/components/pairing-alert/index.tsx index 28ea388ab..3706764bf 100644 --- a/packages/beacon-ui/src/ui/alert/components/pairing-alert/index.tsx +++ b/packages/beacon-ui/src/ui/alert/components/pairing-alert/index.tsx @@ -10,15 +10,13 @@ import { StorageKey } from '@airgap/beacon-types' import QR from 'src/components/qr' import useWallets from '../../hooks/useWallets' import { AlertConfig } from '../../common' -import { useEffect, useState } from 'react' -import { Serializer } from '@airgap/beacon-core' -// todo remove any const PairingAlert: React.FC> = (props) => { - // const { wcPayload, p2pPayload, postPayload, onClose } = props - const [wcPayload, setWcPayload] = useState('') - const [p2pPayload, setP2pPayload] = useState('') - const [postPayload, setPostPayload] = useState('') + const { + walletConnectSyncCode: wcPayload, + p2pSyncCode: p2pPayload, + postmessageSyncCode: postPayload + } = props.pairingPayload! const wallets = useWallets() const [ wallet, @@ -106,22 +104,6 @@ const PairingAlert: React.FC> = (props) => ) } - useEffect(() => { - const serializer = new Serializer() - props.pairingPayload - ?.p2pSyncCode() - .then(async (req) => setP2pPayload(await serializer.serialize(req))) - .catch((err) => console.error(err.message)) - props.pairingPayload - ?.walletConnectSyncCode() - .then((req) => setWcPayload(req.uri)) - .catch((err) => console.error(err.message)) - props.pairingPayload - ?.postmessageSyncCode() - .then(async (req) => setPostPayload(await serializer.serialize(req))) - .catch((err) => console.error(err.message)) - }, []) - return ( { setShowMoreContent(false) - const serializer = new Serializer() - const postmessageCode = await serializer.serialize(postPayload) - const message: ExtensionMessage = { target: ExtensionMessageTarget.EXTENSION, - payload: postmessageCode, + payload: postPayload, targetId: wallet?.id } // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -253,7 +244,7 @@ const useConnect = ( if (wallet?.firefoxId) { const message: ExtensionMessage = { target: ExtensionMessageTarget.EXTENSION, - payload: postmessageCode, + payload: postPayload, targetId: wallet?.firefoxId } // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -280,9 +271,7 @@ const useConnect = ( setShowMoreContent(false) if (p2pPayload) { - const serializer = new Serializer() - const code = await serializer.serialize(p2pPayload) - const link = getTzip10Link(wallet?.deepLink || '', code) + const link = getTzip10Link(wallet?.deepLink || '', p2pPayload) window.open(link, '_blank', 'noopener') }