update main.js
This commit is contained in:
parent
eab25c9c3a
commit
01c63eaf1d
@ -1,5 +1,5 @@
|
||||
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) {
|
||||
dataParser = dataParser || ((v) => v);
|
||||
promiseFun
|
||||
@ -13,15 +13,15 @@ function promiseCb(funId, promiseFun, dataParser) {
|
||||
}
|
||||
/**
|
||||
* oauth login before init internal wallet
|
||||
* @param {string} channel:
|
||||
* 0: google,
|
||||
* 1: apple,
|
||||
* 2: tiktok,
|
||||
* 3: facebook,
|
||||
* 4: twitter
|
||||
* 5: tg,
|
||||
* 6: email,
|
||||
* 7: discord
|
||||
* @param {string} channel:
|
||||
* 0: google,
|
||||
* 1: apple,
|
||||
* 2: tiktok,
|
||||
* 3: facebook,
|
||||
* 4: twitter
|
||||
* 5: tg,
|
||||
* 6: email,
|
||||
* 7: discord
|
||||
* 10: client
|
||||
* @param {string} env: dev release
|
||||
* @param {string} account: guest account to bind
|
||||
@ -33,9 +33,13 @@ function walletLogin(funId, channel, env, account) {
|
||||
channel = parseInt(channel);
|
||||
env = env || 'dev';
|
||||
console.log('walletLogin: ' + channel);
|
||||
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
|
||||
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
|
||||
* @param {string} chain: chain id
|
||||
@ -46,8 +50,7 @@ function walletLogin(funId, channel, env, account) {
|
||||
*/
|
||||
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), () => {
|
||||
promiseCb(funId, jc.wallet.initInternalWallet(chain, pass, env), () => {
|
||||
return jc.wallet.nativeAccount;
|
||||
});
|
||||
}
|
||||
@ -66,15 +69,14 @@ 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;
|
||||
promiseCb(funId, wallet.initThirdPartyWallet(chain, env), () => {
|
||||
promiseCb(funId, jc.wallet.initThirdPartyWallet(chain, env), () => {
|
||||
return jc.wallet.currentAccount();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* all chain list we supported
|
||||
* @return {string} JSON string of
|
||||
* @return {string} JSON string of
|
||||
* [{ name: string
|
||||
* type: string
|
||||
* rpc: string
|
||||
@ -86,12 +88,8 @@ function initThirdPartyWallet(funId, chain, env) {
|
||||
* }]
|
||||
*/
|
||||
function chainList(funId) {
|
||||
try {
|
||||
let data = jc.wallet.chainList;
|
||||
return JSON.stringify({ errcode: 0, data });
|
||||
} catch (err) {
|
||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
||||
}
|
||||
let data = jc.wallet.chainList;
|
||||
promiseCb(funId, Promise.resolve(data));
|
||||
}
|
||||
/**
|
||||
* current actived chain info
|
||||
@ -107,12 +105,8 @@ function chainList(funId) {
|
||||
* }
|
||||
*/
|
||||
function currentChain(funId) {
|
||||
try {
|
||||
let data = jc.wallet.currentChain;
|
||||
return JSON.stringify({ errcode: 0, data });
|
||||
} catch (err) {
|
||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
||||
}
|
||||
let data = jc.wallet.currentChain;
|
||||
promiseCb(funId, Promise.resolve(data));
|
||||
}
|
||||
/**
|
||||
* change current actived chain
|
||||
@ -244,12 +238,8 @@ function sendErc1155(funId, address, to, tokenIds, amounts, estimate) {
|
||||
* @param {string} content: content to show
|
||||
*/
|
||||
function showQRCode(funId, content) {
|
||||
try {
|
||||
jsb.showQRCode(funId, content);
|
||||
return JSON.stringify({ errcode: 0, data: 1 });
|
||||
} catch (err) {
|
||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
||||
}
|
||||
jsb.showQRCode(funId, content);
|
||||
promiseCb(funId, Promise.resolve(1));
|
||||
}
|
||||
/**
|
||||
* show webpage
|
||||
@ -280,18 +270,14 @@ function scanQRCode(funId, title) {
|
||||
* @param {string} pass: password of wallet
|
||||
*/
|
||||
function exportWalletSecKey(funId, pass) {
|
||||
try {
|
||||
let key = jc.wallet.exportPrivateKey(pass);
|
||||
return JSON.stringify({ errcode: 0, data: key });
|
||||
} catch (err) {
|
||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
||||
}
|
||||
let data = jc.wallet.exportPrivateKey(pass);
|
||||
promiseCb(funId, Promise.resolve(data));
|
||||
}
|
||||
|
||||
// ======= begin of interact with contract =======
|
||||
/**
|
||||
* mint NFT
|
||||
* @param {string} address: contract address of NFT
|
||||
* mint NFT
|
||||
* @param {string} address: contract address of NFT
|
||||
* @param {string} tokenIds: token id of NFT, JSON string of string array
|
||||
* @parsm {string} startTime: time of signature generation
|
||||
* @param {string} saltNonce: nonce of signature
|
||||
@ -445,12 +431,8 @@ function emailLogin(funId, 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 });
|
||||
}
|
||||
let data = jc.wallet.currentChainCfg.tokens;
|
||||
promiseCb(funId, Promise.resolve(data));
|
||||
}
|
||||
/**
|
||||
* calc token price of USD
|
||||
@ -490,12 +472,8 @@ function getCryptoPriceOfUSD(funId, crypto, chain) {
|
||||
* @param {string} fixed: fixed of 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 });
|
||||
}
|
||||
let data = jc.wallet.formatPrice(value, decimal, fixed);
|
||||
promiseCb(funId, Promise.resolve(data));
|
||||
}
|
||||
|
||||
// begin of market
|
||||
@ -641,7 +619,7 @@ function gameMallBuy(funId, orderId, currency, price, startTime, saltNonce, sign
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* buy nft from mall
|
||||
* @param {string} currency: address of currency
|
||||
* @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} gas: gas price
|
||||
* @param {string} estimate: 0: execute; 1: only estimate gas price; default: 0
|
||||
*/
|
||||
*/
|
||||
function buyTokenWithErc20(funId, currency, amount, gas, estimate) {
|
||||
estimate = (estimate || '0') | 0;
|
||||
promiseCb(
|
||||
@ -795,7 +773,7 @@ function resetWalletAddress(funId) {
|
||||
}
|
||||
/**
|
||||
* storage pass with google drive
|
||||
* @param {string} key: current account address
|
||||
* @param {string} key: current account address
|
||||
* @param {string} val: pass for current account
|
||||
*/
|
||||
function storePassLocal(funId, key, val) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user