增加walletconnect相关逻辑
This commit is contained in:
parent
5a869a9a21
commit
4296796411
@ -35,7 +35,7 @@
|
||||
|
||||
id<RenderPluginDelegate> _renderDelegate;
|
||||
}
|
||||
|
||||
+(void)toWallet:(NSString *)url;
|
||||
// override it to add your render plugin delegate
|
||||
- (void)shouldAttachRenderDelegate;
|
||||
|
||||
|
@ -142,6 +142,11 @@ NSInteger _forceInterfaceOrientationMask = 0;
|
||||
UnitySetPlayerFocus(1);
|
||||
}
|
||||
|
||||
+(void)toWallet:(NSString *)url{
|
||||
UIApplication *app = [UIApplication sharedApplication];
|
||||
[app openURL:[NSURL URLWithString:url]];
|
||||
}
|
||||
|
||||
extern "C" void UnityDestroyDisplayLink()
|
||||
{
|
||||
[GetAppController() destroyDisplayLink];
|
||||
|
@ -68,6 +68,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||
se::AutoHandleScope hs;
|
||||
jsb_run_script("js/jsb-adapter/jsb-builtin.js");
|
||||
jsb_run_script("js/jcwallet.js");
|
||||
jsb_run_script("js/platform.js");
|
||||
jsb_run_script("js/main.js");
|
||||
se->addAfterCleanupHook([]() {
|
||||
JSBClassType::destroy();
|
||||
|
@ -78,6 +78,7 @@
|
||||
D0DD4D8D8AC82F06A4331428 /* libil2cpp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 924940699744FB37428516DD /* libil2cpp.a */; };
|
||||
D52A8DA1288E6547006574E8 /* libuv_a.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D52A8D9F288E6547006574E8 /* libuv_a.a */; };
|
||||
D5538BA5287E9908000BDFB6 /* WalletEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D5538BA3287E9908000BDFB6 /* WalletEvent.cpp */; };
|
||||
D589C9BB28B62D93002CAA34 /* cacert.pem in Resources */ = {isa = PBXBuildFile; fileRef = D589C9B928B62D93002CAA34 /* cacert.pem */; };
|
||||
D5F2CED6287BE9C4003C2B62 /* Data in Resources */ = {isa = PBXBuildFile; fileRef = D5F2CED5287BE9C4003C2B62 /* Data */; };
|
||||
D5F2CF41287BEC0D003C2B62 /* Bulk_Generics_3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D5F2CED8287BEC0D003C2B62 /* Bulk_Generics_3.cpp */; };
|
||||
D5F2CF42287BEC0D003C2B62 /* Il2CppMethodPointerTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D5F2CED9287BEC0D003C2B62 /* Il2CppMethodPointerTable.cpp */; };
|
||||
@ -350,7 +351,8 @@
|
||||
D52A8D9F288E6547006574E8 /* libuv_a.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libuv_a.a; sourceTree = "<group>"; };
|
||||
D5538BA3287E9908000BDFB6 /* WalletEvent.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WalletEvent.cpp; sourceTree = "<group>"; };
|
||||
D5538BA4287E9908000BDFB6 /* WalletEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WalletEvent.h; sourceTree = "<group>"; };
|
||||
D5F2CED5287BE9C4003C2B62 /* Data */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Data; path = ../tebg/Data; sourceTree = "<group>"; };
|
||||
D589C9B928B62D93002CAA34 /* cacert.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = cacert.pem; sourceTree = "<group>"; };
|
||||
D5F2CED5287BE9C4003C2B62 /* Data */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Data; path = /Users/zhl/Documents/workspace/unity/first/first/target/ios/Data; sourceTree = "<group>"; };
|
||||
D5F2CED8287BEC0D003C2B62 /* Bulk_Generics_3.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Bulk_Generics_3.cpp; sourceTree = "<group>"; };
|
||||
D5F2CED9287BEC0D003C2B62 /* Il2CppMethodPointerTable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Il2CppMethodPointerTable.cpp; sourceTree = "<group>"; };
|
||||
D5F2CEDA287BEC0D003C2B62 /* Bulk_Generics_2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Bulk_Generics_2.cpp; sourceTree = "<group>"; };
|
||||
@ -536,6 +538,7 @@
|
||||
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D589C9B928B62D93002CAA34 /* cacert.pem */,
|
||||
D5F2CFD1287BF83C003C2B62 /* js */,
|
||||
D5F2CFB2287BF425003C2B62 /* cocos2d_libs.xcodeproj */,
|
||||
D5F2CFAB287BF3BD003C2B62 /* Classes_cocos */,
|
||||
@ -814,7 +817,7 @@
|
||||
D5F2CF40287BEC0D003C2B62 /* Il2CppCompilerCalculateTypeValues_12Table.cpp */,
|
||||
);
|
||||
name = Native;
|
||||
path = ../../tebg/Classes/Native;
|
||||
path = /Users/zhl/Documents/workspace/unity/first/first/target/ios/Classes/Native;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D5F2CFAB287BF3BD003C2B62 /* Classes_cocos */ = {
|
||||
@ -988,6 +991,7 @@
|
||||
56C56C9817D6015200616839 /* Images.xcassets in Resources */,
|
||||
ED8C4EF082C57FADCB72325E /* LaunchScreen-iPhone.xib in Resources */,
|
||||
35DD4E0BA71A8E4480E79156 /* LaunchScreen-iPhonePortrait.png in Resources */,
|
||||
D589C9BB28B62D93002CAA34 /* cacert.pem in Resources */,
|
||||
D5F2CFD2287BF83C003C2B62 /* js in Resources */,
|
||||
7885412B8F5A921FCB052FCC /* LaunchScreen-iPhoneLandscape.png in Resources */,
|
||||
B39C4391A8C22B442413FE00 /* LaunchScreen-iPad.xib in Resources */,
|
||||
|
Binary file not shown.
@ -4,22 +4,6 @@
|
||||
type = "1"
|
||||
version = "2.0">
|
||||
<Breakpoints>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "2A19FD93-1BCA-46F2-AD6D-D771B7C76268"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes/UnityAppController.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "129"
|
||||
endingLineNumber = "129"
|
||||
landmarkName = "-startUnity:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
|
3347
cacert.pem
Normal file
3347
cacert.pem
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
67
js/main.js
67
js/main.js
@ -3,16 +3,24 @@ console.log('>>hi tiny wallet3')
|
||||
/**
|
||||
* 初始化钱包, 所有操作进行前, 必须调用此方法
|
||||
* @param {string} password: 用于加密钱包数据的密码
|
||||
* @return {string} 当前激活帐户的地址
|
||||
*/
|
||||
function initWallet(funId,password) {
|
||||
function initWallet(funId, password) {
|
||||
try {
|
||||
if ( !window.jc || !jc.wwallet ) {
|
||||
var wallet = new jcwallet.default(password);
|
||||
var wallet;
|
||||
if ( !window.jc || !jc.wallet ) {
|
||||
wallet = new jcwallet.default({chain: 322, type: 1, password});
|
||||
} else {
|
||||
wallet = jc.wallet;
|
||||
}
|
||||
let address = jc.wallet.currentAccount().address
|
||||
return JSON.stringify({errcode: 0, data: address});
|
||||
console.log('wallet inited, begin connect')
|
||||
wallet.wConnect.connect()
|
||||
.then(() => {
|
||||
console.log(' walletconnect inited')
|
||||
})
|
||||
// let address = jc.wallet.currentAccount().address
|
||||
return JSON.stringify({errcode: 0, data: ''});
|
||||
} catch(err) {
|
||||
console.error('error init wallet: ' + JSON.stringify(err));
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
}
|
||||
}
|
||||
@ -62,30 +70,33 @@ function currentChain(funId) {
|
||||
|
||||
}
|
||||
/**
|
||||
* 切换当前链
|
||||
* [BOTH]切换当前链
|
||||
* 切换链需要调用currentAccount方法, 以刷新界面显示
|
||||
*/
|
||||
function changeChain(funId,chainId) {
|
||||
try {
|
||||
chainId = parseInt(chainId);
|
||||
let data = jc.wallet.updateCurrentChain(chainId);
|
||||
return JSON.stringify({errcode: 0, data});
|
||||
}catch(err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
}
|
||||
function changeChain(funId, chainId) {
|
||||
// chainId = parseInt(chainId);
|
||||
chainId = 80001;
|
||||
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}));
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 获取当前帐户的登录签名
|
||||
* [BOTH]获取当前帐户的登录签名
|
||||
* @param {string} nonce: 从服务端获取的nonce
|
||||
* @param {string} tips: 签名时的提示
|
||||
*/
|
||||
function loginSign(funId, nonce, tips) {
|
||||
try {
|
||||
let result = jc.wallet.loginSign(nonce, tips);
|
||||
return JSON.stringify({errcode: 0, data: result});
|
||||
} catch(err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
}
|
||||
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}));
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 创建一个新帐号, 并将新建帐号设为当前激活帐号
|
||||
@ -150,7 +161,7 @@ function sendEth(funId, to, amount) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成hash图片
|
||||
* [BOTH]生成hash图片
|
||||
* @param {string} msg: 要生成图片的内容
|
||||
* @param {string} diameter: 图片尺寸
|
||||
*/
|
||||
@ -200,3 +211,13 @@ function sendErc20(funId, address, to, amount) {
|
||||
})
|
||||
}
|
||||
|
||||
function restoreFromMnemonic(funId, mnemonic, password) {
|
||||
try {
|
||||
diameter = parseFloat(diameter);
|
||||
let result = jc.wallet.restoreFromMnemonic(mnemonic, password);
|
||||
return JSON.stringify({errcode: 0, data: result});
|
||||
} catch(err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
}
|
||||
}
|
||||
|
||||
|
18
js/platform.js
Normal file
18
js/platform.js
Normal file
@ -0,0 +1,18 @@
|
||||
if (window.JavascriptJavaBridge) {
|
||||
console.log('regist android jsb.reflection')
|
||||
jsb.reflection = new JavascriptJavaBridge();
|
||||
} else if (window.JavaScriptObjCBridge) {
|
||||
jsb.reflection = new JavaScriptObjCBridge();
|
||||
}
|
||||
window.jumpToWallet = function(url) {
|
||||
url = url || 'wc://';
|
||||
url = `https://metamask.app.link/wc?uri=${encodeURIComponent(url)}`;
|
||||
console.log('open native: ' + url);
|
||||
setTimeout(function() {
|
||||
jsb.reflection.callStaticMethod(
|
||||
'UnityAppController',
|
||||
'toWallet:',
|
||||
url
|
||||
)
|
||||
}, 6000)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user