Skip to content

Commit e3abfd7

Browse files
MOB-743 #comment implemented sign transaction JS and iOS API
1 parent 884b53c commit e3abfd7

File tree

11 files changed

+101
-18
lines changed

11 files changed

+101
-18
lines changed

example/android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ android {
7575

7676
namespace "com.tsauthenticationexample"
7777
defaultConfig {
78-
applicationId "com.tsauthenticationexample"
78+
applicationId "com.transmitsecurity.authsdk-rn-example"
7979
minSdkVersion rootProject.ext.minSdkVersion
8080
targetSdkVersion rootProject.ext.targetSdkVersion
8181
versionCode 1
@@ -127,4 +127,4 @@ repositories {
127127
maven {
128128
url('https://transmit.jfrog.io/artifactory/transmit-security-gradle-release-local/')
129129
}
130-
}
130+
}

example/ios/Podfile.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ PODS:
378378
- react-native-ts-authentication (0.1.0):
379379
- RCT-Folly (= 2021.07.22.00)
380380
- React-Core
381-
- TSAuthentication (~> 1.0.1)
381+
- TSAuthentication (~> 1.0.2)
382382
- React-NativeModulesApple (0.72.7):
383383
- hermes-engine
384384
- React-callinvoker
@@ -492,9 +492,9 @@ PODS:
492492
- RNCAsyncStorage (1.21.0):
493493
- React-Core
494494
- SocketRocket (0.6.1)
495-
- TSAuthentication (1.0.1):
496-
- TSCoreSDK (~> 1.0.12)
497-
- TSCoreSDK (1.0.15)
495+
- TSAuthentication (1.0.2):
496+
- TSCoreSDK (~> 1.0.17)
497+
- TSCoreSDK (1.0.17)
498498
- Yoga (1.14.0)
499499
- YogaKit (1.18.1):
500500
- Yoga (~> 1.14)
@@ -704,7 +704,7 @@ SPEC CHECKSUMS:
704704
React-jsiexecutor: c49502e5d02112247ee4526bc3ccfc891ae3eb9b
705705
React-jsinspector: 8baadae51f01d867c3921213a25ab78ab4fbcd91
706706
React-logger: 8edc785c47c8686c7962199a307015e2ce9a0e4f
707-
react-native-ts-authentication: d4449c4e1da8901d262adb240cfed1e2c58bc6c4
707+
react-native-ts-authentication: fa1fdbf7f401515476cce2fe7aeb2d49e6affbe5
708708
React-NativeModulesApple: b6868ee904013a7923128892ee4a032498a1024a
709709
React-perflogger: 31ea61077185eb1428baf60c0db6e2886f141a5a
710710
React-RCTActionSheet: 392090a3abc8992eb269ef0eaa561750588fc39d
@@ -724,8 +724,8 @@ SPEC CHECKSUMS:
724724
ReactCommon: 5f704096ccf7733b390f59043b6fa9cc180ee4f6
725725
RNCAsyncStorage: 618d03a5f52fbccb3d7010076bc54712844c18ef
726726
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
727-
TSAuthentication: 15aadf1ba9458b0542119d7e710512f0dca91dae
728-
TSCoreSDK: f3d664cc802ecfe06a380d8036d8ef5882c4cc94
727+
TSAuthentication: a94a6f2bacf0bc518bf8974e9795b1bd28647d59
728+
TSCoreSDK: c602d0392aef99325911a9c1431903976d64e23a
729729
Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5
730730
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
731731

example/src/App.tsx

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,51 @@ export default class App extends React.Component<any, State> {
4949
<SafeAreaView style={{ flex: 1 }}>
5050
{
5151
this.state.currentScreen === AppScreen.Home ? (
52-
<HomeScreen onStartAuthentication={this.onStartAuthentication} errorMessage={this.state.errorMessage} />
52+
<HomeScreen onStartAuthentication={this.onStartAuthentication} errorMessage={this.state.errorMessage}
53+
/>
5354
) : (
54-
<LoggedIn username={this.state.username} onLogout={this.onLogout} isNewlyRegistered={this.state.isNewlyRegistered}/>
55+
<LoggedIn
56+
username={this.state.username}
57+
onStartTransaction={this.onStartTransaction}
58+
onLogout={this.onLogout}
59+
isNewlyRegistered={this.state.isNewlyRegistered}
60+
/>
5561
)
5662
}
5763
</SafeAreaView>
5864
);
5965
}
6066

67+
// Transaction Process Handlers
68+
69+
public onStartTransaction = async (rawUsername: string): Promise<void> => {
70+
const username = rawUsername.toLowerCase();
71+
this.setState({ errorMessage: '' });
72+
73+
if (localUserStore.isUserIDStored(username)) {
74+
this.signTransaction(username);
75+
} else {
76+
console.log("User not registered");
77+
this.setState({ errorMessage: 'User not registered' });
78+
}
79+
}
80+
81+
private signTransaction = async (username: string): Promise<void> => {
82+
try {
83+
const response = await TSAuthenticationSDKModule.signTransaction(username);
84+
const accessToken = await this.mockServer.getAccessToken();
85+
const success = await this.mockServer.completeAuthentication(accessToken.token, response.result); // should change???
86+
if (success) {
87+
this.setState({ errorMessage: '' });
88+
console.log("Sign Transaction success");
89+
} else {
90+
this.setState({ errorMessage: 'Sign Transaction failed' });
91+
}
92+
} catch (error: any) {
93+
this.setState({ errorMessage: `${error}` });
94+
}
95+
}
96+
6197
// Authentication Process Handlers
6298

