Skip to content

Commit

Permalink
fix: identation
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaccoSordo committed Mar 6, 2024
1 parent d589fee commit 78b2fa9
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/docs/wallet/getting-started/web/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const connectApp = async (): Promise<void> => {
client
.connect(async (message) => {
console.log("beacon message", message);

let response: BeaconResponseInputMessage;
switch (message.type) {
case BeaconMessageType.PermissionRequest:
Expand All @@ -43,19 +42,26 @@ const connectApp = async (): Promise<void> => {
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
Expand All @@ -64,37 +70,47 @@ const connectApp = async (): Promise<void> => {
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 = [
{
kind: "temporary",
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.
Expand All @@ -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);
Expand Down

0 comments on commit 78b2fa9

Please sign in to comment.