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