reformat main.js

This commit is contained in:
CounterFire2023 2023-06-20 09:57:37 +08:00
parent c451cbe166
commit a83df5775b

View File

@ -1,19 +1,13 @@
console.log(">> begin load wallet main file."); console.log('>> begin load wallet main file.');
function promiseCb(funId, promiseFun, dataParser) { function promiseCb(funId, promiseFun, dataParser) {
dataParser = dataParser || ((v) => v); dataParser = dataParser || ((v) => v);
promiseFun promiseFun
.then((result) => { .then((result) => {
jsb.jcCallback( jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: dataParser(result) }));
funId,
JSON.stringify({ errcode: 0, data: dataParser(result) })
);
}) })
.catch((err) => { .catch((err) => {
let code = err.statusCode || 1; let code = err.statusCode || 1;
jsb.jcCallback( jsb.jcCallback(funId, JSON.stringify({ errcode: code, errmsg: err.message || err }));
funId,
JSON.stringify({ errcode: code, errmsg: err.message || err })
);
}); });
} }
/** /**
@ -22,9 +16,8 @@ function promiseCb(funId, promiseFun, dataParser) {
*/ */
function walletLogin(funId, channel) { function walletLogin(funId, channel) {
channel = parseInt(channel); channel = parseInt(channel);
console.log("walletLogin: " + channel); console.log('walletLogin: ' + channel);
const wallet = const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
!window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
promiseCb(funId, wallet.preLogin(channel)); promiseCb(funId, wallet.preLogin(channel));
} }
/** /**
@ -34,8 +27,7 @@ function walletLogin(funId, channel) {
*/ */
function initInternalWallet(funId, chain, pass, env) { function initInternalWallet(funId, chain, pass, env) {
chain = parseInt(chain); chain = parseInt(chain);
const wallet = const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
!window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
promiseCb(funId, wallet.initInternalWallet(chain, pass, env), () => { promiseCb(funId, wallet.initInternalWallet(chain, pass, env), () => {
return jc.wallet.nativeAccount; return jc.wallet.nativeAccount;
}); });
@ -54,8 +46,7 @@ function verifyPassword(funId, pass) {
*/ */
function initThirdPartyWallet(funId, chain, env) { function initThirdPartyWallet(funId, chain, env) {
chain = parseInt(chain); chain = parseInt(chain);
const wallet = const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 1 }) : jc.wallet;
!window.jc || !jc.wallet ? new jcwallet.default({ type: 1 }) : jc.wallet;
promiseCb(funId, wallet.initThirdPartyWallet(chain, env), () => { promiseCb(funId, wallet.initThirdPartyWallet(chain, env), () => {
return jc.wallet.currentAccount(); return jc.wallet.currentAccount();
}); });
@ -115,7 +106,7 @@ function getEthBalance(funId, account) {
* @param {number} estimate: 1: only estimate gas price * @param {number} estimate: 1: only estimate gas price
*/ */
function sendEth(funId, to, amount, estimate) { function sendEth(funId, to, amount, estimate) {
estimate = (estimate || "0") | 0; estimate = (estimate || '0') | 0;
promiseCb(funId, jc.wallet.sendEth(to, amount, estimate)); promiseCb(funId, jc.wallet.sendEth(to, amount, estimate));
} }
@ -153,7 +144,7 @@ function erc20Balance(funId, address, account) {
* send ERC20 token to to * send ERC20 token to to
*/ */
function sendErc20(funId, address, to, amount, estimate) { function sendErc20(funId, address, to, amount, estimate) {
estimate = (estimate || "0") | 0; estimate = (estimate || '0') | 0;
promiseCb(funId, jc.wallet.sendErc20(address, to, amount, estimate)); promiseCb(funId, jc.wallet.sendErc20(address, to, amount, estimate));
} }
@ -161,7 +152,7 @@ function sendErc20(funId, address, to, amount, estimate) {
* send ERC721 NFT to to * send ERC721 NFT to to
*/ */
function sendErc721(funId, address, to, tokenId, estimate) { function sendErc721(funId, address, to, tokenId, estimate) {
estimate = (estimate || "0") | 0; estimate = (estimate || '0') | 0;
promiseCb(funId, jc.wallet.sendNFT(address, to, tokenId, estimate)); promiseCb(funId, jc.wallet.sendNFT(address, to, tokenId, estimate));
} }
@ -181,11 +172,8 @@ function erc1155Balance(funId, address, account, tokenId) {
function sendErc1155(funId, address, to, tokenIds, amounts, estimate) { function sendErc1155(funId, address, to, tokenIds, amounts, estimate) {
tokenIds = JSON.parse(tokenIds); tokenIds = JSON.parse(tokenIds);
amounts = JSON.parse(amounts); amounts = JSON.parse(amounts);
estimate = (estimate || "0") | 0; estimate = (estimate || '0') | 0;
promiseCb( promiseCb(funId, jc.wallet.sendErc1155(address, to, tokenIds, amounts, estimate));
funId,
jc.wallet.sendErc1155(address, to, tokenIds, amounts, estimate)
);
} }
function showQRCode(funId, content) { function showQRCode(funId, content) {
@ -208,7 +196,7 @@ function showWebPage(funId, url) {
} }
function scanQRCode(funId, title) { function scanQRCode(funId, title) {
console.log("scanQRCode: " + title); console.log('scanQRCode: ' + title);
promiseCb(funId, jc.wallet.nativeSvr.scanQRCode(title)); promiseCb(funId, jc.wallet.nativeSvr.scanQRCode(title));
} }
@ -222,15 +210,7 @@ function exportWalletSecKey(funId, pass) {
} }
// ======= begin of interact with contract ======= // ======= begin of interact with contract =======
function mintNFT( function mintNFT(funId, address, tokenIds, startTime, saltNonce, signature, estimate) {
funId,
address,
tokenIds,
startTime,
saltNonce,
signature,
estimate
) {
tokenIds = JSON.parse(tokenIds); tokenIds = JSON.parse(tokenIds);
promiseCb( promiseCb(
funId, funId,
@ -257,17 +237,7 @@ function mintNFT(
* accountId: account id of game user * accountId: account id of game user
* orderId: from pre pay * orderId: from pre pay
*/ */
function beginPay( function beginPay(funId, crypto, address, fiat, fiatAmount, payWayCode, country, accountId, orderId) {
funId,
crypto,
address,
fiat,
fiatAmount,
payWayCode,
country,
accountId,
orderId
) {
promiseCb( promiseCb(
funId, funId,
jc.wallet.paySvr.alchemyPrePay({ jc.wallet.paySvr.alchemyPrePay({
@ -306,8 +276,7 @@ function emailInfo(funId) {
* @param {*} type * @param {*} type
*/ */
function sendEmailCode(funId, email, type) { function sendEmailCode(funId, email, type) {
const wallet = const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
!window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
promiseCb(funId, wallet.emailVerifySvr.sendEmailCode(email, type)); promiseCb(funId, wallet.emailVerifySvr.sendEmailCode(email, type));
} }
/** /**
@ -324,8 +293,7 @@ function verifyEmail(funId, email, code) {
* @param {*} email * @param {*} email
*/ */
function checkEmailExists(funId, email) { function checkEmailExists(funId, email) {
const wallet = const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
!window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
promiseCb(funId, wallet.emailVerifySvr.isEmailRegister(email)); promiseCb(funId, wallet.emailVerifySvr.isEmailRegister(email));
} }
/** /**
@ -335,8 +303,7 @@ function checkEmailExists(funId, email) {
* @param {*} code * @param {*} code
*/ */
function emailRegist(funId, email, password, code) { function emailRegist(funId, email, password, code) {
const wallet = const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
!window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
promiseCb(funId, wallet.emailVerifySvr.registByEmail(email, password, code)); promiseCb(funId, wallet.emailVerifySvr.registByEmail(email, password, code));
} }
@ -346,8 +313,7 @@ function emailRegist(funId, email, password, code) {
* @param {*} password * @param {*} password
*/ */
function emailLogin(funId, email, password) { function emailLogin(funId, email, password) {
const wallet = const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
!window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
promiseCb(funId, wallet.emailLogin(email, password)); promiseCb(funId, wallet.emailLogin(email, password));
} }
@ -393,15 +359,7 @@ function formatPrice(funId, value, decimal, fixed) {
// begin of market // begin of market
// begin sell nft with market // begin sell nft with market
function marketSellNFT( function marketSellNFT(funId, nftToken, currency, tokenId, price, amount, estimate) {
funId,
nftToken,
currency,
tokenId,
price,
amount,
estimate
) {
promiseCb( promiseCb(
funId, funId,
jc.wallet.jcStandard.marketSellNFT({ jc.wallet.jcStandard.marketSellNFT({
@ -450,17 +408,7 @@ function marketBuy(funId, orderId, estimate) {
); );
} }
// buy item of game from market // buy item of game from market
function gameMarketBuy( function gameMarketBuy(funId, orderId, seller, currency, price, startTime, saltNonce, signature, estimate) {
funId,
orderId,
seller,
currency,
price,
startTime,
saltNonce,
signature,
estimate
) {
promiseCb( promiseCb(
funId, funId,
jc.wallet.jcStandard.gameMarketBuy({ jc.wallet.jcStandard.gameMarketBuy({
@ -480,16 +428,7 @@ function gameMarketBuy(
// begin of mall // begin of mall
// buy item of game from mall // buy item of game from mall
function gameMallBuy( function gameMallBuy(funId, orderId, currency, price, startTime, saltNonce, signature, estimate) {
funId,
orderId,
currency,
price,
startTime,
saltNonce,
signature,
estimate
) {
promiseCb( promiseCb(
funId, funId,
jc.wallet.jcStandard.gameMallBuy({ jc.wallet.jcStandard.gameMallBuy({