From 6bc467970b6bf6e6cc3e266caaee5c509961c30c Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Fri, 4 Aug 2023 09:59:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9main.js=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Data/js/main.js | 22 +++++++++++++++++----- Data/js/platform.js | 34 ++++++++++++++++------------------ 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/Data/js/main.js b/Data/js/main.js index 5bafb7f..8188c64 100644 --- a/Data/js/main.js +++ b/Data/js/main.js @@ -522,18 +522,30 @@ function buyTokenWithErc20(funId, currency, amount, gas, estimate) { } // begin of token mall -// begin of google pay +// begin of in-app pay function queryGoogleProducts(funId, productIds) { let ids = JSON.parse(productIds); console.log('queryGoogleProducts:: ' + productIds); - promiseCb(funId, jc.wallet.paySvr.queryGoogleProducts(ids)); + if (window.JavascriptJavaBridge) { + promiseCb(funId, jc.wallet.paySvr.queryGoogleProducts(ids)); + } else { + promiseCb(funId, jc.wallet.paySvr.queryIOSProducts(ids)); + } } function queryGooglePurchases(funId) { - promiseCb(funId, jc.wallet.paySvr.queryGooglePurchases()); + if (window.JavascriptJavaBridge) { + promiseCb(funId, jc.wallet.paySvr.queryGooglePurchases()); + } else { + promiseCb(funId, jc.wallet.paySvr.queryIOSPurchases()); + } } function beginGoogleBuy(funId, productId, orderId) { - promiseCb(funId, jc.wallet.paySvr.buyGoogleProduct(productId, orderId)); + if (window.JavascriptJavaBridge) { + promiseCb(funId, jc.wallet.paySvr.buyGoogleProduct(productId, orderId)); + } else { + promiseCb(funId, jc.wallet.paySvr.beginIOSPurchase(productId, orderId)); + } } -// end of google pay +// end of in-app pay diff --git a/Data/js/platform.js b/Data/js/platform.js index c93c059..87b0796 100644 --- a/Data/js/platform.js +++ b/Data/js/platform.js @@ -1,23 +1,21 @@ if (window.JavascriptJavaBridge) { - console.log('register android jsb.reflection') - jsb.reflection = new JavascriptJavaBridge() + console.log('regist android jsb.reflection'); + jsb.reflection = new JavascriptJavaBridge(); } else if (window.JavaScriptObjCBridge) { - jsb.reflection = new JavaScriptObjCBridge() + jsb.reflection = new JavaScriptObjCBridge(); } - window.jumpToWallet = function (url) { - url = url || 'wc://' - console.log('jumpToWallet: ' + url) - url = 'metamask://wc?uri=' + url - // url = 'imtokenv2://wc?uri='+url - jsb.toWallet(url) - // jsb.reflection.callStaticMethod( - // 'com/jc/jcfw/JcSDK', - // 'toWallet', - // '(Ljava/lang/String;)V', - // url || 'wc://' - // ) -} -function nativeCallback(funId, msg) { - console.log(`native call back:: funid: ${funId} msg: ${msg}`) + url = url || 'wc://'; + if (window.JavascriptJavaBridge) { + url = 'metamask://wc?uri=' + url; + } else { + url = `https://metamask.app.link/wc?uri=${encodeURIComponent(url)}`; + } + console.log('open native: ' + url); + jsb.toWallet(url); +}; + +function nativeCallBack(...args) { + console.log(`jniCallback: ${args[0]}`); + jc.wallet.nativeSvr.handleNativeCallback(...args); }