更新js库

This commit is contained in:
zhl 2023-05-12 09:55:55 +08:00
parent f417db691b
commit 5fb29b98f8
7 changed files with 114 additions and 83 deletions

2
.idea/compiler.xml generated
View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
<bytecodeTargetLevel target="1.8" />
</component>
</project>

9
.idea/gradle.xml generated
View File

@ -7,15 +7,14 @@
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="/usr/local/Cellar/gradle/3.5/libexec" />
<option name="gradleJvm" value="Embedded JDK" />
<option name="gradleJvm" value="1.8" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/install-time-asset_pack" />
<option value="$PROJECT_DIR$/../cocos_js/cocos/platform/android/libcocos2dx" />
<option value="$PROJECT_DIR$/../pubgv4/trunk/android/unityLibrary" />
<option value="$PROJECT_DIR$/../../crypto/cocos_js/cocos/platform/android/libcocos2dx" />
<option value="$PROJECT_DIR$/../../game/wallet-test/target/android/UnityDataAssetPack" />
<option value="$PROJECT_DIR$/../../game/wallet-test/target/android/unityLibrary" />
</set>
</option>
</GradleProjectSettings>

2
.idea/misc.xml generated
View File

@ -15,7 +15,7 @@
</map>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="adopt-1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
console.log(">>begin load wallet main file");
console.log(">> begin load wallet main file.");
function promiseCb(funId, promiseFun, dataParser) {
dataParser = dataParser || ((v) => v);
@ -11,57 +11,89 @@ function promiseCb(funId, promiseFun, dataParser) {
});
}
/**
* init wallet, must call this before all other method
* @param {string} type: wallet type, 0: internal wallet, 1: third party wallet
* @param {string} chain: chain type, 1: ETH, 2: ICON
* @param {string} channel: channel type, 0: google, 1: apple, 2: tiktok, 3: facebook, 4: twitter
* oauth login for before init internal wallet
* @param {*} funId
* @param {*} channel 0: google, 1: apple, 2: tiktok, 3: facebook, 4: twitter 5: tg, 6: email
*/
function initWallet(funId, type, chain, channel = 0) {
chain = parseInt(chain);
console.log(
`initWallet:: type: ${type}, chain: ${chain}, channel: ${channel}`
);
try {
const wallet =
!window.jc || !jc.wallet
? new jcwallet.default({ chain, type })
function walletLogin(funId, channel) {
channel = parseInt(channel);
console.log('walletLogin: ' + channel)
const wallet = !window.jc || !jc.wallet
? new jcwallet.default({ type: 0 })
: jc.wallet;
if (parseInt(type) === 1) {
console.log("wallet init success, begin connect");
wallet
.initThirdPartyWallet()
.then(() => {
console.log("walletconnect connect success");
jsb.jcCallback(
funId,
JSON.stringify({ errcode: 0, data: jc.wallet.currentAccount() })
);
wallet.preLogin(channel)
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
console.log("walletconnect connect error: " + JSON.stringify(err));
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
} else {
wallet
.initInternalWallet(parseInt(channel))
.then(() => {
console.log("internal init success");
jsb.jcCallback(
funId,
JSON.stringify({ errcode: 0, data: jc.wallet.nativeAccount })
);
})
.catch((err) => {
console.log("internal wallet error: " + JSON.stringify(err));
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
}
}
/**
* init internal wallet with password
* @param {*} funId
* @param {*} chain
* @param {*} pass
*/
function initInternalWallet(funId, chain, pass) {
chain = parseInt(chain);
const wallet =
!window.jc || !jc.wallet
? new jcwallet.default({ type: 0 })
: jc.wallet;
wallet
.initInternalWallet(chain, pass)
.then(() => {
console.log("internal init success");
jsb.jcCallback(
funId,
JSON.stringify({ errcode: 0, data: jc.wallet.nativeAccount })
);
})
.catch((err) => {
console.log("internal wallet error: " + JSON.stringify(err));
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
}
/**
* 检查密码是否正确
* @param {*} funId
* @param {*} pass
* @returns
*/
function verifyPassword(funId, pass) {
try {
let result = jsb.verifyLocalPass(pass);
return JSON.stringify({ errcode: 0, data: { result } });
} catch (err) {
console.error("wallet init with error: " + JSON.stringify(err));
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
return JSON.stringify({ errcode: 1, errmsg: err });
}
}
/**
* init third party wallet
* @param {*} funId
* @param {*} chain
*/
function initThirdPartyWallet(funId, chain) {
chain = parseInt(chain);
const wallet =
!window.jc || !jc.wallet
? new jcwallet.default({ type: 1 })
: jc.wallet;
wallet
.initThirdPartyWallet(chain)
.then(() => {
console.log("walletconnect connect success");
jsb.jcCallback(
funId,
JSON.stringify({ errcode: 0, data: jc.wallet.currentAccount() })
);
})
.catch((err) => {
console.log("walletconnect connect error: " + JSON.stringify(err));
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
}
/**
* current account for internal wallet
*/

View File

@ -108,24 +108,24 @@ android {
}
}
//android.applicationVariants.all { variant ->
// delete previous files first
// delete "${buildDir}/intermediates/merged_assets/${variant.dirName}"
//
// variant.mergeAssetsProvider.get().doLast {
// def sourceDir = rootProject.ext.cfgs.jsFilePath
//
// copy{
// from "${sourceDir}"
// include "Data/js/**"
// into outputDir
// }
// copy {
// from "${sourceDir}/cert/cacert.pem"
// into outputDir
// }
// }
//}
android.applicationVariants.all { variant ->
// delete previous files first
delete "${buildDir}/intermediates/merged_assets/${variant.dirName}"
variant.mergeAssetsProvider.get().doLast {
def sourceDir = rootProject.ext.cfgs.jsFilePath
copy{
from "${sourceDir}"
include "Data/js/**"
into outputDir
}
copy {
from "${sourceDir}/cert/cacert.pem"
into outputDir
}
}
}
dependencies {

View File

@ -1,11 +1,11 @@
ext{
cfgs = [
// cocos2d-x项目根路径
cocos2dxBasePath: '/Users/zhl/Documents/workspace/cocos/cocos2d-x',
cocos2dxBasePath: '/Users/zhl/Documents/workspace/crypto/cocos_js',
// js钱包项目路径
jsFilePath: '/Users/zhl/Documents/workspace/android/HeadlessCocos',
jsFilePath: '/Users/zhl/Documents/workspace/android/cocos_android',
// unity export的android项目的根路径
// unityAndroidProject: '/Users/zhl/Documents/workspace/unity/first/android/tebg'
unityAndroidProject: '/Users/zhl/Documents/workspace/unity/first/first/target/android/tebg'
unityAndroidProject: '/Users/zhl/Documents/workspace/game/wallet-test/target/android'
]
}