wallet-test/Assets/scripts/WalletTestPanel.cs
2022-09-13 11:11:02 +08:00

140 lines
3.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class WalletTestPanel : MonoBehaviour
{
private static string TAG = "JCWalletPanel";
private static ILogger logger = Debug.unityLogger;
[SerializeField]
private Text textView;
[SerializeField]
private ScrollRect scrollControl;
// Start is called before the first frame update
void Start(){
}
// Update is called once per frame
void Update(){
}
public void writeTxt(string msg) {
textView.text += "\n" + msg;
scrollToBottom();
}
IEnumerator scrollToBottom()
{
yield return new WaitForEndOfFrame();
scrollControl.verticalNormalizedPosition = 0f;
}
public void initWalletEnv()
{
#if UNITY_ANDROID || UNITY_IOS || UNITY_IPHONE
WalletPanel.initWalletEnv(delegate (string jsonStr){
logger.Log(TAG, "wallet env inited.");
});
#endif
}
public void testInitWallet(){
WalletPanel.callWalletMethod("initWallet",
new [] { "1", "111111" },
delegate (string jsonStr){
logger.Log(TAG, "initWallet result: " + jsonStr);
writeTxt("initWallet result: " + jsonStr);
});
}
public void testSignLogin(){
WalletPanel.callWalletMethod("loginSign",
new [] { "login request", "123455" },
delegate (string jsonStr){
logger.Log(TAG, "loginSign result: " + jsonStr);
writeTxt("loginSign result: " + jsonStr);
});
}
public void testAddAccount(){
WalletPanel.callWalletMethod("createAccount",
new string[0],
delegate (string jsonStr){
logger.Log(TAG, "createAccount result: " + jsonStr);
writeTxt("createAccount result: " + jsonStr);
});
}
public void testImportAccount(){
string key =
"53ba1beb03bd29e25fcb22430e26a03aa6c48b82e60bb0612f02e2888c90bc51";
WalletPanel.callWalletMethod("importAccount",
new [] { key },
delegate (string jsonStr){
logger.Log(TAG, "importAccount result: " + jsonStr);
writeTxt("importAccount result: " + jsonStr);
});
}
public void testCreateIcon()
{
string address = "0xb59f7DE6B6544a1d12df90a317dC3b1E037AF9A3";
string width = "100";
WalletPanel
.callWalletMethod("generateIcon",
new [] { address, width },
delegate (string jsonStr)
{
logger.Log (TAG, jsonStr);
writeTxt("create icon result: " + jsonStr);
});
}
public void testGetEthBalance(){
string address = "0x9981b97dAB4A1e74D65b50eFf47Ac6c5D9Bb2919";
WalletPanel.callWalletMethod("getEthBalance",
new [] { address },
delegate (string jsonStr){
logger.Log (TAG, "balance:: " + jsonStr);
writeTxt("get balance result: " + jsonStr);
});
}
public void testChangeChain() {
WalletPanel.callWalletMethod("changeChain",
new [] {"97"},
delegate (string jsonStr){
logger.Log(TAG, "result:: " + jsonStr);
writeTxt("change chain result: " + jsonStr);
});
}
public void testScanQR() {
WalletPanel.callWalletMethod("scanQRCode",
new [] {"扫码"},
delegate (string jsonStr){
logger.Log(TAG, "result:: " + jsonStr);
writeTxt("sign result: " + jsonStr);
});
}
public void testGoogleLogin() {
WalletPanel.callWalletMethod("signWithGoogle",
new string[0],
delegate (string jsonStr){
logger.Log(TAG, "result:: " + jsonStr);
writeTxt("login result: " + jsonStr);
});
}
public void testGoogleLogout() {
WalletPanel.callWalletMethod("signOutGoogle",
new string[0],
delegate (string jsonStr){
logger.Log(TAG, "result:: " + jsonStr);
writeTxt("login out result: " + jsonStr);
});
}
}