456 lines
11 KiB
JavaScript
456 lines
11 KiB
JavaScript
console.log('>> inject main.js');
|
|
if (jc.wallet.platform !== 'web') {
|
|
/**
|
|
* oauth login before init internal wallet
|
|
* @param {*} channel 0: google, 1: apple, 2: tiktok, 3: facebook, 4: twitter 5: tg, 6: email, 7: discord 10: client
|
|
*/
|
|
function walletLogin(...args) {
|
|
args.unshift('walletLogin');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
/**
|
|
* init internal wallet with password
|
|
* @param {number | string} chain chain id
|
|
* @param {string} pass
|
|
*/
|
|
function initInternalWallet(...args) {
|
|
args.unshift('initInternalWallet');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
/**
|
|
* verify if password is correct
|
|
* compare with local password hash
|
|
* @param {string} pass password for wallet
|
|
*/
|
|
function verifyPassword(...args) {
|
|
args.unshift('verifyPassword');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
/**
|
|
* init third party wallet
|
|
* @param {number | string} chain chain id
|
|
*/
|
|
function initThirdPartyWallet(...args) {
|
|
args.unshift('initThirdPartyWallet');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
/**
|
|
* all chain list we supported
|
|
*/
|
|
function chainList(...args) {
|
|
args.unshift('chainList');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
/**
|
|
* chain active
|
|
*/
|
|
function currentChain(...args) {
|
|
args.unshift('currentChain');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
/**
|
|
* [BOTH]change chain
|
|
*/
|
|
function changeChain(...args) {
|
|
args.unshift('changeChain');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
/**
|
|
* [BOTH] get sign for login
|
|
* @param {string} nonce: nonce from server
|
|
* @param {string} tips: tips message when sign
|
|
*/
|
|
function loginSign(...args) {
|
|
args.unshift('loginSign');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
/**
|
|
* get balance of ETH
|
|
* @param {string} account: account
|
|
* if account is null, we`ll query for current account of wallet
|
|
*/
|
|
function getEthBalance(...args) {
|
|
args.unshift('getEthBalance');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
/**
|
|
* send ETH from current account
|
|
* @param {string} to: target account
|
|
* @param {string} amount:
|
|
* @param {number} estimate: 1: only estimate gas price
|
|
*/
|
|
function sendEth(...args) {
|
|
args.unshift('sendEth');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
/**
|
|
* [BOTH] generate ICON with hashed message
|
|
* @param {string} msg:
|
|
* @param {string} diameter: size of icon
|
|
*/
|
|
// function generateIcon(...args) {
|
|
// try {
|
|
// diameter = parseFloat(diameter);
|
|
// let result = jc.wallet.generateIconData(msg, diameter);
|
|
// return JSON.stringify({ errcode: 0, data: result });
|
|
// } catch (err) {
|
|
// return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
|
// }
|
|
// }
|
|
|
|
/**
|
|
* get symbol and decimal of ERC20, symbol and decimal
|
|
* @param {string} address: address of ERC20
|
|
*/
|
|
function erc20Info(...args) {
|
|
args.unshift('erc20Info');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
/**
|
|
* get balance of ERC20
|
|
* @param {string} address:
|
|
* @param {string} account:
|
|
*/
|
|
function erc20Balance(...args) {
|
|
args.unshift('erc20Balance');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
/**
|
|
* send ERC20 token to to
|
|
*/
|
|
function sendErc20(...args) {
|
|
args.unshift('sendErc20');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
/**
|
|
* send ERC721 NFT to to
|
|
*/
|
|
function sendErc721(...args) {
|
|
args.unshift('sendErc721');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
/**
|
|
* get balance of ERC721
|
|
* @param {string} address: contract address of NFT
|
|
* @param {string} account: wallet address
|
|
* @param {string} chainId: chain id, number string
|
|
*/
|
|
function erc721Balance(...args) {
|
|
args.unshift('erc721Balance');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
/**
|
|
* get balance of ERC1155
|
|
* @param {string} address:
|
|
* @param {string} account:
|
|
* @param {string} tokenId:
|
|
*/
|
|
function erc1155Balance(...args) {
|
|
args.unshift('erc1155Balance');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
/**
|
|
* send ERC1155 to to
|
|
*/
|
|
function sendErc1155(...args) {
|
|
args.unshift('sendErc1155');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
// function showQRCode(...args) {
|
|
// args.unshift('showQRCode');
|
|
// callProxyMethod.apply(this, args);
|
|
// }
|
|
// function scanQRCode(...args) {
|
|
// args.unshift('scanQRCode');
|
|
// callProxyMethod.apply(this, args);
|
|
// }
|
|
// function showWebPage(...args) {
|
|
// try {
|
|
// jsb.showWebPage(...args);
|
|
// // jsb.openURL(url);
|
|
// return JSON.stringify({ errcode: 0, data: 1 });
|
|
// } catch (err) {
|
|
// return JSON.stringify({ errcode: 1, errmsg: err.message || err });
|
|
// }
|
|
// }
|
|
|
|
// function scanQRCode(...args) {
|
|
// console.log('scanQRCode: ' + title);
|
|
// promiseCb(...args));
|
|
// }
|
|
|
|
function exportWalletSecKey(...args) {
|
|
args.unshift('exportWalletSecKey');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
// ======= begin of interact with contract =======
|
|
function mintNFT(...args) {
|
|
args.unshift('mintNFT');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
// ======= end of interact with contract =======
|
|
// ======= begin of pay =======
|
|
/**
|
|
* crypto: 'CEC' or 'CEG', 'ETH'
|
|
* address: wallet address of user
|
|
* fiat: 'USD' or 'CNY'
|
|
* fiatAmount: '100'
|
|
* payWayCode: '10001'
|
|
* country: 'US'
|
|
* accountId: account id of game user
|
|
* orderId: from pre pay
|
|
*/
|
|
function beginPay(...args) {
|
|
args.unshift('beginPay');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
// ======= end of pay =======
|
|
// ======= begin of transaction history =======
|
|
/**
|
|
*
|
|
* @param {*} funId
|
|
* @param {*} start
|
|
* @param {*} limit
|
|
* @param {*} moreParam e.g. {timeBegin: 1655716867832, timeEnd: 1655716867832}
|
|
*/
|
|
function ethHistory(...args) {
|
|
args.unshift('ethHistory');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
function tokenHistory(...args) {
|
|
args.unshift('tokenHistory');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
// ======= end of transaction history =======
|
|
|
|
/**
|
|
* get email info of current user
|
|
*/
|
|
function emailInfo(...args) {
|
|
args.unshift('emailInfo');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
/**
|
|
* send code with email
|
|
* @param {*} email
|
|
* @param {*} type
|
|
*/
|
|
function sendEmailCode(...args) {
|
|
args.unshift('sendEmailCode');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
/**
|
|
* verify email with code, and update email
|
|
* @param {*} email
|
|
* @param {*} code
|
|
*/
|
|
function verifyEmail(...args) {
|
|
args.unshift('verifyEmail');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
/**
|
|
* check if email had already been registed
|
|
* @param {*} email
|
|
*/
|
|
function checkEmailExists(...args) {
|
|
args.unshift('checkEmailExists');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
/**
|
|
* regist with email
|
|
* @param {*} email
|
|
* @param {*} password
|
|
* @param {*} code
|
|
*/
|
|
function emailRegist(...args) {
|
|
args.unshift('emailRegist');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
/**
|
|
* login with email
|
|
* @param {*} email
|
|
* @param {*} password
|
|
*/
|
|
function emailLogin(...args) {
|
|
args.unshift('emailLogin');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
/**
|
|
* token list of current chain
|
|
*/
|
|
function tokenList(...args) {
|
|
args.unshift('tokenList');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
/**
|
|
* calc token price of USD
|
|
* token must already be in DEX
|
|
* @param {*} tokenName
|
|
* @param {*} amount
|
|
*/
|
|
function tokenPrice(...args) {
|
|
args.unshift('tokenPrice');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
/**
|
|
* fiat list
|
|
*/
|
|
function fiatList(...args) {
|
|
args.unshift('fiatList');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
/**
|
|
* query price of crypto -> usd
|
|
* @param {string} crypto
|
|
* @param {number} chain chain id,
|
|
*/
|
|
function getCryptoPriceOfUSD(...args) {
|
|
args.unshift('getCryptoPriceOfUSD');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
/**
|
|
* format price
|
|
*/
|
|
function formatPrice(...args) {
|
|
args.unshift('formatPrice');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
// begin of market
|
|
// begin sell nft with market
|
|
function marketSellNFT(...args) {
|
|
args.unshift('marketSellNFT');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
// update price of order
|
|
function marketUpdatePrice(...args) {
|
|
args.unshift('marketUpdatePrice');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
// cancel order
|
|
function marketCancelOrder(...args) {
|
|
args.unshift('marketCancelOrder');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
// buy order
|
|
function marketBuy(...args) {
|
|
args.unshift('marketBuy');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
// buy item of game from market
|
|
function gameMarketBuy(...args) {
|
|
args.unshift('gameMarketBuy');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
// get order info from chain
|
|
function marketOrderInfo(...args) {
|
|
args.unshift('marketOrderInfo');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
// end of market
|
|
|
|
// begin of mall
|
|
// buy item of game from mall
|
|
function gameMallBuy(...args) {
|
|
args.unshift('gameMallBuy');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
// end of mall
|
|
|
|
// begin of NFT mall
|
|
function nftMallBuy(...args) {
|
|
args.unshift('nftMallBuy');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
// end of NFT mall
|
|
|
|
// begin of token mall
|
|
// buy ceg with usdt, usdc
|
|
function buyTokenWithErc20(...args) {
|
|
args.unshift('buyTokenWithErc20');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
// begin of token mall
|
|
|
|
function stakeNfts(...args) {
|
|
args.unshift('stakeNfts');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
function redeemNfts(...args) {
|
|
args.unshift('redeemNfts');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
function nftStakeInfo(...args) {
|
|
args.unshift('nftStakeInfo');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
// begin of in-app pay
|
|
function queryGoogleProducts(...args) {
|
|
args.unshift('queryGoogleProducts');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
function queryGooglePurchases(...args) {
|
|
args.unshift('queryGooglePurchases');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
function beginGoogleBuy(...args) {
|
|
args.unshift('beginGoogleBuy');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
// end of in-app pay
|
|
|
|
function deleteAccount(...args) {
|
|
args.unshift('deleteAccount');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
function resetWalletAddress(...args) {
|
|
args.unshift('resetWalletAddress');
|
|
callProxyMethod.apply(this, args);
|
|
}
|
|
|
|
// function storePassLocal(...args) {
|
|
// promiseCb(...args));
|
|
// }
|
|
|
|
// function restorePassLocal(...args) {
|
|
// promiseCb(...args));
|
|
// }
|
|
|
|
// function getLocalPassState(...args) {
|
|
// promiseCb(...args));
|
|
// }
|
|
|
|
// function saveLocalVal(...args) {
|
|
// const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
|
|
// wallet.saveLocalItem(key, val);
|
|
// return JSON.stringify({ errcode: 0, data: 1 });
|
|
// }
|
|
|
|
// function loadLocalVal(...args) {
|
|
// const wallet = !window.jc || !jc.wallet ? new jcwallet.default({ type: 0 }) : jc.wallet;
|
|
// let val = wallet.loadLocalItem(key);
|
|
// return JSON.stringify({ errcode: 0, data: val });
|
|
// }
|
|
}
|