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
|
||||
@ -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,8 +69,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;
|
||||
promiseCb(funId, wallet.initThirdPartyWallet(chain, env), () => {
|
||||
promiseCb(funId, jc.wallet.initThirdPartyWallet(chain, env), () => {
|
||||
return jc.wallet.currentAccount();
|
||||
});
|
||||
}
|
||||
@ -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 });
|
||||
}
|
||||
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 });
|
||||
}
|
||||
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 });
|
||||
}
|
||||
promiseCb(funId, Promise.resolve(1));
|
||||
}
|
||||
/**
|
||||
* show webpage
|
||||
@ -280,12 +270,8 @@ 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 =======
|
||||
@ -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 });
|
||||
}
|
||||
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 });
|
||||
}
|
||||
promiseCb(funId, Promise.resolve(data));
|
||||
}
|
||||
|
||||
// begin of market
|
||||
|
Loading…
x
Reference in New Issue
Block a user