From f3161c8340d425ee303fe1418c85e93c853a43e3 Mon Sep 17 00:00:00 2001 From: cebgcontract <99630598+cebgcontract@users.noreply.github.com> Date: Thu, 21 Jul 2022 10:24:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0wallet=20env=20=E5=87=86?= =?UTF-8?q?=E5=A4=87=E5=A5=BD=E5=90=8E=E7=9A=84=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/AppDelegate.cpp | 1 - Classes/JcWallet.cpp | 3 ++- js/main.js | 60 ++++++++++++++++++++++++++++++++++------- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/Classes/AppDelegate.cpp b/Classes/AppDelegate.cpp index e272c50..a035acd 100755 --- a/Classes/AppDelegate.cpp +++ b/Classes/AppDelegate.cpp @@ -72,7 +72,6 @@ bool AppDelegate::applicationDidFinishLaunching() se->addAfterCleanupHook([]() { JSBClassType::destroy(); }); - return true; } diff --git a/Classes/JcWallet.cpp b/Classes/JcWallet.cpp index cd7d203..6caaa5d 100644 --- a/Classes/JcWallet.cpp +++ b/Classes/JcWallet.cpp @@ -107,6 +107,7 @@ NS_CC_BEGIN EventDispatcher::init(); g_app->start(); _isStarted = true; + WalletEvent::Emit("wallet_init_event", "{}"); } } @@ -133,7 +134,7 @@ NS_CC_BEGIN result = ""; } cocos2d::log("method: %s ::result: %s", data->methodName.c_str(), result.c_str()); - WalletEvent::Emit("wallet_inited", result.c_str()); + WalletEvent::Emit(data->funId.c_str(), result.c_str()); return const_cast(result.c_str()); } diff --git a/js/main.js b/js/main.js index f185558..7fbaa71 100644 --- a/js/main.js +++ b/js/main.js @@ -1,36 +1,76 @@ console.log('>>hi tiny wallet3') function initWallet(password) { - if (typeof jc === 'undefined' || typeof jc.wwallet === 'undefined') { - var wallet = new jcwallet.default(password); + try { + if ( !window.jc || !jc.wwallet ) { + var wallet = new jcwallet.default(password); + } + let address = jc.wallet.currentAccount().address + return JSON.stringify({errcode: 0, data: address}); + } catch(err) { + return JSON.stringify({errcode: 1, errmsg: err}); } - return jc.wallet.currentAccount().address; } function currentAccount() { - return jc.wallet.currentAccount().address; + try { + let address = jc.wallet.currentAccount().address + return JSON.stringify({errcode: 0, data: address}); + } catch(err) { + return JSON.stringify({errcode: 1, errmsg: err}); + } } function loginSign(nonce, tips) { - return jc.wallet.loginSign(nonce, tips); + try { + let result = jc.wallet.loginSign(nonce, tips); + return JSON.stringify({errcode: 0, data: result}); + } catch(err) { + return JSON.stringify({errcode: 1, errmsg: err}); + } } function createAccount() { - return jc.wallet.createAccount(); + try { + let result = jc.wallet.createAccount(); + return JSON.stringify({errcode: 0, data: result}); + } catch(err) { + return JSON.stringify({errcode: 1, errmsg: err}); + } } function importAccount(privateKey) { - return jc.wallet.importAccount(privateKey); + try { + let address = jc.wallet.importAccount(privateKey) + return JSON.stringify({errcode: 0, data: address}); + } catch(err) { + return JSON.stringify({errcode: 1, errmsg: err}); + } } function selectAccount(address) { - return jc.wallet.selectAccount(address); + try { + let result = jc.wallet.selectAccount(address); + return JSON.stringify({errcode: 0, data: result}); + } catch(err) { + return JSON.stringify({errcode: 1, errmsg: err}); + } } function getBalance(address) { - return jc.wallet.getBalance(address); + try { + let result = jc.wallet.getBalance(address); + return JSON.stringify({errcode: 0, data: result}); + } catch(err) { + return JSON.stringify({errcode: 1, errmsg: err}); + } } function sendEth(to, amount) { - jc.wallet.sendEth(to, amount); + try { + let result = jc.wallet.sendEth(to, amount); + return JSON.stringify({errcode: 0, data: result}); + } catch(err) { + return JSON.stringify({errcode: 1, errmsg: err}); + } }