增加relay钱包

This commit is contained in:
CounterFire2023 2023-10-18 18:42:57 +08:00
parent 01c63eaf1d
commit bf9e2d7597
6 changed files with 176 additions and 88 deletions

View File

@ -261,6 +261,9 @@ extern "C"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
JNIEXPORT jint JNICALL JNI_JCFW(runJS)(JNIEnv *env, jclass clazz, jstring j_fun_id, jstring j_method_name, jobjectArray j_params)
{
if (!_isStarted) {
return 0;
}
std::string funId = JniHelper::jstring2string(j_fun_id);
std::string methodName = JniHelper::jstring2string(j_method_name);
LOGD("jni call %s | %s", methodName.c_str(), funId.c_str());

File diff suppressed because one or more lines are too long

View File

@ -13,15 +13,15 @@ function promiseCb(funId, promiseFun, dataParser) {
}
/**
* oauth login before init internal wallet
* @param {string} channel:
* 0: google,
* 1: apple,
* 2: tiktok,
* 3: facebook,
* 4: twitter
* 5: tg,
* 6: email,
* 7: discord
* @param {string} channel:
* 0: google,
* 1: apple,
* 2: tiktok,
* 3: facebook,
* 4: twitter
* 5: tg,
* 6: email,
* 7: discord
* 10: client
* @param {string} env: dev release
* @param {string} account: guest account to bind
@ -33,7 +33,7 @@ function walletLogin(funId, channel, env, account) {
channel = parseInt(channel);
env = env || 'dev';
console.log('walletLogin: ' + channel);
promiseCb(funId, wallet.preLogin(channel, env, account));
promiseCb(funId, jc.wallet.preLogin(channel, env, account));
}
function updateGameInfo(funId, info) {
@ -74,9 +74,15 @@ function initThirdPartyWallet(funId, chain, env) {
});
}
function initRelayWallet(funId, chain, env) {
chain = parseInt(chain);
promiseCb(funId, jc.wallet.initRelayWallet(chain, env));
}
/**
* all chain list we supported
* @return {string} JSON string of
* @return {string} JSON string of
* [{ name: string
* type: string
* rpc: string
@ -130,7 +136,7 @@ function loginSign(funId, nonce, tips) {
* if account is null, we`ll query for current account of wallet
*/
function getEthBalance(funId, account) {
promiseCb(funId, jc.wallet.getBalance(account));
promiseCb(funId, jc.wallet.chainCommon.getBalance(account));
}
/**
@ -141,7 +147,7 @@ function getEthBalance(funId, account) {
*/
function sendEth(funId, to, amount, estimate) {
estimate = (estimate || '0') | 0;
promiseCb(funId, jc.wallet.sendEth(to, amount, estimate));
promiseCb(funId, jc.wallet.chainCommon.sendEth(to, amount, estimate));
}
/**
@ -172,7 +178,7 @@ function erc20Info(funId, address) {
* @param {string} account:
*/
function erc20Balance(funId, address, account) {
promiseCb(funId, jc.wallet.erc20Balance(address, account));
promiseCb(funId, jc.wallet.erc20Standard.getBalanceOf(address, account));
}
/**
* send ERC20 token to to
@ -183,7 +189,7 @@ function erc20Balance(funId, address, account) {
*/
function sendErc20(funId, address, to, amount, estimate) {
estimate = (estimate || '0') | 0;
promiseCb(funId, jc.wallet.sendErc20(address, to, amount, estimate));
promiseCb(funId, jc.wallet.erc20Standard.transfer({address, to, amount, estimate}));
}
/**
@ -195,7 +201,7 @@ function sendErc20(funId, address, to, amount, estimate) {
*/
function sendErc721(funId, address, to, tokenId, estimate) {
estimate = (estimate || '0') | 0;
promiseCb(funId, jc.wallet.sendNFT(address, to, tokenId, estimate));
promiseCb(funId, jc.wallet.erc721Standard.transfer({address, to, tokenId, estimate}));
}
/**
@ -215,7 +221,7 @@ function erc721Balance(funId, address, account, chainId) {
* @param {string} tokenId: nft id of NFT
*/
function erc1155Balance(funId, address, account, tokenId) {
promiseCb(funId, jc.wallet.erc1155Balance(address, account, tokenId));
promiseCb(funId, jc.wallet.erc1155Standard.getBalanceOf(address, account, tokenId));
}
/**
@ -230,7 +236,7 @@ function sendErc1155(funId, address, to, tokenIds, amounts, estimate) {
tokenIds = JSON.parse(tokenIds);
amounts = JSON.parse(amounts);
estimate = (estimate || '0') | 0;
promiseCb(funId, jc.wallet.sendErc1155(address, to, tokenIds, amounts, estimate));
promiseCb(funId, jc.wallet.erc1155Standard.transferBatch({address, to, tokenIds, amounts, estimate}));
}
/**
@ -276,8 +282,8 @@ function exportWalletSecKey(funId, pass) {
// ======= begin of interact with contract =======
/**
* mint NFT
* @param {string} address: contract address of NFT
* mint NFT
* @param {string} address: contract address of NFT
* @param {string} tokenIds: token id of NFT, JSON string of string array
* @parsm {string} startTime: time of signature generation
* @param {string} saltNonce: nonce of signature
@ -386,8 +392,7 @@ function emailInfo(funId) {
* @param {string} type
*/
function sendEmailCode(funId, email, type) {
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
promiseCb(funId, wallet.emailVerifySvr.sendEmailCode(email, type));
promiseCb(funId, jc.wallet.emailVerifySvr.sendEmailCode(email, type));
}
/**
* verify email with code, and update email
@ -403,8 +408,7 @@ function verifyEmail(funId, email, code) {
* @param {string} email
*/
function checkEmailExists(funId, email) {
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
promiseCb(funId, wallet.emailVerifySvr.isEmailRegister(email));
promiseCb(funId, jc.wallet.emailVerifySvr.isEmailRegister(email));
}
/**
* regist with email
@ -413,8 +417,7 @@ function checkEmailExists(funId, email) {
* @param {*} code
*/
function emailRegist(funId, email, password, code) {
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
promiseCb(funId, wallet.emailVerifySvr.registByEmail(email, password, code));
promiseCb(funId, jc.wallet.emailVerifySvr.registByEmail(email, password, code));
}
/**
@ -423,8 +426,7 @@ function emailRegist(funId, email, password, code) {
* @param {*} password
*/
function emailLogin(funId, email, password) {
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
promiseCb(funId, wallet.emailLogin(email, password));
promiseCb(funId, jc.wallet.emailLogin(email, password));
}
/**
@ -619,7 +621,7 @@ function gameMallBuy(funId, orderId, currency, price, startTime, saltNonce, sign
);
}
/**
/**
* buy nft from mall
* @param {string} currency: address of currency
* @param {string} addresses: address of nft token, JSON string of array
@ -662,7 +664,7 @@ function nftMallBuy(funId, currency, addresses, ids, amounts, values, signature,
* @param {string} amount: amount of currency
* @param {string} gas: gas price
* @param {string} estimate: 0: execute; 1: only estimate gas price; default: 0
*/
*/
function buyTokenWithErc20(funId, currency, amount, gas, estimate) {
estimate = (estimate || '0') | 0;
promiseCb(
@ -773,7 +775,7 @@ function resetWalletAddress(funId) {
}
/**
* storage pass with google drive
* @param {string} key: current account address
* @param {string} key: current account address
* @param {string} val: pass for current account
*/
function storePassLocal(funId, key, val) {
@ -790,3 +792,4 @@ function restorePassLocal(funId, key) {
function getLocalPassState(funId, key) {
promiseCb(funId, jc.wallet.nativeSvr.passStorageState(key));
}

View File

@ -1,10 +1,10 @@
if (window.JavascriptJavaBridge) {
console.log('regist android jsb.reflection');
console.log('regist android jsb.reflection')
jsb.reflection = new JavascriptJavaBridge();
} else if (window.JavaScriptObjCBridge) {
jsb.reflection = new JavaScriptObjCBridge();
}
window.jumpToWallet = function (url) {
window.jumpToWallet = function(url) {
url = url || 'wc://';
if (window.JavascriptJavaBridge) {
url = 'metamask://wc?uri=' + url;
@ -13,9 +13,25 @@ window.jumpToWallet = function (url) {
}
console.log('open native: ' + url);
jsb.toWallet(url);
};
}
window.toRelayPage = function(url) {
// https://metamask.app.link/dapp/www.sample.com/page.html
// okx://wallet/dapp/details?dappUrl=https://www.sample.com/page.html
let okxUrl = `okx://wallet/dapp/details?dappUrl=${url}`;
//let okxUrl = `https://metamask.app.link/dapp/${url.replace('https://', '')}`;
jsb.toWallet(okxUrl);
}
function nativeCallBack(...args) {
console.log(`jniCallback: ${args[0]}`);
jc.wallet.nativeSvr.handleNativeCallback(...args);
}
function onGamePause() {
console.log('game pause');
}
function onGameResume() {
console.log('game resume');
jc.wallet.relaySvr.checkResult();
}

View File

@ -150,6 +150,12 @@ public class MainActivity extends UnityPlayerActivity
timer.sendEmptyMessage(JSTimers.JS_TICK);
}
@Override protected void onResume(){
super.onResume();
String[] paramArr = new String[0];
JcSDK.callNativeJS("", "onGameResume", paramArr);
}
public static class JSTimers extends Handler {
public static final int JS_TICK = 0;

View File

@ -87,6 +87,8 @@ public class JcSDK {
String downloadUrl = "https://metamask.io/download/";
if (url.startsWith("imtokenv2")) {
downloadUrl = "https://token.im/download";
} else if (url.startsWith("okx://")) {
downloadUrl = "https://www.okx.com/download";
}
i.setData(Uri.parse(downloadUrl));
MainActivity.app.startActivity(i);