import { _decorator, Component, Node, native } from "cc";
const { ccclass, property } = _decorator;
import { createRequestData } from "./WalletSdkUtils";

@ccclass("btn_click")
export class btn_click extends Component {
  start() { }

  update(deltaTime: number) { }
  /**
   * btn_onclick
   */
  public btn_onclick() {
    console.info("点击了按钮");
    // @ts-ignore
    var ret = native.reflection.callStaticMethod("JSHandleClass", "init");
  }

  /**
   * 启动连接
   */
  public btn_onclick1() {
    console.info("点击了按钮");
    var ret = native.reflection.callStaticMethod(
      "JSHandleClass",
      "walleConnectFun:",
      "imtokenv2"
    );
  }

  //发送交易
  public async btn_onclick2() {
    console.info("点击了按钮");
    var temp = createRequestData(
      "0x4eDE150f62dc21aDC0F39a2A02c95A5Cc1FD7B2C",
      "0x62cC9fd83d48eFCe313695bA6a3245bCCC7f196e",
      "Mint",
      "0x4eDE150f62dc21aDC0F39a2A02c95A5Cc1FD7B2C",
    );
    var jsonObj = {
      "method": "eth_sendTransaction",
      "params": JSON.stringify(temp)
    };
    var jsonStr = JSON.stringify(jsonObj);
    ///0x2eB535d54382eA5CED9183899916A9d39e093877

    var ret = native.reflection.callStaticMethod(
      "JSHandleClass",
      "sendContractFun:",
      jsonStr
    );
  }
  public async btn_onclick3() {
    // console.info("点击了按钮");
    // var temp = createRequestData(
    //   "0x4eDE150f62dc21aDC0F39a2A02c95A5Cc1FD7B2C",
    //   "0x62cC9fd83d48eFCe313695bA6a3245bCCC7f196e",
    //   "",
    //   "Mint",
    //   "0x4eDE150f62dc21aDC0F39a2A02c95A5Cc1FD7B2C",
    // );
    // var jsonObj = {
    //   "method": "eth_sendTransaction",
    //   "params": JSON.stringify(temp)
    // };
    var jsonObj = {
      "method": "personal_sign",
      "params": [
        "0x49206861766520313030e282ac",
        "0x2eB535d54382eA5CED9183899916A9d39e093877"
      ]
    };
    var jsonStr = JSON.stringify(jsonObj);
    ///0x2eB535d54382eA5CED9183899916A9d39e093877

    var ret = native.reflection.callStaticMethod(
      "JSHandleClass",
      "sendMessageFun:",
      jsonStr
    );
  }
}
