Skip to content

Commit

Permalink
Added missing features (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
kober32 authored Oct 21, 2024
1 parent 8a84330 commit 498a1c4
Show file tree
Hide file tree
Showing 24 changed files with 29,644 additions and 1,573 deletions.
32 changes: 16 additions & 16 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ PODS:
- ExpoModulesCore
- EXConstants (16.0.2):
- ExpoModulesCore
- EXNotifications (0.28.15):
- EXNotifications (0.28.18):
- ExpoModulesCore
- Expo (51.0.27):
- Expo (51.0.37):
- ExpoModulesCore
- ExpoAsset (10.0.10):
- ExpoModulesCore
- ExpoFileSystem (17.0.1):
- ExpoModulesCore
- ExpoFont (12.0.9):
- ExpoFont (12.0.10):
- ExpoModulesCore
- ExpoKeepAwake (13.0.2):
- ExpoModulesCore
- ExpoModulesCore (1.12.21):
- ExpoModulesCore (1.12.25):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -46,9 +46,9 @@ PODS:
- hermes-engine (0.74.5):
- hermes-engine/Pre-built (= 0.74.5)
- hermes-engine/Pre-built (0.74.5)
- PowerAuth2 (1.7.9):
- PowerAuthCore (~> 1.7.9)
- PowerAuthCore (1.7.9)
- PowerAuth2 (1.7.10):
- PowerAuthCore (~> 1.7.10)
- PowerAuthCore (1.7.10)
- RCT-Folly (2024.01.01.00):
- boost
- DoubleConversion
Expand Down Expand Up @@ -977,8 +977,8 @@ PODS:
- React-Mapbuffer (0.74.5):
- glog
- React-debug
- react-native-powerauth-mobile-sdk (2.5.1):
- PowerAuth2 (~> 1.7.8)
- react-native-powerauth-mobile-sdk (2.5.3):
- PowerAuth2 (~> 1.7.9)
- React-Core
- React-nativeconfig (0.74.5)
- React-NativeModulesApple (0.74.5):
Expand Down Expand Up @@ -1422,19 +1422,19 @@ SPEC CHECKSUMS:
DoubleConversion: 76ab83afb40bddeeee456813d9c04f67f78771b5
EXApplication: c08200c34daca7af7fd76ac4b9d606077410e8ad
EXConstants: 409690fbfd5afea964e5e9d6c4eb2c2b59222c59
EXNotifications: 7d691d3688bd055afd9de36fdf2cffc4d8be3b24
Expo: b3d76e6e707a0760cd70e7465fff521bbe9e11f6
EXNotifications: dd289340c26bc5388e440fc90d0b2c661cbd0285
Expo: 67b60b3b80a3c8e9f3bcaaa84d06d140229a246d
ExpoAsset: 323700f291684f110fb55f0d4022a3362ea9f875
ExpoFileSystem: 80bfe850b1f9922c16905822ecbf97acd711dc51
ExpoFont: e7f2275c10ca8573c991e007329ad6bf98086485
ExpoFont: 00756e6c796d8f7ee8d211e29c8b619e75cbf238
ExpoKeepAwake: 3b8815d9dd1d419ee474df004021c69fdd316d08
ExpoModulesCore: ae1a4244021797374769ef44499fc4313d2ac676
ExpoModulesCore: 0e7d4d5c13169bbbd53496721d811adbcc5d600a
FBLazyVector: ac12dc084d1c8ec4cc4d7b3cf1b0ebda6dab85af
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
glog: fdfdfe5479092de0c4bdbebedd9056951f092c4f
hermes-engine: 8c1577f3fdb849cbe7729c2e7b5abc4b845e88f8
PowerAuth2: 4672bfcab640cec9dd1fa53a9729fcc23867e992
PowerAuthCore: f228a87fb30f240f49c353fb403010d1d4ff7407
PowerAuth2: 05cf7055c96681545bc1fd7d73c8b4fc6870188f
PowerAuthCore: f415c1e1cf79d3ec2ed463dd2703ed5fd5cd9c73
RCT-Folly: 02617c592a293bd6d418e0a88ff4ee1f88329b47
RCTDeprecation: 3afceddffa65aee666dafd6f0116f1d975db1584
RCTRequired: ec1239bc9d8bf63e10fb92bd8b26171a9258e0c1
Expand All @@ -1459,7 +1459,7 @@ SPEC CHECKSUMS:
React-jsitracing: 3b6060bbf5317663667e1dd93560c7943ab86ccc
React-logger: 257858bd55f3a4e1bc0cf07ddc8fb9faba6f8c7c
React-Mapbuffer: 6c1cacdbf40b531f549eba249e531a7d0bfd8e7f
react-native-powerauth-mobile-sdk: ff2a4bb2a3baf3e6fd6deaefd36429746043e7b0
react-native-powerauth-mobile-sdk: f6a8e1a7d26d7833aceaf02aaf26039cf5a8a452
React-nativeconfig: ba9a2e54e2f0882cf7882698825052793ed4c851
React-NativeModulesApple: 8d11ff8955181540585c944cf48e9e7236952697
React-perflogger: ed4e0c65781521e0424f2e5e40b40cc7879d737e
Expand Down
15 changes: 12 additions & 3 deletions example/ios/example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@
CURRENT_PROJECT_VERSION = 1;
INFOPLIST_FILE = example/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.4;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
OTHER_LDFLAGS = (
"$(inherited)",
Expand Down Expand Up @@ -453,7 +456,10 @@
LIBRARY_SEARCH_PATHS = "$(SDKROOT)/usr/lib/swift\"$(inherited)\"";
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = "$(inherited) ";
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down Expand Up @@ -511,7 +517,10 @@
);
LIBRARY_SEARCH_PATHS = "$(SDKROOT)/usr/lib/swift\"$(inherited)\"";
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_LDFLAGS = "$(inherited) ";
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down
124 changes: 114 additions & 10 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, useEffect } from 'react';
import * as Notifications from 'expo-notifications';
import { StyleSheet, View, Text, Alert, Button } from 'react-native';
import { MobileToken, type MobileTokenUserOperation } from 'react-native-mtoken-sdk';
import { MobileToken, type UserOperation, QROperationParser } from 'react-native-mtoken-sdk';
import { PowerAuth, PowerAuthActivation, PowerAuthAuthentication, type PowerAuthActivationStatus } from 'react-native-powerauth-mobile-sdk';

