1. 调整js的默认路径

2. 更新jswallet,增加交易记录相关方法
This commit is contained in:
zhl 2023-02-03 15:40:00 +08:00
parent ed487bdfc5
commit 3f5e33c1ba
7 changed files with 77 additions and 224 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,14 @@
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: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
}
/**
* init wallet, must call this before all other method
* @param {string} type: wallet type, 0: internal wallet, 1: third party wallet
@ -94,14 +103,7 @@ function currentChain(funId) {
*/
function changeChain(funId, chainId) {
chainId = parseInt(chainId);
jc.wallet
.updateCurrentChain(chainId)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
promiseCb(funId, jc.wallet.updateCurrentChain(chainId));
}
/**
* [BOTH] get sign for login
@ -109,14 +111,7 @@ function changeChain(funId, chainId) {
* @param {string} tips: tips message when sign
*/
function loginSign(funId, nonce, tips) {
jc.wallet
.loginSign(nonce, tips)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
promiseCb(funId, jc.wallet.loginSign(nonce, tips));
}
/**
@ -125,15 +120,9 @@ function loginSign(funId, nonce, tips) {
* if account is null, we`ll query for current account of wallet
*/
function getEthBalance(funId, account) {
jc.wallet
.getBalance(account)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
promiseCb(funId, jc.wallet.getBalance(account));
}
/**
* send ETH from current account
* @param {string} to: target account
@ -142,14 +131,7 @@ function getEthBalance(funId, account) {
*/
function sendEth(funId, to, amount, estimate) {
estimate = (estimate || "0") | 0;
jc.wallet
.sendEth(to, amount, estimate)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
promiseCb(funId, jc.wallet.sendEth(to, amount, estimate))
}
/**
@ -172,14 +154,7 @@ function generateIcon(funId, msg, diameter) {
* @param {string} address: address of ERC20
*/
function erc20Info(funId, address) {
jc.wallet
.erc20Info(address)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
promiseCb(funId, jc.wallet.erc20Info(address));
}
/**
* get balance of ERC20
@ -187,28 +162,14 @@ function erc20Info(funId, address) {
* @param {string} account:
*/
function erc20Balance(funId, address, account) {
jc.wallet
.erc20Balance(address, account)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
promiseCb(funId, jc.wallet.erc20Balance(address, account));
}
/**
* send ERC20 token to to
*/
function sendErc20(funId, address, to, amount, estimate) {
estimate = (estimate || "0") | 0;
jc.wallet
.sendErc20(address, to, amount, estimate)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
promiseCb(funId, jc.wallet.sendErc20(address, to, amount, estimate));
}
/**
@ -216,14 +177,7 @@ function sendErc20(funId, address, to, amount, estimate) {
*/
function sendErc721(funId, address, to, tokenId, estimate) {
estimate = (estimate || "0") | 0;
jc.wallet
.sendNFT(address, to, tokenId, estimate)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
promiseCb(funId, jc.wallet.sendNFT(address, to, tokenId, estimate));
}
/**
@ -233,14 +187,7 @@ function sendErc721(funId, address, to, tokenId, estimate) {
* @param {string} tokenId:
*/
function erc1155Balance(funId, address, account, tokenId) {
jc.wallet
.erc1155Balance(address, account, tokenId)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
promiseCb(funId, jc.wallet.erc1155Balance(address, account, tokenId));
}
/**
@ -250,14 +197,7 @@ function sendErc1155(funId, address, to, tokenIds, amounts, estimate) {
tokenIds = JSON.parse(tokenIds);
amounts = JSON.parse(amounts);
estimate = (estimate || "0") | 0;
jc.wallet
.sendErc1155(address, to, tokenIds, amounts, estimate)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
promiseCb(funId, jc.wallet.sendErc1155(address, to, tokenIds, amounts, estimate));
}
function showQRCode(funId, content) {
@ -271,14 +211,7 @@ function showQRCode(funId, content) {
function scanQRCode(funId, title) {
console.log("scanQRCode: " + title);
jc.wallet.nativeSvr
.scanQRCode(title)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
promiseCb(funId, jc.wallet.nativeSvr.scanQRCode(title));
}
function exportWalletSecKey(funId) {
@ -295,25 +228,12 @@ function buyNft721(funId, addresses, values, signature, estimate) {
addresses = JSON.parse(addresses);
values = JSON.parse(values);
estimate = (estimate || "0") | 0;
jc.wallet.jcStandard
.buyNft721({
promiseCb(funId, jc.wallet.jcStandard.buyNft721({
addresses,
values,
signature,
estimate,
})
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({
errcode: 0,
data: JSON.stringify(result),
})
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
}), (v)=>JSON.stringify(v));
}
function buyNft1155(
@ -331,7 +251,7 @@ function buyNft1155(
amounts = JSON.parse(amounts);
estimate = (estimate || "0") | 0;
jc.wallet.jcStandard
promiseCb(funId, jc.wallet.jcStandard
.buyNft1155({
addresses,
values,
@ -339,19 +259,7 @@ function buyNft1155(
amounts,
signature,
estimate,
})
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({
errcode: 0,
data: JSON.stringify(result),
})
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
}), (v)=>JSON.stringify(v));
}
function evolveNft721(
@ -365,6 +273,7 @@ function evolveNft721(
) {
tokenIds = JSON.parse(tokenIds);
estimate = (estimate || "0") | 0;
promiseCb(funId,
jc.wallet.jcStandard
.evolve721NFT({
nftAddress,
@ -373,24 +282,13 @@ function evolveNft721(
nonce,
signature,
estimate,
})
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({
errcode: 0,
data: JSON.stringify(result),
})
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
}), (v)=>JSON.stringify(v));
}
function evolveChip(funId, tokenIds, startTime, nonce, signature, estimate) {
tokenIds = JSON.parse(tokenIds);
estimate = (estimate || "0") | 0;
promiseCb(funId,
jc.wallet.jcStandard
.evolveChip({
tokenIds,
@ -398,19 +296,7 @@ function evolveChip(funId, tokenIds, startTime, nonce, signature, estimate) {
nonce,
signature,
estimate,
})
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({
errcode: 0,
data: JSON.stringify(result),
})
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
}), (v)=>JSON.stringify(v));
}
function mintShardBatchUser(
@ -425,6 +311,7 @@ function mintShardBatchUser(
tokenIds = JSON.parse(tokenIds);
amounts = JSON.parse(amounts);
estimate = (estimate || "0") | 0;
promiseCb(funId,
jc.wallet.jcStandard
.mintShardBatchUser({
tokenIds,
@ -433,19 +320,7 @@ function mintShardBatchUser(
nonce,
signature,
estimate,
})
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({
errcode: 0,
data: JSON.stringify(result),
})
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
}), (v)=>JSON.stringify(v));
}
function shardMixByUser(
@ -464,6 +339,7 @@ function shardMixByUser(
ids = JSON.parse(ids);
amounts = JSON.parse(amounts);
estimate = (estimate || "0") | 0;
promiseCb(funId,
jc.wallet.jcStandard
.shardMixByUser({
tokenId,
@ -476,19 +352,7 @@ function shardMixByUser(
nonce,
signature,
estimate,
})
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({
errcode: 0,
data: JSON.stringify(result),
})
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
}), (v)=>JSON.stringify(v));
}
// addresses: [nftId, chip, sign_address]
@ -503,17 +367,12 @@ function pluginChip(
signature,
estimate
) {
console.log("addresses:" + addresses);
console.log("values:" + values);
console.log("chipIds:" + chipIds);
console.log("slots:" + slots);
console.log("signature:" + signature);
estimate = (estimate || "0") | 0;
addresses = JSON.parse(addresses);
values = JSON.parse(values);
chipIds = JSON.parse(chipIds);
slots = JSON.parse(slots);
promiseCb(funId,
jc.wallet.jcStandard
.pluginChip({
addresses,
@ -522,16 +381,7 @@ function pluginChip(
slots,
signature,
estimate,
})
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({ errcode: 0, data: JSON.stringify(result) })
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
}), (v)=>JSON.stringify(v));
}
// addresses: [nftId, chip, sign_address]
@ -551,7 +401,7 @@ function unplugChip(
chipIds = JSON.parse(chipIds);
slots = JSON.parse(slots);
estimate = (estimate || "0") | 0;
promiseCb(funId,
jc.wallet.jcStandard
.unplugChip({
addresses,
@ -560,15 +410,17 @@ function unplugChip(
slots,
signature,
estimate,
})
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({ errcode: 0, data: JSON.stringify(result) })
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
}), (v)=>JSON.stringify(v));
}
// ======= end of interact with contract =======
// ======= begin of transaction history =======
function ethHistory(funId, start, limit) {
promiseCb(funId, jc.wallet.historySvr.ethRecords(start, limit));
}
function tokenHistory(funId, start, limit, address, tokenId) {
var data = {start, limit, address, tokenId}
promiseCb(funId, jc.wallet.historySvr.tokenRecords(data))
}
// ======= end of transaction history =======

View File

@ -5,6 +5,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
buildToolsVersion PROP_BUILD_TOOLS_VERSION
ndkVersion "21.4.7075529"
defaultConfig {
applicationId "com.cege.games.release"
@ -100,7 +101,7 @@ android.applicationVariants.all { variant ->
copy{
from "${sourceDir}"
include "js/**"
include "Data/js/**"
into outputDir
}
copy {