remove some unused code
This commit is contained in:
parent
23f6445726
commit
bd5210d22e
@ -143,7 +143,7 @@ NS_CC_BEGIN
|
||||
}
|
||||
|
||||
char *JcWallet::runJsMethod(std::shared_ptr<JSMethodParam> data) {
|
||||
cocos2d::log("thread: %ld call method %s params: %lu", uv_thread_self(), data->methodName.c_str(), data->args.size());
|
||||
cocos2d::log("thread: %p call method %s params: %lu", uv_thread_self(), data->methodName.c_str(), data->args.size());
|
||||
se::Value value;
|
||||
bool ok = cocos2d::runGlobalMethod(data->methodName.c_str(), data->args, &value);
|
||||
static std::string result;
|
||||
@ -301,32 +301,6 @@ bool jsb_scanQRCode(se::State& s) {
|
||||
}
|
||||
SE_BIND_FUNC(jsb_scanQRCode)
|
||||
|
||||
|
||||
bool JSB_restoreKey(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc > 1) {
|
||||
std::string funid;
|
||||
ok = seval_to_std_string(args[0], &funid);
|
||||
SE_PRECONDITION2(ok, false, "funid is invalid!");
|
||||
std::string oid;
|
||||
ok = seval_to_std_string(args[1], &oid);
|
||||
SE_PRECONDITION2(ok, false, "oid is invalid!");
|
||||
NSString *nfunid = [NSString stringWithCString:funid.c_str() encoding:NSUTF8StringEncoding];
|
||||
NSString *noid = [NSString stringWithCString:oid.c_str() encoding:NSUTF8StringEncoding];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
|
||||
[window.rootViewController loadRestoreKey:nfunid oid: noid];
|
||||
});
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_restoreKey)
|
||||
|
||||
bool jsb_signWithGoogle(se::State& s) {
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
@ -491,7 +465,6 @@ bool jsb_register_walletevent_modules(se::Object* global) {
|
||||
getOrCreatePlainObject_r("jsb", global, &__jsbObj);
|
||||
__jsbObj->defineFunction("jcCallback", _SE(jsb_wallet_callback));
|
||||
__jsbObj->defineFunction("scanQRCode", _SE(jsb_scanQRCode));
|
||||
__jsbObj->defineFunction("restoreKey", _SE(JSB_restoreKey));
|
||||
__jsbObj->defineFunction("signWithGoogle", _SE(jsb_signWithGoogle));
|
||||
__jsbObj->defineFunction("signWithApple", _SE(jsb_signWithApple));
|
||||
__jsbObj->defineFunction("signWithTikTok", _SE(jsb_signWithTikTok));
|
||||
@ -500,6 +473,8 @@ bool jsb_register_walletevent_modules(se::Object* global) {
|
||||
__jsbObj->defineFunction("signOutGoogle", _SE(jsb_signOutGoogle));
|
||||
__jsbObj->defineFunction("showQRCode", _SE(JSB_showQRCode));
|
||||
__jsbObj->defineFunction("showWebPage", _SE(jsb_showWebPage));
|
||||
// JSB_signWithEmail
|
||||
// JSB_beginBuyJNI
|
||||
return true;
|
||||
}
|
||||
|
||||
|
10
Podfile
10
Podfile
@ -1,6 +1,16 @@
|
||||
platform :ios, '12.0'
|
||||
use_frameworks!
|
||||
|
||||
post_install do |installer|
|
||||
installer.generated_projects.each do |project|
|
||||
project.targets.each do |target|
|
||||
target.build_configurations.each do |config|
|
||||
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
target 'Unity-iPhone' do
|
||||
pod 'GoogleSignIn', :path => '/Users/zhl/Downloads/sourcecode/google/GoogleSignIn-iOS/'
|
||||
pod 'TikTokOpenSDK', '~> 5.0.14'
|
||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -68,22 +68,6 @@
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "91A0523E-D695-4DA1-801F-07902D05E64E"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "174"
|
||||
endingLineNumber = "174"
|
||||
landmarkName = "-nativeCb:hasErr:dataStr:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
@ -164,22 +148,6 @@
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "E0747763-2B1B-4962-9526-56C3D14B2FCC"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes_cocos/UIViewController+Share.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "24"
|
||||
endingLineNumber = "24"
|
||||
landmarkName = "shareWithFacebook(url)"
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
@ -228,22 +196,6 @@
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "60486E7D-44D6-4425-917D-BA6C5FEB4D22"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "193"
|
||||
endingLineNumber = "193"
|
||||
landmarkName = "-showPage:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
@ -276,5 +228,37 @@
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "3A702ECC-3A6F-49D9-B559-60DD627B3AE1"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes_cocos/JcWallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "188"
|
||||
endingLineNumber = "188"
|
||||
landmarkName = "initEnv()"
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "BC9EFF06-D59A-4CAE-8ADE-8B169EEEF334"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes_cocos/JcWallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "114"
|
||||
endingLineNumber = "114"
|
||||
landmarkName = "JcWallet::initEnv()"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
|
File diff suppressed because one or more lines are too long
791
js/main.js
791
js/main.js
@ -1,65 +1,55 @@
|
||||
console.log(">>begin load wallet main file");
|
||||
|
||||
/**
|
||||
* init wallet, must call this before all other method
|
||||
* @param {string} type: wallet type, 0: internal wallet, 1: third party wallet
|
||||
|
||||
*/
|
||||
function initWallet(funId, type, chain, channel) {
|
||||
type = parseInt(type)
|
||||
chain = parseInt(chain)
|
||||
channel = channel || 2; // 0:google, 1: apple, 2: tiktok
|
||||
channel = parseInt(channel);
|
||||
console.log(`initWallet:: type: ${type}, chain: ${chain}, channel: ${channel}`)
|
||||
try {
|
||||
let wallet;
|
||||
if (!window.jc || !jc.wallet) {
|
||||
wallet = new jcwallet.default({ chain, type });
|
||||
} else {
|
||||
wallet = jc.wallet;
|
||||
}
|
||||
type = parseInt(type);
|
||||
if (type === 1) {
|
||||
console.log("wallet init success, begin connect");
|
||||
wallet
|
||||
.initThirdPartyWallet()
|
||||
.then(() => {
|
||||
console.log("walletconnect connect success");
|
||||
let account = jc.wallet.currentAccount();
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: account}));
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("walletconnect connect error: " + JSON.stringify(err));
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
} else {
|
||||
wallet.initInternalWallet(channel)
|
||||
.then(() => {
|
||||
console.log("internal init success");
|
||||
let address = jc.wallet.nativeAccount;
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: address}));
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("internal wallet error: " + JSON.stringify(err));
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("wallet init with error: " + JSON.stringify(err));
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
}
|
||||
console.log('>> begin load wallet main file.');
|
||||
function promiseCb(funId, promiseFun, dataParser) {
|
||||
dataParser = dataParser || ((v) => v);
|
||||
promiseFun
|
||||
.then((result) => {
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: dataParser(result) }));
|
||||
})
|
||||
.catch((err) => {
|
||||
let code = err.statusCode || 1;
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: code, errmsg: err.message || err }));
|
||||
});
|
||||
}
|
||||
/**
|
||||
* current account for internal wallet
|
||||
* oauth login before init internal wallet
|
||||
* @param {*} channel 0: google, 1: apple, 2: tiktok, 3: facebook, 4: twitter 5: tg
|
||||
*/
|
||||
function currentAccount(funId) {
|
||||
try {
|
||||
let data = jc.wallet.currentAccountData;
|
||||
return JSON.stringify({errcode: 0, data});
|
||||
} catch (err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
}
|
||||
function walletLogin(funId, channel) {
|
||||
channel = parseInt(channel);
|
||||
console.log('walletLogin: ' + channel);
|
||||
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
|
||||
promiseCb(funId, wallet.preLogin(channel));
|
||||
}
|
||||
/**
|
||||
* init internal wallet with password
|
||||
* @param {number | string} chain chain id
|
||||
* @param {string} pass
|
||||
*/
|
||||
function initInternalWallet(funId, chain, pass, env) {
|
||||
chain = parseInt(chain);
|
||||
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
|
||||
promiseCb(funId, wallet.initInternalWallet(chain, pass, env), () => {
|
||||
return jc.wallet.nativeAccount;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* verify if password is correct
|
||||
* compare with local password hash
|
||||
* @param {string} pass password for wallet
|
||||
*/
|
||||
function verifyPassword(funId, pass) {
|
||||
promiseCb(funId, jc.wallet.verifyLocalPass(pass));
|
||||
}
|
||||
/**
|
||||
* init third party wallet
|
||||
* @param {number | string} chain chain id
|
||||
*/
|
||||
function initThirdPartyWallet(funId, chain, env) {
|
||||
chain = parseInt(chain);
|
||||
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 1 }) : jc.wallet;
|
||||
promiseCb(funId, wallet.initThirdPartyWallet(chain, env), () => {
|
||||
return jc.wallet.currentAccount();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,9 +58,9 @@ function currentAccount(funId) {
|
||||
function chainList(funId) {
|
||||
try {
|
||||
let data = jc.wallet.chainList;
|
||||
return JSON.stringify({errcode: 0, data});
|
||||
return JSON.stringify({ errcode: 0, data });
|
||||
} catch (err) {
|
||||
return JSON.stringify({ errcode: 1, errmsg: err });
|
||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -79,12 +69,9 @@ function chainList(funId) {
|
||||
function currentChain(funId) {
|
||||
try {
|
||||
let data = jc.wallet.currentChain;
|
||||
return JSON.stringify({errcode: 0,data});
|
||||
return JSON.stringify({ errcode: 0, data });
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -92,14 +79,7 @@ function currentChain(funId) {
|
||||
*/
|
||||
function changeChain(funId, chainId) {
|
||||
chainId = parseInt(chainId);
|
||||
jc.wallet
|
||||
.updateCurrentChain(chainId)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0,data: result }));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({ errcode: 1,errmsg: err }));
|
||||
});
|
||||
promiseCb(funId, jc.wallet.updateCurrentChain(chainId));
|
||||
}
|
||||
/**
|
||||
* [BOTH] get sign for login
|
||||
@ -107,14 +87,7 @@ function changeChain(funId, chainId) {
|
||||
* @param {string} tips: tips message when sign
|
||||
*/
|
||||
function loginSign(funId, nonce, tips) {
|
||||
jc.wallet
|
||||
.loginSign(nonce, tips)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 1,errmsg: err }));
|
||||
});
|
||||
promiseCb(funId, jc.wallet.loginSign(nonce, tips));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,35 +96,24 @@ function loginSign(funId, nonce, tips) {
|
||||
* if account is null, we`ll query for current account of wallet
|
||||
*/
|
||||
function getEthBalance(funId, account) {
|
||||
jc.wallet
|
||||
.getBalance(account)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
promiseCb(funId, jc.wallet.getBalance(account));
|
||||
}
|
||||
|
||||
/**
|
||||
* send ETH from current account
|
||||
* @param {string} to: target account
|
||||
* @param {string} amount:
|
||||
* @param {string} amount:
|
||||
* @param {number} estimate: 1: only estimate gas price
|
||||
*/
|
||||
function sendEth(funId, to, amount) {
|
||||
jc.wallet
|
||||
.sendEth(to, amount)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
function sendEth(funId, to, amount, estimate) {
|
||||
estimate = (estimate || '0') | 0;
|
||||
promiseCb(funId, jc.wallet.sendEth(to, amount, estimate));
|
||||
}
|
||||
|
||||
/**
|
||||
* [BOTH] generate ICON with hashed message
|
||||
* @param {string} msg:
|
||||
* @param {string} diameter: size of icon
|
||||
* @param {string} msg:
|
||||
* @param {string} diameter: size of icon
|
||||
*/
|
||||
function generateIcon(funId, msg, diameter) {
|
||||
try {
|
||||
@ -159,7 +121,7 @@ function generateIcon(funId, msg, diameter) {
|
||||
let result = jc.wallet.generateIconData(msg, diameter);
|
||||
return JSON.stringify({ errcode: 0, data: result });
|
||||
} catch (err) {
|
||||
return JSON.stringify({ errcode: 1, errmsg: err });
|
||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,41 +130,60 @@ function generateIcon(funId, msg, diameter) {
|
||||
* @param {string} address: address of ERC20
|
||||
*/
|
||||
function erc20Info(funId, address) {
|
||||
jc.wallet
|
||||
.erc20Info(address)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
promiseCb(funId, jc.wallet.erc20Info(address));
|
||||
}
|
||||
/**
|
||||
* get balance of ERC20
|
||||
* @param {string} address:
|
||||
* @param {string} account:
|
||||
* @param {string} address:
|
||||
* @param {string} account:
|
||||
*/
|
||||
function erc20Balance(funId, address, account) {
|
||||
jc.wallet
|
||||
.erc20Balance(address, account)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
promiseCb(funId, jc.wallet.erc20Balance(address, account));
|
||||
}
|
||||
/**
|
||||
* send ERC20 token to to
|
||||
*/
|
||||
function sendErc20(funId, address, to, amount) {
|
||||
jc.wallet.sendErc20(address, to, amount)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1, errmsg: err}));
|
||||
});
|
||||
function sendErc20(funId, address, to, amount, estimate) {
|
||||
estimate = (estimate || '0') | 0;
|
||||
promiseCb(funId, jc.wallet.sendErc20(address, to, amount, estimate));
|
||||
}
|
||||
|
||||
/**
|
||||
* send ERC721 NFT to to
|
||||
*/
|
||||
function sendErc721(funId, address, to, tokenId, estimate) {
|
||||
estimate = (estimate || '0') | 0;
|
||||
promiseCb(funId, jc.wallet.sendNFT(address, to, tokenId, estimate));
|
||||
}
|
||||
|
||||
/**
|
||||
* get balance of ERC721
|
||||
* @param {string} address: contract address of NFT
|
||||
* @param {string} account: wallet address
|
||||
* @param {string} chainId: chain id, number string
|
||||
*/
|
||||
function erc721Balance(funId, address, account, chainId) {
|
||||
promiseCb(funId, jc.wallet.erc721Standard.getBalance(address, account, chainId));
|
||||
}
|
||||
|
||||
/**
|
||||
* get balance of ERC1155
|
||||
* @param {string} address:
|
||||
* @param {string} account:
|
||||
* @param {string} tokenId:
|
||||
*/
|
||||
function erc1155Balance(funId, address, account, tokenId) {
|
||||
promiseCb(funId, jc.wallet.erc1155Balance(address, account, tokenId));
|
||||
}
|
||||
|
||||
/**
|
||||
* send ERC1155 to to
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
function showQRCode(funId, content) {
|
||||
@ -210,288 +191,322 @@ function showQRCode(funId, content) {
|
||||
jsb.showQRCode(funId, content);
|
||||
return JSON.stringify({ errcode: 0, data: 1 });
|
||||
} catch (err) {
|
||||
return JSON.stringify({ errcode: 1, errmsg: err });
|
||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
||||
}
|
||||
}
|
||||
|
||||
function showWebPage(funId, url) {
|
||||
try {
|
||||
jsb.showWebPage(funId, url);
|
||||
// jsb.openURL(url);
|
||||
// jsb.openURL(url);
|
||||
return JSON.stringify({ errcode: 0, data: 1 });
|
||||
} catch (err) {
|
||||
return JSON.stringify({ errcode: 1, errmsg: err });
|
||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
||||
}
|
||||
}
|
||||
|
||||
function scanQRCode(funId, title) {
|
||||
console.log('scanQRCode: ' + title)
|
||||
jc.wallet.scanQr(title)
|
||||
.then((result)=> {
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 1, errmsg: err }));
|
||||
});
|
||||
console.log('scanQRCode: ' + title);
|
||||
promiseCb(funId, jc.wallet.nativeSvr.scanQRCode(title));
|
||||
}
|
||||
|
||||
function exportWalletSecKey(funId) {
|
||||
function exportWalletSecKey(funId, pass) {
|
||||
try {
|
||||
let key = jsb.walletSecKey(funId)
|
||||
let key = jc.wallet.exportPrivateKey(pass);
|
||||
return JSON.stringify({ errcode: 0, data: key });
|
||||
} catch (err) {
|
||||
return JSON.stringify({ errcode: 1, errmsg: err });
|
||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
||||
}
|
||||
}
|
||||
|
||||
// ======= begin of interact with contract =======
|
||||
function buyNft721(funId, addresses, values, signature) {
|
||||
addresses = JSON.parse(addresses)
|
||||
values = JSON.parse(values)
|
||||
jc.wallet.jcStandard
|
||||
.buyNft721({
|
||||
addresses,
|
||||
values,
|
||||
signature,
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: JSON.stringify(result),
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
function buyNft1155(funId, addresses, values, ids, amounts, signature) {
|
||||
addresses = JSON.parse(addresses)
|
||||
values = JSON.parse(values)
|
||||
ids = JSON.parse(ids)
|
||||
amounts = JSON.parse(amounts)
|
||||
|
||||
jc.wallet.jcStandard
|
||||
.buyNft1155({
|
||||
addresses,
|
||||
values,
|
||||
ids,
|
||||
amounts,
|
||||
signature,
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: JSON.stringify(result),
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
function evolveNft721(
|
||||
funId,
|
||||
nftAddress,
|
||||
tokenIds,
|
||||
startTime,
|
||||
nonce,
|
||||
signature
|
||||
) {
|
||||
tokenIds = JSON.parse(tokenIds)
|
||||
jc.wallet.jcStandard
|
||||
.evolve721NFT({
|
||||
nftAddress,
|
||||
tokenIds,
|
||||
startTime,
|
||||
nonce,
|
||||
signature,
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: JSON.stringify(result),
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
function evolveChip(funId, tokenIds, startTime, nonce, signature) {
|
||||
tokenIds = JSON.parse(tokenIds)
|
||||
jc.wallet.jcStandard
|
||||
.evolveChip({
|
||||
function mintNFT(funId, address, tokenIds, startTime, saltNonce, signature, estimate) {
|
||||
tokenIds = JSON.parse(tokenIds);
|
||||
promiseCb(
|
||||
funId,
|
||||
jc.wallet.jcStandard.mintNFT({
|
||||
address,
|
||||
tokenIds,
|
||||
startTime,
|
||||
nonce,
|
||||
saltNonce,
|
||||
signature,
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: JSON.stringify(result),
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
function mintShardBatchUser(
|
||||
funId,
|
||||
tokenIds,
|
||||
amounts,
|
||||
startTime,
|
||||
nonce,
|
||||
signature
|
||||
) {
|
||||
tokenIds = JSON.parse(tokenIds)
|
||||
amounts = JSON.parse(amounts)
|
||||
|
||||
jc.wallet.jcStandard
|
||||
.mintShardBatchUser({
|
||||
tokenIds,
|
||||
amounts,
|
||||
startTime,
|
||||
nonce,
|
||||
signature,
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: JSON.stringify(result),
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
function shardMixByUser(
|
||||
funId,
|
||||
tokenId,
|
||||
nftType,
|
||||
payToken,
|
||||
payAmount,
|
||||
ids,
|
||||
amounts,
|
||||
startTime,
|
||||
nonce,
|
||||
signature
|
||||
) {
|
||||
ids = JSON.parse(ids)
|
||||
amounts = JSON.parse(amounts)
|
||||
|
||||
jc.wallet.jcStandard
|
||||
.shardMixByUser({
|
||||
tokenId,
|
||||
nftType,
|
||||
payToken,
|
||||
payAmount,
|
||||
ids,
|
||||
amounts,
|
||||
startTime,
|
||||
nonce,
|
||||
signature,
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: JSON.stringify(result),
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// addresses: [nftId, chip, sign_address]
|
||||
// values: [token_id,salt_nonce,startTime]
|
||||
// chipIds: [...chipIds]
|
||||
function pluginChip(
|
||||
funId,
|
||||
addresses,
|
||||
values,
|
||||
chipIds,
|
||||
slots,
|
||||
signature
|
||||
) {
|
||||
console.log('addresses:' + addresses)
|
||||
console.log('values:' + values)
|
||||
console.log('chipIds:' + chipIds)
|
||||
console.log('slots:' + slots)
|
||||
console.log('signature:' + signature)
|
||||
|
||||
addresses = JSON.parse(addresses)
|
||||
values = JSON.parse(values)
|
||||
chipIds = JSON.parse(chipIds)
|
||||
slots = JSON.parse(slots)
|
||||
jc.wallet.jcStandard
|
||||
.pluginChip({
|
||||
addresses,
|
||||
values,
|
||||
chipIds,
|
||||
slots,
|
||||
signature
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: JSON.stringify(result)}));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
// addresses: [nftId, chip, sign_address]
|
||||
// values: [token_id,salt_nonce,startTime]
|
||||
// chipIds: [...chipIds]
|
||||
function unplugChip(
|
||||
funId,
|
||||
addresses,
|
||||
values,
|
||||
chipIds,
|
||||
slots,
|
||||
signature
|
||||
) {
|
||||
|
||||
addresses = JSON.parse(addresses)
|
||||
values = JSON.parse(values)
|
||||
chipIds = JSON.parse(chipIds)
|
||||
slots = JSON.parse(slots)
|
||||
|
||||
jc.wallet.jcStandard
|
||||
.unplugChip({
|
||||
addresses,
|
||||
values,
|
||||
chipIds,
|
||||
slots,
|
||||
signature
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: JSON.stringify(result)}));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
estimate,
|
||||
}),
|
||||
(v) => JSON.stringify(v)
|
||||
);
|
||||
}
|
||||
// ======= end of interact with contract =======
|
||||
// ======= begin of pay =======
|
||||
/**
|
||||
* crypto: 'CEC' or 'CEG', 'ETH'
|
||||
* address: wallet address of user
|
||||
* fiat: 'USD' or 'CNY'
|
||||
* fiatAmount: '100'
|
||||
* payWayCode: '10001'
|
||||
* country: 'US'
|
||||
* accountId: account id of game user
|
||||
* orderId: from pre pay
|
||||
*/
|
||||
function beginPay(funId, crypto, address, fiat, fiatAmount, payWayCode, country, accountId, orderId) {
|
||||
promiseCb(
|
||||
funId,
|
||||
jc.wallet.paySvr.alchemyPrePay({
|
||||
crypto,
|
||||
address,
|
||||
fiat,
|
||||
fiatAmount,
|
||||
payWayCode,
|
||||
country,
|
||||
accountId,
|
||||
orderId,
|
||||
})
|
||||
);
|
||||
}
|
||||
// ======= end of pay =======
|
||||
// ======= begin of transaction history =======
|
||||
/**
|
||||
*
|
||||
* @param {*} funId
|
||||
* @param {*} start
|
||||
* @param {*} limit
|
||||
* @param {*} moreParam e.g. {timeBegin: 1655716867832, timeEnd: 1655716867832}
|
||||
*/
|
||||
function ethHistory(funId, start, limit, moreParam) {
|
||||
moreParam = moreParam ? JSON.parse(moreParam) : {};
|
||||
promiseCb(funId, jc.wallet.historySvr.ethRecords(start, limit, moreParam));
|
||||
}
|
||||
|
||||
function tokenHistory(funId, start, limit, address, tokenId, moreParam) {
|
||||
moreParam = moreParam ? JSON.parse(moreParam) : {};
|
||||
var data = { start, limit, address, tokenId };
|
||||
promiseCb(funId, jc.wallet.historySvr.tokenRecords(data, moreParam));
|
||||
}
|
||||
// ======= end of transaction history =======
|
||||
|
||||
/**
|
||||
* get email info of current user
|
||||
*/
|
||||
function emailInfo(funId) {
|
||||
promiseCb(funId, jc.wallet.emailVerifySvr.checkEmailVerified());
|
||||
}
|
||||
/**
|
||||
* send code with email
|
||||
* @param {*} email
|
||||
* @param {*} 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));
|
||||
}
|
||||
/**
|
||||
* verify email with code, and update email
|
||||
* @param {*} email
|
||||
* @param {*} code
|
||||
*/
|
||||
function verifyEmail(funId, email, code) {
|
||||
promiseCb(funId, jc.wallet.emailVerifySvr.updateEmailVerify(email, code));
|
||||
}
|
||||
|
||||
/**
|
||||
* check if email had already been registed
|
||||
* @param {*} email
|
||||
*/
|
||||
function checkEmailExists(funId, email) {
|
||||
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
|
||||
promiseCb(funId, wallet.emailVerifySvr.isEmailRegister(email));
|
||||
}
|
||||
/**
|
||||
* regist with email
|
||||
* @param {*} email
|
||||
* @param {*} password
|
||||
* @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));
|
||||
}
|
||||
|
||||
/**
|
||||
* login with email
|
||||
* @param {*} email
|
||||
* @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));
|
||||
}
|
||||
|
||||
/**
|
||||
* token list of current chain
|
||||
*/
|
||||
function tokenList(funId) {
|
||||
try {
|
||||
let data = jc.wallet.currentChainCfg.tokens;
|
||||
return JSON.stringify({ errcode: 0, data });
|
||||
} catch (err) {
|
||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
||||
}
|
||||
}
|
||||
/**
|
||||
* calc token price of USD
|
||||
* token must already be in DEX
|
||||
* @param {*} tokenName
|
||||
* @param {*} amount
|
||||
*/
|
||||
function tokenPrice(funId, tokenName, amount) {
|
||||
promiseCb(funId, jc.wallet.calcTokenPrice(tokenName, amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* fiat list
|
||||
*/
|
||||
function fiatList(funId) {
|
||||
promiseCb(funId, jc.wallet.paySvr.fetchFiatList());
|
||||
}
|
||||
|
||||
/**
|
||||
* format price
|
||||
*/
|
||||
function formatPrice(funId, value, decimal, fixed) {
|
||||
try {
|
||||
let data = jc.wallet.formatPrice(value, decimal, fixed);
|
||||
return JSON.stringify({ errcode: 0, data });
|
||||
} catch (err) {
|
||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
||||
}
|
||||
}
|
||||
|
||||
// begin of market
|
||||
// begin sell nft with market
|
||||
function marketSellNFT(funId, nftToken, currency, tokenId, price, amount, estimate) {
|
||||
promiseCb(
|
||||
funId,
|
||||
jc.wallet.jcStandard.marketSellNFT({
|
||||
nftToken,
|
||||
currency,
|
||||
tokenId,
|
||||
price,
|
||||
amount,
|
||||
estimate,
|
||||
}),
|
||||
(v) => JSON.stringify(v)
|
||||
);
|
||||
}
|
||||
// update price of order
|
||||
function marketUpdatePrice(funId, orderId, price, estimate) {
|
||||
promiseCb(
|
||||
funId,
|
||||
jc.wallet.jcStandard.marketUpdatePrice({
|
||||
orderId,
|
||||
price,
|
||||
estimate,
|
||||
}),
|
||||
(v) => JSON.stringify(v)
|
||||
);
|
||||
}
|
||||
// cancel order
|
||||
function marketCancelOrder(funId, orderId, estimate) {
|
||||
promiseCb(
|
||||
funId,
|
||||
jc.wallet.jcStandard.marketCancelOrder({
|
||||
orderId,
|
||||
estimate,
|
||||
}),
|
||||
(v) => JSON.stringify(v)
|
||||
);
|
||||
}
|
||||
// buy order
|
||||
function marketBuy(funId, orderId, price, estimate) {
|
||||
promiseCb(
|
||||
funId,
|
||||
jc.wallet.jcStandard.marketBuy({
|
||||
orderId,
|
||||
price,
|
||||
estimate,
|
||||
}),
|
||||
(v) => JSON.stringify(v)
|
||||
);
|
||||
}
|
||||
// buy item of game from market
|
||||
function gameMarketBuy(funId, orderId, seller, currency, price, startTime, saltNonce, signature, estimate) {
|
||||
promiseCb(
|
||||
funId,
|
||||
jc.wallet.jcStandard.gameMarketBuy({
|
||||
orderId,
|
||||
seller,
|
||||
currency,
|
||||
price,
|
||||
startTime,
|
||||
saltNonce,
|
||||
signature,
|
||||
estimate,
|
||||
}),
|
||||
(v) => JSON.stringify(v)
|
||||
);
|
||||
}
|
||||
// get order info from chain
|
||||
function marketOrderInfo(funId, orderId) {
|
||||
promiseCb(funId, jc.wallet.jcStandard.marketOrderInfo(orderId));
|
||||
}
|
||||
// end of market
|
||||
|
||||
// begin of mall
|
||||
// buy item of game from mall
|
||||
function gameMallBuy(funId, orderId, currency, price, startTime, saltNonce, signature, estimate) {
|
||||
promiseCb(
|
||||
funId,
|
||||
jc.wallet.jcStandard.gameMallBuy({
|
||||
orderId,
|
||||
currency,
|
||||
price,
|
||||
startTime,
|
||||
saltNonce,
|
||||
signature,
|
||||
estimate,
|
||||
}),
|
||||
(v) => JSON.stringify(v)
|
||||
);
|
||||
}
|
||||
// end of mall
|
||||
|
||||
// begin of NFT mall
|
||||
function nftMallBuy(funId, currency, addresses, ids, amounts, values, signature, gas, estimate) {
|
||||
addresses = JSON.parse(addresses);
|
||||
ids = JSON.parse(ids);
|
||||
amounts = JSON.parse(amounts);
|
||||
values = JSON.parse(values);
|
||||
promiseCb(
|
||||
funId,
|
||||
jc.wallet.jcStandard.mallBuy({
|
||||
currency,
|
||||
addresses,
|
||||
ids,
|
||||
amounts,
|
||||
values,
|
||||
signature,
|
||||
gas,
|
||||
estimate,
|
||||
}),
|
||||
(v) => JSON.stringify(v)
|
||||
);
|
||||
}
|
||||
|
||||
// end of NFT mall
|
||||
|
||||
// begin of google pay
|
||||
function queryGoogleProducts(funId, productIds) {
|
||||
let ids = JSON.parse(productIds);
|
||||
console.log('queryGoogleProducts:: ' + productIds);
|
||||
promiseCb(funId, jc.wallet.paySvr.queryGoogleProducts(ids));
|
||||
}
|
||||
|
||||
function queryGooglePurchases(funId) {
|
||||
promiseCb(funId, jc.wallet.paySvr.queryGooglePurchases());
|
||||
}
|
||||
|
||||
function beginGoogleBuy(funId, productId, orderId) {
|
||||
promiseCb(funId, jc.wallet.paySvr.buyGoogleProduct(productId, orderId));
|
||||
}
|
||||
|
||||
// end of google pay
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user