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
@ -13,15 +13,15 @@ function promiseCb(funId, promiseFun, dataParser) {
} }
/** /**
* oauth login before init internal wallet * oauth login before init internal wallet
* @param {string} channel: * @param {string} channel:
* 0: google, * 0: google,
* 1: apple, * 1: apple,
* 2: tiktok, * 2: tiktok,
* 3: facebook, * 3: facebook,
* 4: twitter * 4: twitter
* 5: tg, * 5: tg,
* 6: email, * 6: email,
* 7: discord * 7: discord
* 10: client * 10: client
* @param {string} env: dev release * @param {string} env: dev release
* @param {string} account: guest account to bind * @param {string} account: guest account to bind
@ -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,15 +69,14 @@ 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();
}); });
} }
/** /**
* all chain list we supported * all chain list we supported
* @return {string} JSON string of * @return {string} JSON string of
* [{ name: string * [{ name: string
* type: string * type: string
* rpc: string * rpc: string
@ -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; promiseCb(funId, Promise.resolve(data));
return JSON.stringify({ errcode: 0, 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; promiseCb(funId, Promise.resolve(data));
return JSON.stringify({ errcode: 0, 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); promiseCb(funId, Promise.resolve(1));
return JSON.stringify({ errcode: 0, data: 1 });
} catch (err) {
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
}
} }
/** /**
* show webpage * show webpage
@ -280,18 +270,14 @@ 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 =======
/** /**
* mint NFT * mint NFT
* @param {string} address: contract address of NFT * @param {string} address: contract address of NFT
* @param {string} tokenIds: token id of NFT, JSON string of string array * @param {string} tokenIds: token id of NFT, JSON string of string array
* @parsm {string} startTime: time of signature generation * @parsm {string} startTime: time of signature generation
* @param {string} saltNonce: nonce of signature * @param {string} saltNonce: nonce of signature
@ -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; promiseCb(funId, Promise.resolve(data));
return JSON.stringify({ errcode: 0, 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); promiseCb(funId, Promise.resolve(data));
return JSON.stringify({ errcode: 0, data });
} catch (err) {
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
}
} }
// begin of market // begin of market
@ -641,7 +619,7 @@ function gameMallBuy(funId, orderId, currency, price, startTime, saltNonce, sign
); );
} }
/** /**
* buy nft from mall * buy nft from mall
* @param {string} currency: address of currency * @param {string} currency: address of currency
* @param {string} addresses: address of nft token, JSON string of array * @param {string} addresses: address of nft token, JSON string of array
@ -684,7 +662,7 @@ function nftMallBuy(funId, currency, addresses, ids, amounts, values, signature,
* @param {string} amount: amount of currency * @param {string} amount: amount of currency
* @param {string} gas: gas price * @param {string} gas: gas price
* @param {string} estimate: 0: execute; 1: only estimate gas price; default: 0 * @param {string} estimate: 0: execute; 1: only estimate gas price; default: 0
*/ */
function buyTokenWithErc20(funId, currency, amount, gas, estimate) { function buyTokenWithErc20(funId, currency, amount, gas, estimate) {
estimate = (estimate || '0') | 0; estimate = (estimate || '0') | 0;
promiseCb( promiseCb(
@ -795,7 +773,7 @@ function resetWalletAddress(funId) {
} }
/** /**
* storage pass with google drive * storage pass with google drive
* @param {string} key: current account address * @param {string} key: current account address
* @param {string} val: pass for current account * @param {string} val: pass for current account
*/ */
function storePassLocal(funId, key, val) { function storePassLocal(funId, key, val) {