6399
public onStartAuthentication = async (rawUsername: string): Promise<void> => {
@@ -115,10 +151,10 @@ export default class App extends React.Component<any, State> {
115151
// Navigation
116152

117153
private navigateToAuthenticatedUserScreen = (username: string, isNewRegistration: boolean): void => {
118-
this.setState({
119-
currentScreen: AppScreen.AuthenticatedUser,
120-
username,
121-
isNewlyRegistered: isNewRegistration
154+
this.setState({
155+
currentScreen: AppScreen.AuthenticatedUser,
156+
username,
157+
isNewlyRegistered: isNewRegistration
122158
});
123159
}
124160

example/src/home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default class HomeScreen extends React.Component<Props, State> {
6969
/>
7070
</View>
7171
)
72-
}
72+
}
7373
}
7474

7575
const styles = StyleSheet.create({

example/src/logged-in.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { View, StyleSheet, Text, Button, TextInput } from 'react-native';
1111
export type Props = {
1212
username: string;
1313
isNewlyRegistered: boolean;
14+
onStartTransaction: (username: string) => void;
1415
onLogout: () => void;
1516
};
1617

@@ -28,8 +29,9 @@ export default class LoggedIn extends React.Component<Props, State> {
2829
<View style={styles.container}>
2930
<View style={{ marginTop: 20 }} />
3031
<Text style={styles.sectionTitle}>
31-
{`Hello ${this.props.username}. You are authenticated. Your user status is: ${stateText}`}
32+
{`Hello ${this.props.username}. You are authenticated.\nYour user status is:\n ${stateText}`}
3233
</Text>
34+
{this.renderStartSignTransactionButton()}
3335
{this.renderLogoutButton()}
3436
</View>
3537
);
@@ -45,6 +47,17 @@ export default class LoggedIn extends React.Component<Props, State> {
4547
</View>
4648
)
4749
}
50+
51+
private renderStartSignTransactionButton(): ReactElement {
52+
return (
53+
<View style={{ marginTop: 24 }}>
54+
<Button
55+
title="Start Transaction"
56+
onPress={() => this.props.onStartTransaction(this.props.username)}
57+
/>
58+
</View>
59+
)
60+
}
4861
}
4962

5063
const styles = StyleSheet.create({

ios/TsAuthentication.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ @interface RCT_EXTERN_MODULE(TsAuthentication, NSObject)
99
withRejecter:(RCTPromiseRejectBlock)reject)
1010
RCT_EXTERN_METHOD(authenticate:(NSString *)username withResolver:(RCTPromiseResolveBlock)resolve
1111
withRejecter:(RCTPromiseRejectBlock)reject)
12+
RCT_EXTERN_METHOD(signTransaction:(NSString *)username withResolver:(RCTPromiseResolveBlock)resolve
13+
withRejecter:(RCTPromiseRejectBlock)reject)
1214

1315
+ (BOOL)requiresMainQueueSetup
1416
{

ios/TsAuthentication.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,25 @@ class TsAuthentication: NSObject {
6969
}
7070
}
7171

72+
@objc(signTransaction:withResolver:withRejecter:)
73+
func signTransaction(
74+
_ username: String,
75+
resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
76+
77+
runBlockOnMain {
78+
TSAuthentication.shared.signTransaction(username: username) { [weak self] results in
79+
guard let self = self else { return }
80+
81+
switch results {
82+
case .success(let response):
83+
resolve(["result": response.result])
84+
case .failure(let error):
85+
reject(self.kTag, error.localizedDescription, error)
86+
}
87+
}
88+
}
89+
}
90+
7291
// MARK: - Threading
7392

7493
private func runBlockOnMain(_ block: @escaping () -> Void) {
File renamed without changes.

react-native-ts-authentication.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Pod::Spec.new do |s|
1414
s.platforms = { :ios => "15.0" }
1515
s.source = { :git => "https://github.com/TransmitSecurity/react-native-ts-authentication.git", :tag => "#{s.version}" }
1616

17-
s.dependency 'TSAuthentication', '~> 1.0.1'
17+
s.dependency 'TSAuthentication', '~> 1.0.2'
1818
s.source_files = "ios/**/*.{h,m,mm,swift}"
1919

2020
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.

src/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,9 @@ class AuthenticationSDK implements TSAuthenticationSDKModule {
6262
return TsAuthentication.authenticate(username);
6363
}
6464

65+
signTransaction(username: string): Promise<TSAuthenticationSDK.TSAuthenticationResult> {
66+
return TsAuthentication.signTransaction(username);
67+
}
68+
6569
}
6670
export default new AuthenticationSDK();

0 commit comments

Comments
 (0)