export default function App() {
Expand Down Expand Up @@ -39,7 +39,7 @@ export default function App() {
await updateStatus()
}

mtoken.acceptLanguage = "cs";
mtoken.setAcceptLanguage("cs");
}

const updateStatus = async () => {
Expand Down Expand Up @@ -69,7 +69,7 @@ export default function App() {
}} />
<Button title='Fetch operations' onPress={async () => {
try {
let result = await mtoken.operationList();
let result = await mtoken.operations.pendingList();
let json = JSON.stringify(result);
console.log(json);
if (result.responseObject) {
Expand All @@ -83,11 +83,11 @@ export default function App() {
}} />
<Button title='Fetch operation detail' onPress={async () => {
try {
let result = await mtoken.operationList();
let result = await mtoken.operations.pendingList();
console.log(JSON.stringify(result));
if (result.responseObject) {
if (result.responseObject[0]) {
let detail = await mtoken.operationDetail(result.responseObject[0].id);
let detail = await mtoken.operations.detail(result.responseObject[0].id);
Alert.alert("OperatioDetailMessage", `${detail.responseObject?.operationCreated.toLocaleString()}\n${detail.responseObject?.formData.title}\n${detail.responseObject?.status}`)
} else {
Alert.alert("No operation in the list")
Expand All @@ -102,11 +102,11 @@ export default function App() {
}} />
<Button title='Auhtorize first operation' onPress={async () => {
try {
let list = await mtoken.operationList();
let list = await mtoken.operations.pendingList();
console.log(JSON.stringify(list));
if (list.responseObject) {
if (list.responseObject[0]) {
let response = await mtoken.authorize(list.responseObject[0], PowerAuthAuthentication.password(pin));
let response = await mtoken.operations.authorize(list.responseObject[0], PowerAuthAuthentication.password(pin));
Alert.alert("Authorize Result", `${response.status}`)
} else {
Alert.alert("No operation in the list")
Expand All @@ -121,11 +121,11 @@ export default function App() {
}} />
<Button title='Reject first operation' onPress={async () => {
try {
let list = await mtoken.operationList();
let list = await mtoken.operations.pendingList();
console.log(JSON.stringify(list));
if (list.responseObject) {
if (list.responseObject[0]) {
let response= await mtoken.reject(list.responseObject[0].id, "HELLO_FROM_REACT");
let response= await mtoken.operations.reject(list.responseObject[0].id, "HELLO_FROM_REACT");
Alert.alert("Reject Result", `${response.status}`)
} else {
Alert.alert("No operation in the list")
Expand Down Expand Up @@ -155,18 +155,122 @@ export default function App() {
let token = (await Notifications.getDevicePushTokenAsync()).data;
console.log(`token: ${token}`);

let apiResult = await mtoken.registerForPush(token);
let apiResult = await mtoken.push.register(token);

alert(JSON.stringify(apiResult));

} catch (err) {
log(err);
}
}} />
<Button title='Authorize QR operation' onPress={async () => {
try {

//const code = makeCode()

Alert.prompt("QR Operation", "Insert QR code data", async code => {
if (!code) {
return;
}

try {

const parsed = QROperationParser.parse(code.replaceAll("\\n", "\n"))

console.log(parsed)

const result = await mtoken.operations.authorizeOffline(parsed, PowerAuthAuthentication.password(pin));
Alert.alert(`code: ${result}`)
} catch (err) {
log(err);
}
})

} catch (err) {
log(err);
}
}} />
<Button title='Fetch inbox' onPress={async () => {
try {
let result = await mtoken.inbox.list(0, 10, false);
let json = JSON.stringify(result);
console.log(json);
if (result.responseObject) {
Alert.alert(json);
} else if (result.responseError) {
Alert.alert(`${result.responseError.code}`, `${result.responseError.message}`);
}
} catch (err) {
log(err);
}
}} />
<Button title='Inbox unread count' onPress={async () => {
try {
let result = await mtoken.inbox.unreadCount();
let json = JSON.stringify(result);
console.log(json);
if (result.responseObject) {
Alert.alert(json);
} else if (result.responseError) {
Alert.alert(`${result.responseError.code}`, `${result.responseError.message}`);
}
} catch (err) {
log(err);
}
}} />
<Button title='Fetch first message' onPress={async () => {
try {
let list = await mtoken.inbox.list(0, 10, false);
let result = await mtoken.inbox.detail(list.responseObject!![0].id);
let json = JSON.stringify(result);
console.log(json);
if (result.responseObject) {
Alert.alert(json);
} else if (result.responseError) {
Alert.alert(`${result.responseError.code}`, `${result.responseError.message}`);
}
} catch (err) {
log(err);
}
}} />
<Button title='Make first message read' onPress={async () => {
try {
let list = await mtoken.inbox.list(0, 10, false);
let result = await mtoken.inbox.markRead(list.responseObject!![0].id);
let json = JSON.stringify(result);
Alert.alert(json);
} catch (err) {
log(err);
}
}} />
<Button title='Make all messages read' onPress={async () => {
try {
let result = await mtoken.inbox.markAllRead()
let json = JSON.stringify(result);
Alert.alert(json);
} catch (err) {
log(err);
}
}} />
</View>
);
}

function makeCode(
operationId: string = "5ff1b1ed-a3cc-45a3-8ab0-ed60950312b6",
title: string = "Payment",
message: string = "Please confirm this payment",
operationData: string = "A1*A100CZK*ICZ2730300000001165254011*D20180425*Thello world",
flags: string = "BCFX",
otherAttrs: string[] | undefined = undefined,
nonce: string = "AD8bOO0Df73kNaIGb3Vmpg==",
signingKey: string = "0",
signature: string = "MEYCIQDby1Uq+MaxiAAGzKmE/McHzNOUrvAP2qqGBvSgcdtyjgIhAMo1sgqNa1pPZTFBhhKvCKFLGDuHuTTYexdmHFjUUIJW"
): string {
let attrs = otherAttrs == null ? "" : otherAttrs.join("\n") + "\n"
return `${operationId}\n${title}\n${message}\n${operationData}\n${flags}\n${attrs}${nonce}\n${signingKey}${signature}`
}

const styles = StyleSheet.create({
container: {
flex: 1,
Expand Down
Loading

0 comments on commit 498a1c4

Please sign in to comment.