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"); 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 * init wallet, must call this before all other method
* @param {string} type: wallet type, 0: internal wallet, 1: third party wallet * @param {string} type: wallet type, 0: internal wallet, 1: third party wallet
@ -94,14 +103,7 @@ function currentChain(funId) {
*/ */
function changeChain(funId, chainId) { function changeChain(funId, chainId) {
chainId = parseInt(chainId); chainId = parseInt(chainId);
jc.wallet promiseCb(funId, jc.wallet.updateCurrentChain(chainId));
.updateCurrentChain(chainId)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
} }
/** /**
* [BOTH] get sign for login * [BOTH] get sign for login
@ -109,14 +111,7 @@ function changeChain(funId, chainId) {
* @param {string} tips: tips message when sign * @param {string} tips: tips message when sign
*/ */
function loginSign(funId, nonce, tips) { function loginSign(funId, nonce, tips) {
jc.wallet promiseCb(funId, jc.wallet.loginSign(nonce, tips));
.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 }));
});
} }
/** /**
@ -125,15 +120,9 @@ 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) {
jc.wallet promiseCb(funId, jc.wallet.getBalance(account));
.getBalance(account)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
} }
/** /**
* send ETH from current account * send ETH from current account
* @param {string} to: target account * @param {string} to: target account
@ -142,14 +131,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;
jc.wallet promiseCb(funId, jc.wallet.sendEth(to, amount, estimate))
.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 }));
});
} }
/** /**
@ -172,14 +154,7 @@ function generateIcon(funId, msg, diameter) {
* @param {string} address: address of ERC20 * @param {string} address: address of ERC20
*/ */
function erc20Info(funId, address) { function erc20Info(funId, address) {
jc.wallet promiseCb(funId, jc.wallet.erc20Info(address));
.erc20Info(address)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
} }
/** /**
* get balance of ERC20 * get balance of ERC20
@ -187,28 +162,14 @@ function erc20Info(funId, address) {
* @param {string} account: * @param {string} account:
*/ */
function erc20Balance(funId, address, account) { function erc20Balance(funId, address, account) {
jc.wallet promiseCb(funId, jc.wallet.erc20Balance(address, account));
.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 }));
});
} }
/** /**
* send ERC20 token to to * send ERC20 token to to
*/ */
function sendErc20(funId, address, to, amount, estimate) { function sendErc20(funId, address, to, amount, estimate) {
estimate = (estimate || "0") | 0; estimate = (estimate || "0") | 0;
jc.wallet promiseCb(funId, jc.wallet.sendErc20(address, to, amount, estimate));
.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 }));
});
} }
/** /**
@ -216,14 +177,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;
jc.wallet promiseCb(funId, jc.wallet.sendNFT(address, to, tokenId, estimate));
.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 }));
});
} }
/** /**
@ -233,14 +187,7 @@ function sendErc721(funId, address, to, tokenId, estimate) {
* @param {string} tokenId: * @param {string} tokenId:
*/ */
function erc1155Balance(funId, address, account, tokenId) { function erc1155Balance(funId, address, account, tokenId) {
jc.wallet promiseCb(funId, jc.wallet.erc1155Balance(address, account, tokenId));
.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 }));
});
} }
/** /**
@ -250,14 +197,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;
jc.wallet promiseCb(funId, jc.wallet.sendErc1155(address, to, tokenIds, amounts, estimate));
.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 }));
});
} }
function showQRCode(funId, content) { function showQRCode(funId, content) {
@ -271,14 +211,7 @@ function showQRCode(funId, content) {
function scanQRCode(funId, title) { function scanQRCode(funId, title) {
console.log("scanQRCode: " + title); console.log("scanQRCode: " + title);
jc.wallet.nativeSvr promiseCb(funId, jc.wallet.nativeSvr.scanQRCode(title));
.scanQRCode(title)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
} }
function exportWalletSecKey(funId) { function exportWalletSecKey(funId) {
@ -295,25 +228,12 @@ function buyNft721(funId, addresses, values, signature, estimate) {
addresses = JSON.parse(addresses); addresses = JSON.parse(addresses);
values = JSON.parse(values); values = JSON.parse(values);
estimate = (estimate || "0") | 0; estimate = (estimate || "0") | 0;
jc.wallet.jcStandard promiseCb(funId, jc.wallet.jcStandard.buyNft721({
.buyNft721({
addresses, addresses,
values, values,
signature, signature,
estimate, estimate,
}) }), (v)=>JSON.stringify(v));
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({
errcode: 0,
data: JSON.stringify(result),
})
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
} }
function buyNft1155( function buyNft1155(
@ -331,7 +251,7 @@ function buyNft1155(
amounts = JSON.parse(amounts); amounts = JSON.parse(amounts);
estimate = (estimate || "0") | 0; estimate = (estimate || "0") | 0;
jc.wallet.jcStandard promiseCb(funId, jc.wallet.jcStandard
.buyNft1155({ .buyNft1155({
addresses, addresses,
values, values,
@ -339,19 +259,7 @@ function buyNft1155(
amounts, amounts,
signature, signature,
estimate, estimate,
}) }), (v)=>JSON.stringify(v));
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({
errcode: 0,
data: JSON.stringify(result),
})
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
} }
function evolveNft721( function evolveNft721(
@ -365,52 +273,30 @@ function evolveNft721(
) { ) {
tokenIds = JSON.parse(tokenIds); tokenIds = JSON.parse(tokenIds);
estimate = (estimate || "0") | 0; estimate = (estimate || "0") | 0;
jc.wallet.jcStandard promiseCb(funId,
jc.wallet.jcStandard
.evolve721NFT({ .evolve721NFT({
nftAddress, nftAddress,
tokenIds, tokenIds,
startTime, startTime,
nonce, nonce,
signature, signature,
estimate, estimate,
}) }), (v)=>JSON.stringify(v));
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({
errcode: 0,
data: JSON.stringify(result),
})
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
} }
function evolveChip(funId, tokenIds, startTime, nonce, signature, estimate) { function evolveChip(funId, tokenIds, startTime, nonce, signature, estimate) {
tokenIds = JSON.parse(tokenIds); tokenIds = JSON.parse(tokenIds);
estimate = (estimate || "0") | 0; estimate = (estimate || "0") | 0;
jc.wallet.jcStandard promiseCb(funId,
jc.wallet.jcStandard
.evolveChip({ .evolveChip({
tokenIds, tokenIds,
startTime, startTime,
nonce, nonce,
signature, signature,
estimate, estimate,
}) }), (v)=>JSON.stringify(v));
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({
errcode: 0,
data: JSON.stringify(result),
})
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
} }
function mintShardBatchUser( function mintShardBatchUser(
@ -425,7 +311,8 @@ function mintShardBatchUser(
tokenIds = JSON.parse(tokenIds); tokenIds = JSON.parse(tokenIds);
amounts = JSON.parse(amounts); amounts = JSON.parse(amounts);
estimate = (estimate || "0") | 0; estimate = (estimate || "0") | 0;
jc.wallet.jcStandard promiseCb(funId,
jc.wallet.jcStandard
.mintShardBatchUser({ .mintShardBatchUser({
tokenIds, tokenIds,
amounts, amounts,
@ -433,19 +320,7 @@ function mintShardBatchUser(
nonce, nonce,
signature, signature,
estimate, estimate,
}) }), (v)=>JSON.stringify(v));
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({
errcode: 0,
data: JSON.stringify(result),
})
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
} }
function shardMixByUser( function shardMixByUser(
@ -464,7 +339,8 @@ function shardMixByUser(
ids = JSON.parse(ids); ids = JSON.parse(ids);
amounts = JSON.parse(amounts); amounts = JSON.parse(amounts);
estimate = (estimate || "0") | 0; estimate = (estimate || "0") | 0;
jc.wallet.jcStandard promiseCb(funId,
jc.wallet.jcStandard
.shardMixByUser({ .shardMixByUser({
tokenId, tokenId,
nftType, nftType,
@ -476,19 +352,7 @@ function shardMixByUser(
nonce, nonce,
signature, signature,
estimate, estimate,
}) }), (v)=>JSON.stringify(v));
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({
errcode: 0,
data: JSON.stringify(result),
})
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
} }
// addresses: [nftId, chip, sign_address] // addresses: [nftId, chip, sign_address]
@ -503,18 +367,13 @@ function pluginChip(
signature, signature,
estimate 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; estimate = (estimate || "0") | 0;
addresses = JSON.parse(addresses); addresses = JSON.parse(addresses);
values = JSON.parse(values); values = JSON.parse(values);
chipIds = JSON.parse(chipIds); chipIds = JSON.parse(chipIds);
slots = JSON.parse(slots); slots = JSON.parse(slots);
jc.wallet.jcStandard promiseCb(funId,
jc.wallet.jcStandard
.pluginChip({ .pluginChip({
addresses, addresses,
values, values,
@ -522,16 +381,7 @@ function pluginChip(
slots, slots,
signature, signature,
estimate, estimate,
}) }), (v)=>JSON.stringify(v));
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({ errcode: 0, data: JSON.stringify(result) })
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
} }
// addresses: [nftId, chip, sign_address] // addresses: [nftId, chip, sign_address]
@ -551,8 +401,8 @@ function unplugChip(
chipIds = JSON.parse(chipIds); chipIds = JSON.parse(chipIds);
slots = JSON.parse(slots); slots = JSON.parse(slots);
estimate = (estimate || "0") | 0; estimate = (estimate || "0") | 0;
promiseCb(funId,
jc.wallet.jcStandard jc.wallet.jcStandard
.unplugChip({ .unplugChip({
addresses, addresses,
values, values,
@ -560,15 +410,17 @@ function unplugChip(
slots, slots,
signature, signature,
estimate, estimate,
}) }), (v)=>JSON.stringify(v));
.then((result) => {
jsb.jcCallback(
funId,
JSON.stringify({ errcode: 0, data: JSON.stringify(result) })
);
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
} }
// ======= end of interact with contract ======= // ======= 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 { android {
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger() compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
buildToolsVersion PROP_BUILD_TOOLS_VERSION buildToolsVersion PROP_BUILD_TOOLS_VERSION
ndkVersion "21.4.7075529"
defaultConfig { defaultConfig {
applicationId "com.cege.games.release" applicationId "com.cege.games.release"
@ -100,7 +101,7 @@ android.applicationVariants.all { variant ->
copy{ copy{
from "${sourceDir}" from "${sourceDir}"
include "js/**" include "Data/js/**"
into outputDir into outputDir
} }
copy { copy {