Skip to content

Commit

Permalink
Updated JSON serializtion params in Typescript side;
Browse files Browse the repository at this point in the history
  • Loading branch information
k-karuna committed Nov 24, 2023
1 parent 09d5a23 commit 54f58a8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Runtime/View/AuthenticationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ void Start()
Tezos.Wallet.EventManager.AccountDisconnected += OnAccountDisconnected;
}

void OnHandshakeReceived(HandshakeData handshake_data)
void OnHandshakeReceived(HandshakeData handshakeData)
{
EnableUI(isAuthenticated: false);
qrCodeView.SetQrCode(handshake_data.PairingData);
qrCodeView.SetQrCode(handshakeData);
}

void OnAccountConnected(AccountInfo account_info)
Expand Down
5 changes: 3 additions & 2 deletions Runtime/View/QRCodeView.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using TezosSDK.Beacon;
using UnityEngine;
using UnityEngine.UI;
using ZXing;
Expand All @@ -18,9 +19,9 @@ void Start()
_texture.filterMode = FilterMode.Point;
}

public void SetQrCode(string handshake)
public void SetQrCode(HandshakeData handshakeData)
{
var uri = "tezos://?type=tzip10&data=" + handshake;
var uri = "tezos://?type=tzip10&data=" + handshakeData.PairingData;
EncodeTextToQrCode(uri);
}

Expand Down
2 changes: 1 addition & 1 deletion WebGLFrontend/output/StreamingAssets/webgl-frontend.js

Large diffs are not rendered by default.

27 changes: 24 additions & 3 deletions WebGLFrontend/src/WalletProviders/BaseWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,35 @@ class BaseWallet implements AbstractWallet {
localStorage.setItem("iconUrl", this.iconUrl);
}

private CallUnityMethod(value: any) {
private CallUnityMethod(eventData: UnityEvent) {
const resultEventData = {
EventType: eventData.eventType,
Data: JSON.stringify(this.CapitalizeKeys(eventData.data)),
};

window.unityInstance.SendMessage(
"UnityBeacon",
"WalletEventManager",
"HandleEvent",
typeof value === "string" ? value : JSON.stringify(value)
JSON.stringify(resultEventData)
);
}

private CapitalizeKeys(obj: any): any {
if (Array.isArray(obj)) {
return obj.map((o) => this.CapitalizeKeys(o));
} else if (typeof obj === "object" && obj !== null) {
return Object.entries(obj).reduce(
(r, [k, v]) => ({
...r,
[`${k.charAt(0).toUpperCase()}${k.slice(1)}`]: this.CapitalizeKeys(v),
}),
{}
);
} else {
return obj;
}
}

GetHexPayloadString(
signingType: SigningType,
plainTextPayload: string
Expand Down
1 change: 0 additions & 1 deletion WebGLFrontend/src/WalletProviders/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ interface AbstractWallet {
CallUnityOnAccountConnected(accountInfo: AccountInfo): void;
CallUnityOnAccountDisconnected(accountInfo: AccountInfo): void;
CallUnityOnPayloadSigned(result: SignResult): void;

CallUnityOnContractCallCompleted(result: OperationResult): void;
CallUnityOnAccountFailedToConnect(error: Error): void;
CallUnityOnContractCallFailed(error: Error): void;
Expand Down
43 changes: 28 additions & 15 deletions WebGLFrontend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {BaseFileUploaderType, BaseUploaderConfig, IpfsUploaderConfig, IpfsUploaderType,} from "./FileUploaders/Types";
import {Wallet, WalletType} from "./WalletProviders/Types";

import Base64Uploader from "./FileUploaders/Base64Uploader";
import IpfsUploader from "./FileUploaders/IpfsUploader";
import BeaconWallet from "./WalletProviders/Beacon";
import IpfsUploader from "./FileUploaders/IpfsUploader";
import KukaiWallet from "./WalletProviders/Kukai";
import {AccountInfo, DAppClient} from "@airgap/beacon-sdk";
import { AccountInfo, DAppClient } from "@airgap/beacon-sdk";
import { Wallet, WalletType } from "./WalletProviders/Types";
import {
BaseFileUploaderType,
BaseUploaderConfig,
IpfsUploaderConfig,
IpfsUploaderType,
} from "./FileUploaders/Types";

let kukaiWallet: KukaiWallet;
let beaconWallet: BeaconWallet;
Expand All @@ -22,9 +26,10 @@ function InitWalletProvider(
if (!kukaiWallet) kukaiWallet = new KukaiWallet(appName, appUrl, iconUrl);
window.WalletProvider = kukaiWallet;
}

if (walletType === WalletType.beacon) {
if (!beaconWallet) beaconWallet = new BeaconWallet(appName, appUrl, iconUrl);
if (!beaconWallet)
beaconWallet = new BeaconWallet(appName, appUrl, iconUrl);
window.WalletProvider = beaconWallet;
}

Expand Down Expand Up @@ -60,19 +65,27 @@ async function UnityReadyEvent() {

if (beaconActiveAccount) {
InitWalletProvider(
beaconActiveAccount.network.type,
beaconActiveAccount.network.rpcUrl,
WalletType.beacon,
dappName,
dappUrl,
iconUrl);
beaconActiveAccount.network.type,
beaconActiveAccount.network.rpcUrl,
WalletType.beacon,
dappName,
dappUrl,
iconUrl
);

window.WalletProvider.client = dAppClient;
window.WalletProvider.ConnectAccount();
} else {
const networkName = localStorage.getItem("networkName")
const networkName = localStorage.getItem("networkName");
if (networkName) {
InitWalletProvider(networkName, "", WalletType.kukai, dappName, dappUrl, iconUrl);
InitWalletProvider(
networkName,
"",
WalletType.kukai,
dappName,
dappUrl,
iconUrl
);
window.WalletProvider.ConnectAccount();
}
}
Expand Down

0 comments on commit 54f58a8

Please sign in to comment.