update sth
This commit is contained in:
parent
39af283b07
commit
9daf77c83a
File diff suppressed because one or more lines are too long
@ -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
|
||||||
@ -33,21 +33,26 @@ 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, jc.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
|
||||||
* @param {string} pass: password for wallet
|
* @param {string} pass: password for wallet
|
||||||
* @param {string} env: dev release
|
* @param {string} env: dev release
|
||||||
|
* @param {string} useApi: 1: yes, 0: no
|
||||||
* @return {string} address
|
* @return {string} address
|
||||||
* @throws {Error} if password is wrong
|
* @throws {Error} if password is wrong
|
||||||
*/
|
*/
|
||||||
function initInternalWallet(funId, chain, pass, env) {
|
function initInternalWallet(funId, chain, pass, env, useApi) {
|
||||||
chain = parseInt(chain);
|
chain = parseInt(chain);
|
||||||
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
|
useApi = (useApi && useApi == '1') ? true: false
|
||||||
promiseCb(funId, wallet.initInternalWallet(chain, pass, env), () => {
|
promiseCb(funId, jc.wallet.initInternalWallet(chain, pass, env, useApi), () => {
|
||||||
return jc.wallet.nativeAccount;
|
return jc.wallet.nativeAccount;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -66,12 +71,17 @@ 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();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function initRelayWallet(funId, chain, env) {
|
||||||
|
chain = parseInt(chain);
|
||||||
|
promiseCb(funId, jc.wallet.initRelayWallet(chain, env));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* all chain list we supported
|
* all chain list we supported
|
||||||
* @return {string} JSON string of
|
* @return {string} JSON string of
|
||||||
@ -86,12 +96,8 @@ function initThirdPartyWallet(funId, chain, env) {
|
|||||||
* }]
|
* }]
|
||||||
*/
|
*/
|
||||||
function chainList(funId) {
|
function chainList(funId) {
|
||||||
try {
|
|
||||||
let data = jc.wallet.chainList;
|
let data = jc.wallet.chainList;
|
||||||
return JSON.stringify({ errcode: 0, data });
|
promiseCb(funId, Promise.resolve(data));
|
||||||
} catch (err) {
|
|
||||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* current actived chain info
|
* current actived chain info
|
||||||
@ -107,12 +113,8 @@ function chainList(funId) {
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
function currentChain(funId) {
|
function currentChain(funId) {
|
||||||
try {
|
|
||||||
let data = jc.wallet.currentChain;
|
let data = jc.wallet.currentChain;
|
||||||
return JSON.stringify({ errcode: 0, data });
|
promiseCb(funId, Promise.resolve(data));
|
||||||
} catch (err) {
|
|
||||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* change current actived chain
|
* change current actived chain
|
||||||
@ -136,7 +138,7 @@ function loginSign(funId, nonce, tips) {
|
|||||||
* if account is null, we`ll query for current account of wallet
|
* if account is null, we`ll query for current account of wallet
|
||||||
*/
|
*/
|
||||||
function getEthBalance(funId, account) {
|
function getEthBalance(funId, account) {
|
||||||
promiseCb(funId, jc.wallet.getBalance(account));
|
promiseCb(funId, jc.wallet.chainCommon.getBalance(account));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -147,7 +149,7 @@ function getEthBalance(funId, account) {
|
|||||||
*/
|
*/
|
||||||
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.chainCommon.sendEth(to, amount, estimate));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -178,7 +180,7 @@ function erc20Info(funId, address) {
|
|||||||
* @param {string} account:
|
* @param {string} account:
|
||||||
*/
|
*/
|
||||||
function erc20Balance(funId, address, account) {
|
function erc20Balance(funId, address, account) {
|
||||||
promiseCb(funId, jc.wallet.erc20Balance(address, account));
|
promiseCb(funId, jc.wallet.erc20Standard.getBalanceOf(address, account));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* send ERC20 token to to
|
* send ERC20 token to to
|
||||||
@ -189,7 +191,7 @@ function erc20Balance(funId, address, account) {
|
|||||||
*/
|
*/
|
||||||
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.erc20Standard.transfer({address, to, amount, estimate}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -201,7 +203,7 @@ function sendErc20(funId, address, to, amount, estimate) {
|
|||||||
*/
|
*/
|
||||||
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.erc721Standard.transfer({address, to, tokenId, estimate}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -221,7 +223,7 @@ function erc721Balance(funId, address, account, chainId) {
|
|||||||
* @param {string} tokenId: nft id of NFT
|
* @param {string} tokenId: nft id of NFT
|
||||||
*/
|
*/
|
||||||
function erc1155Balance(funId, address, account, tokenId) {
|
function erc1155Balance(funId, address, account, tokenId) {
|
||||||
promiseCb(funId, jc.wallet.erc1155Balance(address, account, tokenId));
|
promiseCb(funId, jc.wallet.erc1155Standard.getBalanceOf(address, account, tokenId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -236,7 +238,7 @@ 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(funId, jc.wallet.sendErc1155(address, to, tokenIds, amounts, estimate));
|
promiseCb(funId, jc.wallet.erc1155Standard.transferBatch({address, to, tokenIds, amounts, estimate}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -244,12 +246,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);
|
||||||
return JSON.stringify({ errcode: 0, data: 1 });
|
promiseCb(funId, Promise.resolve(1));
|
||||||
} catch (err) {
|
|
||||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* show webpage
|
* show webpage
|
||||||
@ -280,12 +278,8 @@ 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 =======
|
||||||
@ -400,8 +394,7 @@ function emailInfo(funId) {
|
|||||||
* @param {string} type
|
* @param {string} type
|
||||||
*/
|
*/
|
||||||
function sendEmailCode(funId, email, type) {
|
function sendEmailCode(funId, email, type) {
|
||||||
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
|
promiseCb(funId, jc.wallet.emailVerifySvr.sendEmailCode(email, type));
|
||||||
promiseCb(funId, wallet.emailVerifySvr.sendEmailCode(email, type));
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* verify email with code, and update email
|
* verify email with code, and update email
|
||||||
@ -417,8 +410,7 @@ function verifyEmail(funId, email, code) {
|
|||||||
* @param {string} email
|
* @param {string} email
|
||||||
*/
|
*/
|
||||||
function checkEmailExists(funId, email) {
|
function checkEmailExists(funId, email) {
|
||||||
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
|
promiseCb(funId, jc.wallet.emailVerifySvr.isEmailRegister(email));
|
||||||
promiseCb(funId, wallet.emailVerifySvr.isEmailRegister(email));
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* regist with email
|
* regist with email
|
||||||
@ -427,8 +419,7 @@ function checkEmailExists(funId, email) {
|
|||||||
* @param {*} code
|
* @param {*} code
|
||||||
*/
|
*/
|
||||||
function emailRegist(funId, email, password, code) {
|
function emailRegist(funId, email, password, code) {
|
||||||
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
|
promiseCb(funId, jc.wallet.emailVerifySvr.registByEmail(email, password, code));
|
||||||
promiseCb(funId, wallet.emailVerifySvr.registByEmail(email, password, code));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -437,20 +428,15 @@ function emailRegist(funId, email, password, code) {
|
|||||||
* @param {*} password
|
* @param {*} password
|
||||||
*/
|
*/
|
||||||
function emailLogin(funId, email, password) {
|
function emailLogin(funId, email, password) {
|
||||||
const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
|
promiseCb(funId, jc.wallet.emailLogin(email, password));
|
||||||
promiseCb(funId, wallet.emailLogin(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;
|
||||||
return JSON.stringify({ errcode: 0, data });
|
promiseCb(funId, Promise.resolve(data));
|
||||||
} catch (err) {
|
|
||||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* calc token price of USD
|
* calc token price of USD
|
||||||
@ -490,12 +476,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);
|
||||||
return JSON.stringify({ errcode: 0, data });
|
promiseCb(funId, Promise.resolve(data));
|
||||||
} catch (err) {
|
|
||||||
return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// begin of market
|
// begin of market
|
||||||
@ -812,3 +794,4 @@ function restorePassLocal(funId, key) {
|
|||||||
function getLocalPassState(funId, key) {
|
function getLocalPassState(funId, key) {
|
||||||
promiseCb(funId, jc.wallet.nativeSvr.passStorageState(key));
|
promiseCb(funId, jc.wallet.nativeSvr.passStorageState(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
index.html
35
index.html
@ -26,7 +26,7 @@ button{
|
|||||||
display: flex;
|
display: flex;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
justify-content: flex-start;
|
justify-content: space-between;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
.app button {
|
.app button {
|
||||||
@ -36,7 +36,6 @@ button{
|
|||||||
max-height: 50px;
|
max-height: 50px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class='app' id='app'>
|
<div class='app' id='app'>
|
||||||
@ -46,13 +45,12 @@ button{
|
|||||||
/**
|
/**
|
||||||
* 加载外部js
|
* 加载外部js
|
||||||
*/
|
*/
|
||||||
var loadSingleScript = function (sub) {
|
var loadSingleScript = function (src, isModule) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let src = sub[0];
|
|
||||||
console.log(`>> begin load script: ${src}`);
|
console.log(`>> begin load script: ${src}`);
|
||||||
let s = document.createElement('script');
|
let s = document.createElement('script');
|
||||||
s.async = true;
|
s.async = true;
|
||||||
if (sub[1] == 1)s.type = 'module';
|
if (isModule)s.type = 'module';
|
||||||
s.src =src;
|
s.src =src;
|
||||||
s.addEventListener('load', function () {
|
s.addEventListener('load', function () {
|
||||||
console.log(`<< finish load script: ${src}`);
|
console.log(`<< finish load script: ${src}`);
|
||||||
@ -64,22 +62,29 @@ button{
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
var scripts = [
|
var scripts = [
|
||||||
['assets/scripts/libs/jcwallet.js'],
|
'assets/scripts/libs/jcwallet.js',
|
||||||
['assets/scripts/libs/main.js'],
|
'assets/scripts/libs/main.js',
|
||||||
['assets/scripts/libs/utils.js'],
|
'assets/scripts/libs/utils.js',
|
||||||
['assets/scripts/libs/native_bridge.js', 1],
|
['assets/scripts/libs/native_bridge.js', 1],
|
||||||
['assets/scripts/libs/main_native_inject.js'],
|
'assets/scripts/libs/main_native_inject.js',
|
||||||
['assets/scripts/run_sample.js'],
|
'assets/scripts/run_sample.js',
|
||||||
]
|
]
|
||||||
|
|
||||||
var loadScripts = function (list, refresh = false) {
|
var loadScripts = function (list, refresh = false) {
|
||||||
var loaded = 0;
|
var loaded = 0;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var loadNext = function () {
|
var loadNext = function () {
|
||||||
if (refresh) {
|
var current = list[loaded];
|
||||||
list[loaded][0] = list[loaded][0] + (list[loaded][0].indexOf("?") == -1 ? "?" : "&") + "t=" + Date.now();
|
var src = current;
|
||||||
|
var isModule = false;
|
||||||
|
if (typeof current === 'object' && current instanceof Array) {
|
||||||
|
src = current[0];
|
||||||
|
isModule = current.length > 1 && current[1] == 1
|
||||||
}
|
}
|
||||||
loadSingleScript(list[loaded]).then(() => {
|
|
||||||
|
if (refresh) {
|
||||||
|
src = src + (src.indexOf("?") == -1 ? "?" : "&") + "t=" + Date.now();
|
||||||
|
}
|
||||||
|
loadSingleScript(src, isModule).then(() => {
|
||||||
if (++loaded >= list.length) {
|
if (++loaded >= list.length) {
|
||||||
resolve && resolve();
|
resolve && resolve();
|
||||||
} else {
|
} else {
|
||||||
@ -90,7 +95,7 @@ button{
|
|||||||
loadNext();
|
loadNext();
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
loadScripts(scripts);
|
loadScripts(scripts, false);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user