diff --git a/src/docs/wallet/getting-started/web/getting-started.mdx b/src/docs/wallet/getting-started/web/getting-started.mdx index aee5fe10..1c0faf2a 100644 --- a/src/docs/wallet/getting-started/web/getting-started.mdx +++ b/src/docs/wallet/getting-started/web/getting-started.mdx @@ -32,7 +32,6 @@ const connectApp = async (): Promise => { client .connect(async (message) => { console.log("beacon message", message); - let response: BeaconResponseInputMessage; switch (message.type) { case BeaconMessageType.PermissionRequest: @@ -43,19 +42,26 @@ const connectApp = async (): Promise => { scopes: message.scopes, id: message.id, publicKey: - "3b92229274683b311cf8b040cf91ac0f8e19e410f06eda5537ef077e718e0024", // Optional + "3b92229274683b311cf8b040cf91ac0f8e19e410f06eda5537ef077e718e0024" + } + + // Optional // If the user aborts an action at any time, you can send back an error: response = { type: BeaconMessageType.Error, id: message.id, - errorType: BeaconErrorType.ABORTED_ERROR, break; + errorType: BeaconErrorType.ABORTED_ERROR + } + break; case BeaconMessageType.SignPayloadRequest: // Sign message.payload and return signature response = { type: BeaconMessageType.SignPayloadResponse, id: message.id, signingType: message.signingType, - signature: "edsig...", break; + signature: "edsig..." + } + break; case BeaconMessageType.OperationRequest: // Prepare transaction based on the details give in message.operationDetails // message.operationDetails only contains a partial tezos transaction. Not all fields are mandatory @@ -64,7 +70,10 @@ const connectApp = async (): Promise => { response = { type: BeaconMessageType.OperationResponse, id: message.id, - transactionHash: "op...", // Optional + transactionHash: "op..." + } + + // Optional // If the transaction cannot be prepared, (eg. run_operations fails), an error containing the rpc error can be returned let error = [ { @@ -72,29 +81,36 @@ const connectApp = async (): Promise => { id: "proto.008-PtEdo2Zk.contract.balance_too_low", contract: "tz1...", balance: "100", - amount: "200", + amount: "200" }, ]; // RPC error response = { type: BeaconMessageType.Error, id: message.id, errorType: BeaconErrorType.TRANSACTION_INVALID_ERROR, - errorData: error, break; + errorData: error + } + break; case BeaconMessageType.BroadcastRequest: response = { type: BeaconMessageType.OperationResponse, id: message.id, - transactionHash: "op...", break; + transactionHash: "op..." + } + break; default: response = { type: BeaconMessageType.Error, id: message.id, - errorType: BeaconErrorType.ABORTED_ERROR, + errorType: BeaconErrorType.ABORTED_ERROR + } } client.respond(response); }) - .catch((error) => console.error("connect error", error));connectApp().catch((error) => console.error("connect error", error)); + .catch((error) => console.error("connect error", error)); + + connectApp().catch((error) => console.error("connect error", error)); ``` By adding the code above, our app is now ready to receive messages. Now all that is left for us to do is connecting to a dApp. @@ -112,6 +128,7 @@ const isBeaconMessage: (obj: unknown) => obj is P2PPairingRequest = ( typeof (obj as P2PPairingRequest).relayServer === "string" ); + const handshakeMessage = ""; // This was received from the dApp, eg. through QR scanning or deeplink const deserialized = await new Serializer().deserialize(handshakeMessage);