Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate iOS Code to Swift #727

Open
wants to merge 10 commits into
base: master-v12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ dist/
.vscode
example/android/build/
example/.yalc
example/yalc.lock
example/yalc.lock

FabricExample/android/build/
FabricExample/.yalc
FabricExample/yalc.lock
10 changes: 5 additions & 5 deletions FabricExample/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PODS:
- hermes-engine (0.74.1):
- hermes-engine/Pre-built (= 0.74.1)
- hermes-engine/Pre-built (0.74.1)
- Plaid (5.5.1)
- Plaid (6.0.0)
- RCT-Folly (2024.01.01.00):
- boost
- DoubleConversion
Expand Down Expand Up @@ -936,11 +936,11 @@ PODS:
- React-Mapbuffer (0.74.1):
- glog
- React-debug
- react-native-plaid-link-sdk (11.10.2):
- react-native-plaid-link-sdk (12.0.0):
- DoubleConversion
- glog
- hermes-engine
- Plaid (~> 5.5.1)
- Plaid (~> 6.0.0)
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
Expand Down Expand Up @@ -1515,7 +1515,7 @@ SPEC CHECKSUMS:
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
hermes-engine: 16b8530de1b383cdada1476cf52d1b52f0692cbc
Plaid: 276eb2892728a7b33a89f54aa0d62cf532af2c1d
Plaid: ae1b67f78e433a5465939fd093c6af6d024c38b2
RCT-Folly: 02617c592a293bd6d418e0a88ff4ee1f88329b47
RCTDeprecation: efb313d8126259e9294dc4ee0002f44a6f676aba
RCTRequired: f49ea29cece52aee20db633ae7edc4b271435562
Expand All @@ -1540,7 +1540,7 @@ SPEC CHECKSUMS:
React-jsitracing: 233d1a798fe0ff33b8e630b8f00f62c4a8115fbc
React-logger: 7e7403a2b14c97f847d90763af76b84b152b6fce
React-Mapbuffer: 11029dcd47c5c9e057a4092ab9c2a8d10a496a33
react-native-plaid-link-sdk: aa721fc10b14926ee16f805083c2a61ad0c693a5
react-native-plaid-link-sdk: 14d024322c284481ca74925c23c851faa218a126
react-native-safe-area-context: 7f54ad0a774de306ab790c70d9d950321e5c5449
React-nativeconfig: b0073a590774e8b35192fead188a36d1dca23dec
React-NativeModulesApple: df46ff3e3de5b842b30b4ca8a6caae6d7c8ab09f
Expand Down
19 changes: 11 additions & 8 deletions FabricExample/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion FabricExample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"react": "18.2.0",
"react-native": "0.74.1",
"react-native-gesture-handler": "^2.16.2",
"react-native-plaid-link-sdk": "^11.10.3",
"react-native-plaid-link-sdk": "file:.yalc/react-native-plaid-link-sdk",
"react-native-safe-area-context": "4.10.1",
"react-native-screens": "3.31.1"
},
Expand Down
71 changes: 66 additions & 5 deletions FabricExample/src/Screens/PlaidLinkScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {TextInput, Text, TouchableOpacity} from 'react-native';
import {Platform, TextInput, Text, TouchableOpacity} from 'react-native';
import {styles} from '../Styles';

