add login for tiktok
This commit is contained in:
parent
2aacd20379
commit
42dd1c98e3
@ -38,6 +38,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/sysctl.h>
|
||||
#import <TikTokOpenSDK/TikTokOpenSDKApplicationDelegate.h>
|
||||
|
||||
|
||||
// we assume that app delegate is never changed and we can cache it, instead of re-query UIApplication every time
|
||||
@ -243,6 +244,21 @@ extern "C" void UnityRequestQuit()
|
||||
if (annotation) notifData[@"annotation"] = annotation;
|
||||
|
||||
AppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);
|
||||
|
||||
[[TikTokOpenSDKApplicationDelegate sharedInstance] application:app openURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
|
||||
return YES;
|
||||
}
|
||||
|
||||
// for tiktok
|
||||
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
|
||||
{
|
||||
[[TikTokOpenSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
|
||||
{
|
||||
[[TikTokOpenSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:nil annotation:nil];
|
||||
return YES;
|
||||
}
|
||||
|
||||
@ -289,6 +305,7 @@ extern "C" void UnityRequestQuit()
|
||||
g.delaysTouchesBegan = false;
|
||||
}
|
||||
#endif
|
||||
[[TikTokOpenSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -291,8 +291,10 @@ bool jsb_scanQRCode(se::State& s) {
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
NSString *ntitle = [NSString stringWithCString:title.c_str() encoding:NSUTF8StringEncoding];
|
||||
NSString *nfunid = [NSString stringWithCString:funid.c_str() encoding:NSUTF8StringEncoding];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
|
||||
[window.rootViewController scanQRCode:nfunid title:ntitle];
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -314,8 +316,10 @@ bool JSB_restoreKey(se::State& s)
|
||||
SE_PRECONDITION2(ok, false, "oid is invalid!");
|
||||
NSString *nfunid = [NSString stringWithCString:funid.c_str() encoding:NSUTF8StringEncoding];
|
||||
NSString *noid = [NSString stringWithCString:oid.c_str() encoding:NSUTF8StringEncoding];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
|
||||
[window.rootViewController loadRestoreKey:nfunid oid: noid];
|
||||
});
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
|
||||
@ -332,8 +336,10 @@ bool jsb_signWithGoogle(se::State& s) {
|
||||
ok = seval_to_std_string(args[0], &funid);
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
NSString *nfunid = [NSString stringWithCString:funid.c_str() encoding:NSUTF8StringEncoding];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
|
||||
[window.rootViewController signWithGoogle:nfunid];
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -349,14 +355,35 @@ bool jsb_signWithApple(se::State& s) {
|
||||
ok = seval_to_std_string(args[0], &funid);
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
NSString *nfunid = [NSString stringWithCString:funid.c_str() encoding:NSUTF8StringEncoding];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
|
||||
[window.rootViewController signWithApple:nfunid];
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(jsb_signWithApple)
|
||||
|
||||
bool jsb_signWithTikTok(se::State& s) {
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc >= 1) {
|
||||
bool ok;
|
||||
std::string funid;
|
||||
ok = seval_to_std_string(args[0], &funid);
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
NSString *nfunid = [NSString stringWithCString:funid.c_str() encoding:NSUTF8StringEncoding];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
|
||||
[window.rootViewController signWithTikTok:nfunid];
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(jsb_signWithTikTok)
|
||||
|
||||
bool jsb_signOutGoogle(se::State& s) {
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
@ -366,8 +393,10 @@ bool jsb_signOutGoogle(se::State& s) {
|
||||
ok = seval_to_std_string(args[0], &funid);
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
NSString *nfunid = [NSString stringWithCString:funid.c_str() encoding:NSUTF8StringEncoding];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
|
||||
[window.rootViewController signOutGoogle:nfunid];
|
||||
[window.rootViewController signWithTikTok:nfunid];
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -382,6 +411,7 @@ bool jsb_register_walletevent_modules(se::Object* global) {
|
||||
__jsbObj->defineFunction("restoreKey", _SE(JSB_restoreKey));
|
||||
__jsbObj->defineFunction("signWithGoogle", _SE(jsb_signWithGoogle));
|
||||
__jsbObj->defineFunction("signWithApple", _SE(jsb_signWithApple));
|
||||
__jsbObj->defineFunction("signWithTikTok", _SE(jsb_signWithTikTok));
|
||||
__jsbObj->defineFunction("signOutGoogle", _SE(jsb_signOutGoogle));
|
||||
return true;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
+(void)toWallet:(NSString *)url;
|
||||
-(void)signWithGoogle:(NSString *)funid;
|
||||
-(void)signWithApple:(NSString *)funid;
|
||||
-(void)signWithTikTok:(NSString *)funid;
|
||||
-(void)signOutGoogle:(NSString *)funid;
|
||||
-(void)saveKey:(NSString *) account key:(NSString *) key;
|
||||
-(NSString *)loadKey:(NSString *) account;
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#import "UIViewController+Wallet.h"
|
||||
|
||||
#import <TikTokOpenSDK/TikTokOpenSDKAuth.h>
|
||||
|
||||
#include <string>
|
||||
#include "WalletEvent.h"
|
||||
#include "JcWallet.h"
|
||||
@ -108,6 +110,32 @@ static NSString * const kClientID =
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -- Sign In with TikTok
|
||||
- (void) signWithTikTok:(NSString *) funid {
|
||||
/* STEP 1: Create the request and set permissions */
|
||||
NSArray *scopes = [NSArray arrayWithObjects: @"user.info.basic,video.list", nil]; // list your scopes;
|
||||
NSOrderedSet *scopesSet = [NSOrderedSet orderedSetWithArray:scopes];
|
||||
TikTokOpenSDKAuthRequest *request = [[TikTokOpenSDKAuthRequest alloc] init];
|
||||
request.permissions = scopesSet;
|
||||
|
||||
/* STEP 2: Send the request */
|
||||
__weak typeof(self) ws = self;
|
||||
[request sendAuthRequestViewController:self
|
||||
completion:^(TikTokOpenSDKAuthResponse *_Nonnull resp) {
|
||||
__strong typeof(ws) sf = ws;
|
||||
|
||||
/* STEP 3: Parse and handle the response */
|
||||
if (resp.errCode == 0) {
|
||||
NSString *responseCode = resp.code;
|
||||
// Upload response code to your server and obtain user access token
|
||||
NSLog(@"tiktok resp: %@", responseCode);
|
||||
} else {
|
||||
// User authorization failed. Handle errors
|
||||
NSLog(@"tiktok resp error: %@", resp.description);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
-(void)nativeCb:(NSString *)funid hasErr: (BOOL) hasErr dataStr:(NSString *) dataStr {
|
||||
if ([NSString isStringEmpty:funid]) {
|
||||
|
23
Info.plist
23
Info.plist
@ -2,8 +2,6 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSPhotoLibraryUsageDescription</key>
|
||||
<string>Restore Wallet recovery key need Photo Libray</string>
|
||||
<key>CADisableMinimumFrameDuration</key>
|
||||
<false/>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
@ -25,8 +23,12 @@
|
||||
<key>CFBundleURLTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Editor</string>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>7168682541145278470</string>
|
||||
</array>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>com.googleusercontent.apps.53206975661-0d6q9pqljn84n9l63gm0to1ulap9cbk4</string>
|
||||
@ -35,6 +37,13 @@
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>0</string>
|
||||
<key>LSApplicationQueriesSchemes</key>
|
||||
<array>
|
||||
<string>tiktokopensdk</string>
|
||||
<string>tiktoksharesdk</string>
|
||||
<string>snssdk1180</string>
|
||||
<string>snssdk1233</string>
|
||||
</array>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
@ -44,6 +53,10 @@
|
||||
</dict>
|
||||
<key>NSCameraUsageDescription</key>
|
||||
<string>The camera is need to scan QR codes</string>
|
||||
<key>NSPhotoLibraryUsageDescription</key>
|
||||
<string>Restore Wallet recovery key need Photo Libray</string>
|
||||
<key>TikTokAppID</key>
|
||||
<string>7168682541145278470</string>
|
||||
<key>UIApplicationExitsOnSuspend</key>
|
||||
<false/>
|
||||
<key>UILaunchStoryboardName~ipad</key>
|
||||
@ -56,7 +69,7 @@
|
||||
<false/>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
<string>arm64</string>
|
||||
</array>
|
||||
<key>UIRequiresFullScreen</key>
|
||||
<true/>
|
||||
|
1
Podfile
1
Podfile
@ -3,4 +3,5 @@ use_frameworks!
|
||||
|
||||
target 'Unity-iPhone' do
|
||||
pod 'GoogleSignIn', :path => '/Users/zhl/Downloads/sourcecode/google/GoogleSignIn-iOS/'
|
||||
pod 'TikTokOpenSDK', '~> 5.0.14'
|
||||
end
|
||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -100,5 +100,101 @@
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "7F7312BF-4E29-4C33-8BF4-8D00ADA72A88"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "128"
|
||||
endingLineNumber = "128"
|
||||
landmarkName = "-signWithTikTok:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "436E79B4-8769-4CAF-9B57-CE0E3D8D5AFF"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "134"
|
||||
endingLineNumber = "134"
|
||||
landmarkName = "-signWithTikTok:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "79E256FF-FD49-47A5-BFAE-26D14EFA1DB6"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes/UnityAppController.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "255"
|
||||
endingLineNumber = "255"
|
||||
landmarkName = "UnityAppController"
|
||||
landmarkType = "3">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "A1445887-A4BB-41E7-A04A-1B36F17FF535"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes/UnityAppController.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "248"
|
||||
endingLineNumber = "248"
|
||||
landmarkName = "-application:openURL:options:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "A56931E1-E34B-494D-91D8-C297EC6C5AC7"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes/UnityAppController.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "239"
|
||||
endingLineNumber = "239"
|
||||
landmarkName = "-application:openURL:options:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "4AB36A93-5471-4274-9346-7A357FE914BD"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes/UnityAppController.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "308"
|
||||
endingLineNumber = "308"
|
||||
landmarkName = "-application:didFinishLaunchingWithOptions:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
|
File diff suppressed because one or more lines are too long
221
js/main.js
221
js/main.js
@ -8,15 +8,13 @@ console.log(">>begin load wallet main file");
|
||||
function initWallet(funId, type, chain, channel) {
|
||||
type = parseInt(type)
|
||||
chain = parseInt(chain)
|
||||
channel = channel || 0;
|
||||
channel = channel || 2; // 0:google, 1: apple, 2: tiktok
|
||||
channel = parseInt(channel);
|
||||
console.log(`initWallet:: type: ${type}, chain: ${chain}, channel: ${channel}`)
|
||||
try {
|
||||
var wallet;
|
||||
let wallet;
|
||||
if (!window.jc || !jc.wallet) {
|
||||
wallet = new jcwallet.default({
|
||||
chain,
|
||||
type
|
||||
});
|
||||
wallet = new jcwallet.default({ chain, type });
|
||||
} else {
|
||||
wallet = jc.wallet;
|
||||
}
|
||||
@ -27,7 +25,7 @@ function initWallet(funId, type, chain, channel) {
|
||||
.initThirdPartyWallet()
|
||||
.then(() => {
|
||||
console.log("walletconnect connect success");
|
||||
var account = jc.wallet.currentAccount();
|
||||
let account = jc.wallet.currentAccount();
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: account}));
|
||||
})
|
||||
.catch((err) => {
|
||||
@ -38,7 +36,7 @@ function initWallet(funId, type, chain, channel) {
|
||||
wallet.initInternalWallet(channel)
|
||||
.then(() => {
|
||||
console.log("internal init success");
|
||||
var address = jc.wallet.nativeAccount;
|
||||
let address = jc.wallet.nativeAccount;
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: address}));
|
||||
})
|
||||
.catch((err) => {
|
||||
@ -58,37 +56,21 @@ function initWallet(funId, type, chain, channel) {
|
||||
function currentAccount(funId) {
|
||||
try {
|
||||
let data = jc.wallet.currentAccountData;
|
||||
return JSON.stringify({errcode: 0,data});
|
||||
return JSON.stringify({errcode: 0, data});
|
||||
} catch (err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* all account for internal wallet
|
||||
*/
|
||||
function accountList(funId) {
|
||||
try {
|
||||
let data = jc.wallet.accounts;
|
||||
return JSON.stringify({errcode: 0,data});
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* all chain list we supported
|
||||
*/
|
||||
function chainList(funId) {
|
||||
try {
|
||||
let data = jc.wallet.chainList;
|
||||
return JSON.stringify({errcode: 0,data});
|
||||
return JSON.stringify({errcode: 0, data});
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
return JSON.stringify({ errcode: 1, errmsg: err });
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -109,15 +91,14 @@ function currentChain(funId) {
|
||||
* [BOTH]change chain
|
||||
*/
|
||||
function changeChain(funId, chainId) {
|
||||
// chainId = parseInt(chainId);
|
||||
chainId = 80001;
|
||||
chainId = parseInt(chainId);
|
||||
jc.wallet
|
||||
.updateCurrentChain(chainId)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: result}));
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0,data: result }));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
jsb.jcCallback(funId,JSON.stringify({ errcode: 1,errmsg: err }));
|
||||
});
|
||||
}
|
||||
/**
|
||||
@ -129,87 +110,23 @@ function loginSign(funId, nonce, tips) {
|
||||
jc.wallet
|
||||
.loginSign(nonce, tips)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 1,errmsg: err }));
|
||||
});
|
||||
}
|
||||
/**
|
||||
* add one new account, then active this account
|
||||
* @return {string} account actived
|
||||
*/
|
||||
function createAccount(funId) {
|
||||
try {
|
||||
let result = jc.wallet.createAccount();
|
||||
return JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
});
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* import account with private key
|
||||
* @return {string} account actived
|
||||
*/
|
||||
function importAccount(funId, privateKey) {
|
||||
try {
|
||||
let address = jc.wallet.importAccount(privateKey);
|
||||
return JSON.stringify({
|
||||
errcode: 0,
|
||||
data: address,
|
||||
});
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* active one account
|
||||
*/
|
||||
function selectAccount(funId, address) {
|
||||
try {
|
||||
let result = jc.wallet.selectAccount(address);
|
||||
return JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
});
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get balance of ETH
|
||||
* @param {string} address: account
|
||||
* @param {string} account: account
|
||||
* if account is null, we`ll query for current account of wallet
|
||||
*/
|
||||
function getEthBalance(funId, address) {
|
||||
function getEthBalance(funId, account) {
|
||||
jc.wallet
|
||||
.getBalance(address)
|
||||
.getBalance(account)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
@ -224,13 +141,7 @@ function sendEth(funId, to, amount) {
|
||||
jc.wallet
|
||||
.sendEth(to, amount)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
@ -246,15 +157,9 @@ function generateIcon(funId, msg, diameter) {
|
||||
try {
|
||||
diameter = parseFloat(diameter);
|
||||
let result = jc.wallet.generateIconData(msg, diameter);
|
||||
return JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
});
|
||||
return JSON.stringify({ errcode: 0, data: result });
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
return JSON.stringify({ errcode: 1, errmsg: err });
|
||||
}
|
||||
}
|
||||
|
||||
@ -266,13 +171,7 @@ function erc20Info(funId, address) {
|
||||
jc.wallet
|
||||
.erc20Info(address)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
@ -287,13 +186,7 @@ function erc20Balance(funId, address, account) {
|
||||
jc.wallet
|
||||
.erc20Balance(address, account)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
@ -304,81 +197,24 @@ function sendErc20(funId, address, to, amount) {
|
||||
jc.wallet
|
||||
.sendErc20(address, to, amount)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
function restoreFromMnemonic(funId, mnemonic, password) {
|
||||
try {
|
||||
let result = jc.wallet.restoreFromMnemonic(mnemonic, password);
|
||||
return JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
});
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function scanQRCode(funId, title) {
|
||||
try {
|
||||
console.log('scanQRCode: ' + title)
|
||||
jsb.scanQRCode(funId, title);
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
return JSON.stringify({ errcode: 1, errmsg: err });
|
||||
}
|
||||
}
|
||||
|
||||
function signWithGoogle(funId) {
|
||||
jc.wallet.nativeSvr.signWithGoogle(funId)
|
||||
.then(res => {
|
||||
console.log(`google sign result: ${typeof res}`)
|
||||
console.log(res)
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: res}));
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('google sign error: ' + err);
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
})
|
||||
}
|
||||
|
||||
function signOutGoogle(funId) {
|
||||
jc.wallet.nativeSvr.signOutGoogle(funId)
|
||||
then(res => {
|
||||
console.log(`google sign out result: ${typeof res}`)
|
||||
console.log(res)
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: res}));
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('google sign out error: ' + err);
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
})
|
||||
}
|
||||
|
||||
//function toWalletJNI(funId, url) {
|
||||
// try {
|
||||
// jsb.toWallet(url);
|
||||
// return JSON.stringify({errcode: 0});
|
||||
// } catch(err) {
|
||||
// return JSON.stringify({errcode: 1, errmsg: err});
|
||||
// }
|
||||
//}
|
||||
|
||||
// ======= begin of interact with contract =======
|
||||
function buyNft721(funId, addresses, values, signature) {
|
||||
addresses = JSON.parse(addresses)
|
||||
values = JSON.parse(values)
|
||||
@ -628,3 +464,4 @@ function unplugChip(
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
// ======= end of interact with contract =======
|
||||
|
Loading…
x
Reference in New Issue
Block a user