update main.js

This commit is contained in:
CounterFire2023 2023-10-11 16:15:32 +08:00
parent eab25c9c3a
commit 01c63eaf1d

View File

@ -1,5 +1,5 @@
console.log('>> begin load wallet main file.'); console.log('>> begin load wallet main file.');
!window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet; !window.jc || !jc.wallet ? new jcwallet.default() : jc.wallet;
function promiseCb(funId, promiseFun, dataParser) { function promiseCb(funId, promiseFun, dataParser) {
dataParser = dataParser || ((v) => v); dataParser = dataParser || ((v) => v);
promiseFun promiseFun
@ -33,9 +33,13 @@ function walletLogin(funId, channel, env, account) {
channel = parseInt(channel); channel = parseInt(channel);
env = env || 'dev'; env = env || 'dev';
console.log('walletLogin: ' + channel); console.log('walletLogin: ' + channel);
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
promiseCb(funId, wallet.preLogin(channel, env, account)); promiseCb(funId, wallet.preLogin(channel, env, account));
} }
function updateGameInfo(funId, info) {
jsb.updateGameInfo(funId, info);
promiseCb(funId, Promise.resolve(1));
}
/** /**
* init internal wallet with password * init internal wallet with password
* @param {string} chain: chain id * @param {string} chain: chain id
@ -46,8 +50,7 @@ function walletLogin(funId, channel, env, account) {
*/ */
function initInternalWallet(funId, chain, pass, env) { function initInternalWallet(funId, chain, pass, env) {
chain = parseInt(chain); chain = parseInt(chain);
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet; promiseCb(funId, jc.wallet.initInternalWallet(chain, pass, env), () => {
promiseCb(funId, wallet.initInternalWallet(chain, pass, env), () => {
return jc.wallet.nativeAccount; return jc.wallet.nativeAccount;
}); });
} }
@ -66,8 +69,7 @@ function verifyPassword(funId, pass) {
*/ */
function initThirdPartyWallet(funId, chain, env) { function initThirdPartyWallet(funId, chain, env) {
chain = parseInt(chain); chain = parseInt(chain);
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 1 }) : jc.wallet; promiseCb(funId, jc.wallet.initThirdPartyWallet(chain, env), () => {
promiseCb(funId, wallet.initThirdPartyWallet(chain, env), () => {
return jc.wallet.currentAccount(); return jc.wallet.currentAccount();
}); });
} }
@ -86,12 +88,8 @@ function initThirdPartyWallet(funId, chain, env) {
* }] * }]
*/ */
function chainList(funId) { function chainList(funId) {
try {
let data = jc.wallet.chainList; let data = jc.wallet.chainList;
return JSON.stringify({ errcode: 0, data }); promiseCb(funId, Promise.resolve(data));
} catch (err) {
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
}
} }
/** /**
* current actived chain info * current actived chain info
@ -107,12 +105,8 @@ function chainList(funId) {
* } * }
*/ */
function currentChain(funId) { function currentChain(funId) {
try {
let data = jc.wallet.currentChain; let data = jc.wallet.currentChain;
return JSON.stringify({ errcode: 0, data }); promiseCb(funId, Promise.resolve(data));
} catch (err) {
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
}
} }
/** /**
* change current actived chain * change current actived chain
@ -244,12 +238,8 @@ function sendErc1155(funId, address, to, tokenIds, amounts, estimate) {
* @param {string} content: content to show * @param {string} content: content to show
*/ */
function showQRCode(funId, content) { function showQRCode(funId, content) {
try {
jsb.showQRCode(funId, content); jsb.showQRCode(funId, content);
return JSON.stringify({ errcode: 0, data: 1 }); promiseCb(funId, Promise.resolve(1));
} catch (err) {
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
}
} }
/** /**
* show webpage * show webpage
@ -280,12 +270,8 @@ function scanQRCode(funId, title) {
* @param {string} pass: password of wallet * @param {string} pass: password of wallet
*/ */
function exportWalletSecKey(funId, pass) { function exportWalletSecKey(funId, pass) {
try { let data = jc.wallet.exportPrivateKey(pass);
let key = jc.wallet.exportPrivateKey(pass); promiseCb(funId, Promise.resolve(data));
return JSON.stringify({ errcode: 0, data: key });
} catch (err) {
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
}
} }
// ======= begin of interact with contract ======= // ======= begin of interact with contract =======
@ -445,12 +431,8 @@ function emailLogin(funId, email, password) {
* token list of current chain * token list of current chain
*/ */
function tokenList(funId) { function tokenList(funId) {
try {
let data = jc.wallet.currentChainCfg.tokens; let data = jc.wallet.currentChainCfg.tokens;
return JSON.stringify({ errcode: 0, data }); promiseCb(funId, Promise.resolve(data));
} catch (err) {
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
}
} }
/** /**
* calc token price of USD * calc token price of USD
@ -490,12 +472,8 @@ function getCryptoPriceOfUSD(funId, crypto, chain) {
* @param {string} fixed: fixed of price * @param {string} fixed: fixed of price
*/ */
function formatPrice(funId, value, decimal, fixed) { function formatPrice(funId, value, decimal, fixed) {
try {
let data = jc.wallet.formatPrice(value, decimal, fixed); let data = jc.wallet.formatPrice(value, decimal, fixed);
return JSON.stringify({ errcode: 0, data }); promiseCb(funId, Promise.resolve(data));
} catch (err) {
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
}
} }
// begin of market // begin of market