import {
Expand All @@ -12,10 +12,14 @@ import {
usePlaidEmitter,
LinkIOSPresentationStyle,
LinkTokenConfiguration,
FinanceKitError,
create,
open,
syncFinanceKit,
submit,
SubmissionData,
} from 'react-native-plaid-link-sdk';

import {create, open} from 'react-native-plaid-link-sdk/dist/PlaidLink';

function isValidString(str: string): boolean {
if (str && str.trim() !== '') {
return true;
Expand All @@ -35,6 +39,12 @@ function createLinkTokenConfiguration(
};
}

function createSubmissionData(phoneNumber: string): SubmissionData {
return {
phoneNumber: phoneNumber,
};
}

function createLinkOpenProps(): LinkOpenProps {
return {
onSuccess: (success: LinkSuccess) => {
Expand All @@ -53,7 +63,8 @@ function createLinkOpenProps(): LinkOpenProps {
};
}

export function PlaidLinkScreen(): React.JSX.Element {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function PlaidLinkScreen() {
// Render using the link_token integration. Refer to the docs
// https://plaid.com/docs/#create-link-token on how to create
// a new link_token.
Expand All @@ -67,6 +78,32 @@ export function PlaidLinkScreen(): React.JSX.Element {
const [text, onChangeText] = React.useState('');
const [disabled, setDisabled] = React.useState(true);

const iOSVersionParts = String(Platform.Version).split('.');
const [majorVersion, minorVersion] =
iOSVersionParts.length >= 2 ? iOSVersionParts : [null, null];

const financeKitText = () => {
if (majorVersion && minorVersion) {
const majorInt = parseInt(majorVersion, 10);
const minorInt = parseInt(minorVersion, 10);

if (majorInt > 17) {
return <Text style={styles.button}>Sync FinanceKit</Text>;
} else if (majorInt === 17 && minorInt >= 4) {
return <Text style={styles.button}>Sync FinanceKit</Text>;
} else {
return (
<Text style={styles.button}>
FinanceKit not supported on this version of iOS
</Text>
);
}
} else {
// Fallback return if majorVersion or minorVersion are not provided.
return <Text style={styles.button}>Invalid iOS version</Text>;
}
};

return (
<>
<TextInput
Expand All @@ -87,6 +124,15 @@ export function PlaidLinkScreen(): React.JSX.Element {
}}>
<Text style={styles.button}>Create Link</Text>
</TouchableOpacity>
<TouchableOpacity
disabled={disabled}
style={disabled ? styles.disabledButton : styles.button}
onPress={() => {
const submissionData = createSubmissionData('415-555-0015');
submit(submissionData);
}}>
<Text style={styles.button}>Submit Layer Phone Number</Text>
</TouchableOpacity>
<TouchableOpacity
disabled={disabled}
style={disabled ? styles.disabledButton : styles.button}
Expand All @@ -97,6 +143,21 @@ export function PlaidLinkScreen(): React.JSX.Element {
}}>
<Text style={styles.button}>Open Link</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
const completionHandler = (error?: FinanceKitError) => {
if (error) {
console.error('Error:', error);
} else {
console.log('Sync completed successfully');
}
};
const requestAuthorizationIfNeeded = true;
syncFinanceKit(text, requestAuthorizationIfNeeded, completionHandler);
}}>
{financeKitText()}
</TouchableOpacity>
</>
);
}
}
4 changes: 2 additions & 2 deletions example/src/Screens/PlaidEmbeddedLinkScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import {TextInput, Text, View} from 'react-native';
import {styles} from '../Styles';
import {
EmbeddedLinkView,
// EmbeddedLinkView,
LinkIOSPresentationStyle,
LinkEvent,
LinkExit,
Expand Down Expand Up @@ -57,7 +57,7 @@ export function PlaidEmbeddedLinkScreen() {
placeholder="link-sandbox-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
placeholderTextColor={'#D3D3D3'}
/>
<EmbeddedView token={text} />
{/* <EmbeddedView token={text} /> */}
</>
);
}
41 changes: 41 additions & 0 deletions ios/Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Foundation
import LinkKit

extension LinkKit.Plaid.CreateError {
var code: Int {
switch self {
case .configurationError(let nestedError):
return nestedError.code
@unknown default:
return -1
}
}
}

extension LinkKit.ConfigurationError {
var code: Int {
switch self {
case .malformedClientID: return 0
case .missingAuthorization: return 1
case .noProduct: return 2
case .invalidOptionValue: return 3
case .invalidOptionCombination: return 4
case .invalidToken: return 5
@unknown default: return -1
}
}
}

@available(iOS 17.4, *)
extension LinkKit.FinanceKitError {
var code: Int {
switch self {
case .invalidToken: return 0
case .permissionError: return 1
case .linkApiError: return 2
case .permissionAccessError: return 3
case .unknown: return 4
@unknown default: return -1
}
}
}
Loading