react-native-unit-components 1.4.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -57
- package/ios/UNAppInfo/UNAppInfo.swift +5 -1
- package/lib/commonjs/components/UNACHCreditComponent/UNACHCreditComponent.js +46 -3
- package/lib/commonjs/components/UNACHCreditComponent/UNACHCreditComponent.js.map +1 -1
- package/lib/commonjs/components/UNACHCreditComponent/UNACHCreditComponent.utils.js +18 -11
- package/lib/commonjs/components/UNACHCreditComponent/UNACHCreditComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNACHDebitComponent/UNACHDebitComponent.js +5 -6
- package/lib/commonjs/components/UNACHDebitComponent/UNACHDebitComponent.js.map +1 -1
- package/lib/commonjs/components/UNACHDebitComponent/UNACHDebitComponent.utils.js +2 -23
- package/lib/commonjs/components/UNACHDebitComponent/UNACHDebitComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.js +1 -0
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.js.map +1 -1
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.utils.js +2 -1
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.js +1 -0
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.js.map +1 -1
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.utils.js +2 -1
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.js +2 -1
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.js.map +1 -1
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js +1 -0
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.js +1 -0
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.js.map +1 -1
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.utils.js +1 -0
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNCheckDepositComponent/UNCheckDepositComponent.js +1 -0
- package/lib/commonjs/components/UNCheckDepositComponent/UNCheckDepositComponent.js.map +1 -1
- package/lib/commonjs/components/utils/nativeModulesInfo.js +20 -0
- package/lib/commonjs/components/utils/nativeModulesInfo.js.map +1 -0
- package/lib/commonjs/scripts/html/bodyScript.js +13 -2
- package/lib/commonjs/scripts/html/bodyScript.js.map +1 -1
- package/lib/commonjs/unitSdkManager/UnitSdkManager.js +6 -1
- package/lib/commonjs/unitSdkManager/UnitSdkManager.js.map +1 -1
- package/lib/commonjs/webComponent/WebComponent.js +8 -3
- package/lib/commonjs/webComponent/WebComponent.js.map +1 -1
- package/lib/module/components/UNACHCreditComponent/UNACHCreditComponent.js +49 -6
- package/lib/module/components/UNACHCreditComponent/UNACHCreditComponent.js.map +1 -1
- package/lib/module/components/UNACHCreditComponent/UNACHCreditComponent.utils.js +16 -10
- package/lib/module/components/UNACHCreditComponent/UNACHCreditComponent.utils.js.map +1 -1
- package/lib/module/components/UNACHDebitComponent/UNACHDebitComponent.js +5 -6
- package/lib/module/components/UNACHDebitComponent/UNACHDebitComponent.js.map +1 -1
- package/lib/module/components/UNACHDebitComponent/UNACHDebitComponent.utils.js +1 -21
- package/lib/module/components/UNACHDebitComponent/UNACHDebitComponent.utils.js.map +1 -1
- package/lib/module/components/UNAccountComponent/UNAccountComponent.js +1 -0
- package/lib/module/components/UNAccountComponent/UNAccountComponent.js.map +1 -1
- package/lib/module/components/UNAccountComponent/UNAccountComponent.utils.js +2 -1
- package/lib/module/components/UNAccountComponent/UNAccountComponent.utils.js.map +1 -1
- package/lib/module/components/UNActivityComponent/UNActivityComponent.js +1 -0
- package/lib/module/components/UNActivityComponent/UNActivityComponent.js.map +1 -1
- package/lib/module/components/UNActivityComponent/UNActivityComponent.utils.js +2 -1
- package/lib/module/components/UNActivityComponent/UNActivityComponent.utils.js.map +1 -1
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.js +2 -1
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.js.map +1 -1
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js +1 -0
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js.map +1 -1
- package/lib/module/components/UNCardComponent/UNCardComponent.js +1 -0
- package/lib/module/components/UNCardComponent/UNCardComponent.js.map +1 -1
- package/lib/module/components/UNCardComponent/UNCardComponent.utils.js +1 -0
- package/lib/module/components/UNCardComponent/UNCardComponent.utils.js.map +1 -1
- package/lib/module/components/UNCheckDepositComponent/UNCheckDepositComponent.js +1 -0
- package/lib/module/components/UNCheckDepositComponent/UNCheckDepositComponent.js.map +1 -1
- package/lib/module/components/utils/nativeModulesInfo.js +13 -0
- package/lib/module/components/utils/nativeModulesInfo.js.map +1 -0
- package/lib/module/scripts/html/bodyScript.js +13 -2
- package/lib/module/scripts/html/bodyScript.js.map +1 -1
- package/lib/module/unitSdkManager/UnitSdkManager.js +6 -1
- package/lib/module/unitSdkManager/UnitSdkManager.js.map +1 -1
- package/lib/module/webComponent/WebComponent.js +8 -3
- package/lib/module/webComponent/WebComponent.js.map +1 -1
- package/lib/typescript/components/UNACHCreditComponent/UNACHCreditComponent.d.ts +2 -0
- package/lib/typescript/components/UNACHCreditComponent/UNACHCreditComponent.utils.d.ts +4 -1
- package/lib/typescript/components/UNACHDebitComponent/UNACHDebitComponent.d.ts +1 -0
- package/lib/typescript/components/UNACHDebitComponent/UNACHDebitComponent.utils.d.ts +0 -1
- package/lib/typescript/components/UNAccountComponent/UNAccountComponent.d.ts +1 -0
- package/lib/typescript/components/UNActivityComponent/UNActivityComponent.d.ts +2 -1
- package/lib/typescript/components/UNBookPaymentComponent/UNBookPaymentComponent.d.ts +2 -0
- package/lib/typescript/components/UNCardComponent/UNCardComponent.d.ts +2 -0
- package/lib/typescript/components/UNCheckDepositComponent/UNCheckDepositComponent.d.ts +1 -0
- package/lib/typescript/components/utils/nativeModulesInfo.d.ts +1 -0
- package/lib/typescript/scripts/html/bodyScript.d.ts +1 -0
- package/lib/typescript/unitSdkManager/UnitSdkManager.d.ts +3 -1
- package/lib/typescript/webComponent/WebComponent.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/UNACHCreditComponent/UNACHCreditComponent.tsx +46 -5
- package/src/components/UNACHCreditComponent/UNACHCreditComponent.utils.ts +14 -11
- package/src/components/UNACHDebitComponent/UNACHDebitComponent.tsx +7 -9
- package/src/components/UNACHDebitComponent/UNACHDebitComponent.utils.ts +1 -20
- package/src/components/UNAccountComponent/UNAccountComponent.tsx +2 -0
- package/src/components/UNAccountComponent/UNAccountComponent.utils.ts +2 -1
- package/src/components/UNActivityComponent/UNActivityComponent.tsx +4 -2
- package/src/components/UNActivityComponent/UNActivityComponent.utils.ts +3 -1
- package/src/components/UNBookPaymentComponent/UNBookPaymentComponent.tsx +8 -0
- package/src/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.ts +1 -0
- package/src/components/UNCardComponent/UNCardComponent.tsx +5 -2
- package/src/components/UNCardComponent/UNCardComponent.utils.ts +1 -0
- package/src/components/UNCheckDepositComponent/UNCheckDepositComponent.tsx +3 -1
- package/src/components/utils/nativeModulesInfo.ts +11 -0
- package/src/scripts/html/bodyScript.ts +13 -3
- package/src/unitSdkManager/UnitSdkManager.ts +7 -1
- package/src/webComponent/WebComponent.tsx +9 -3
- package/ios/UnitReactNativeComponents.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
- package/ios/UnitReactNativeComponents.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/UnitReactNativeComponents.xcodeproj/project.xcworkspace/xcuserdata/alonshprung.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/UnitReactNativeComponents.xcodeproj/xcuserdata/alonshprung.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
|
@@ -9,10 +9,12 @@ export declare const UNIT_SCRIPT_URL: {
|
|
|
9
9
|
export declare class UnitSDK {
|
|
10
10
|
protected static env?: UNEnvironment;
|
|
11
11
|
protected static theme?: string;
|
|
12
|
+
protected static language?: string;
|
|
12
13
|
protected static signedNonce?: string;
|
|
13
|
-
static init: (env: UNEnvironment, theme?: string) => Promise<void>;
|
|
14
|
+
static init: (env: UNEnvironment, theme?: string, language?: string) => Promise<void>;
|
|
14
15
|
static setSignedNonce: (signedNonce: string) => void;
|
|
15
16
|
static getEnv: () => UNEnvironment | undefined;
|
|
16
17
|
static getTheme: () => string | undefined;
|
|
18
|
+
static getLanguage: () => string | undefined;
|
|
17
19
|
static getSignedNonce: () => string | undefined;
|
|
18
20
|
}
|
package/package.json
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
1
|
+
import React, { useState, useEffect, useRef } from 'react';
|
|
2
2
|
import { WebComponent, WebComponentType } from '../../webComponent/WebComponent';
|
|
3
3
|
import { PresentationMode } from '../../scripts/html/bodyHtml';
|
|
4
4
|
import type { WebViewMessage } from '../../messages/webMessages';
|
|
5
5
|
import type { UNOnLoadResponse, UNACHData, UNACHOnLoadData, UNError, UNOnLoadResponseData } from '../../sharedTypes';
|
|
6
6
|
import { HeightEvent, PageMessage } from '../../messages/webMessages/pageMessage';
|
|
7
|
-
import { View } from 'react-native';
|
|
8
|
-
import {
|
|
9
|
-
import { getACHCreditParams, getACHCreditScript } from './UNACHCreditComponent.utils';
|
|
7
|
+
import { Platform, View } from 'react-native';
|
|
8
|
+
import { getACHCreditParams, getACHCreditScript, injectUnitPlaidResponse } from './UNACHCreditComponent.utils';
|
|
10
9
|
import { PaymentMessage } from '../../messages/webMessages/paymentsMessage';
|
|
11
10
|
import type { ACHEvent } from '../../messages/webMessages/achCreditMessage';
|
|
12
11
|
import { RESPONSE_KEYS, UnitOnLoadResponseEvent } from '../../messages/webMessages/onLoadMessage';
|
|
12
|
+
import { PlaidLinkTokenData, PlaidTokenCreatedEvent, RequestExternalSdkEvent, UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
13
|
+
import { LinkSuccess, openLink } from 'react-native-plaid-link-sdk';
|
|
14
|
+
import type WebView from 'react-native-webview';
|
|
15
|
+
import { getAndroidPackageName } from '../utils/nativeModulesInfo';
|
|
13
16
|
|
|
14
17
|
export interface UNACHCreditComponentProps {
|
|
15
18
|
accountId: string;
|
|
16
19
|
customerToken: string;
|
|
17
20
|
theme?: string;
|
|
21
|
+
language?: string;
|
|
18
22
|
isAutoFocus?: boolean;
|
|
19
23
|
fee?: number;
|
|
24
|
+
withPlaid?: boolean;
|
|
20
25
|
onPaymentCreated?: (data: UNACHData) => void;
|
|
21
26
|
onLoad?: (response: UNOnLoadResponse<UNACHOnLoadData>) => void;
|
|
22
27
|
}
|
|
@@ -24,6 +29,19 @@ export interface UNACHCreditComponentProps {
|
|
|
24
29
|
export const UNACHCreditComponent = (props: UNACHCreditComponentProps) => {
|
|
25
30
|
const [height, setHeight] = useState<number>(0);
|
|
26
31
|
const [presentationMode, setPresentationMode] = useState<PresentationMode>(PresentationMode.Inherit);
|
|
32
|
+
const [linkToken, setLinkToken] = useState<string>();
|
|
33
|
+
const [appPackageName, setAppPackageName] = useState<string>();
|
|
34
|
+
const webRef = useRef<WebView>(null);
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const setPackageNameForAndroid = async () => {
|
|
38
|
+
if (Platform.OS === 'android') {
|
|
39
|
+
const packageName = await getAndroidPackageName();
|
|
40
|
+
setAppPackageName(packageName);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
setPackageNameForAndroid();
|
|
44
|
+
}, []);
|
|
27
45
|
|
|
28
46
|
const handleUnitOnLoad = (response: UnitOnLoadResponseEvent) => {
|
|
29
47
|
if (!props.onLoad) {
|
|
@@ -71,19 +89,42 @@ export const UNACHCreditComponent = (props: UNACHCreditComponentProps) => {
|
|
|
71
89
|
}
|
|
72
90
|
break;
|
|
73
91
|
}
|
|
92
|
+
case UnitMessage.UNIT_PLAID_TOKEN_CREATED: {
|
|
93
|
+
const linkTokenEvent = message.details as PlaidTokenCreatedEvent;
|
|
94
|
+
const linkTokenData = linkTokenEvent.linkToken as PlaidLinkTokenData;
|
|
95
|
+
setLinkToken(linkTokenData.attributes.linkToken);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
case UnitMessage.UNIT_REQUEST_EXTERNAL_SDK: {
|
|
100
|
+
const externalSdkType = (message.details as RequestExternalSdkEvent).type;
|
|
101
|
+
if (externalSdkType !== 'plaid') return;
|
|
102
|
+
linkToken && openLink({
|
|
103
|
+
tokenConfig: { noLoadingState: false, token: linkToken },
|
|
104
|
+
onSuccess: (success: LinkSuccess) => {
|
|
105
|
+
injectUnitPlaidResponse(webRef.current, success);
|
|
106
|
+
},
|
|
107
|
+
onExit: exit => { console.log(exit); }
|
|
108
|
+
}).catch(e => {
|
|
109
|
+
console.error(e);
|
|
110
|
+
});
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
74
113
|
}
|
|
75
114
|
};
|
|
76
115
|
|
|
77
116
|
const renderACHCreditWebView = () => {
|
|
78
117
|
return (
|
|
79
118
|
<WebComponent
|
|
119
|
+
ref={webRef}
|
|
80
120
|
type={WebComponentType.achCreditPayment}
|
|
81
121
|
presentationMode={presentationMode}
|
|
82
122
|
params={getACHCreditParams(props)}
|
|
83
|
-
script={getACHCreditScript()}
|
|
123
|
+
script={getACHCreditScript(appPackageName)}
|
|
84
124
|
onMessage={(message: WebViewMessage) => handleWebViewMessage(message)}
|
|
85
125
|
isScrollable={false}
|
|
86
126
|
theme={props.theme}
|
|
127
|
+
language={props.language}
|
|
87
128
|
/>
|
|
88
129
|
);
|
|
89
130
|
};
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import type { UNACHCreditComponentProps } from './UNACHCreditComponent';
|
|
2
|
-
|
|
3
|
-
import {
|
|
2
|
+
import type WebView from 'react-native-webview';
|
|
3
|
+
import type { LinkSuccess } from 'react-native-plaid-link-sdk';
|
|
4
|
+
import { DISPATCH_PLAID_RESPONSE, LISTENERS } from '../../scripts/html/bodyScript';
|
|
4
5
|
|
|
5
6
|
export const getACHCreditParams = (props: UNACHCreditComponentProps) => {
|
|
6
7
|
return `
|
|
7
8
|
account-id="${props.accountId}"
|
|
8
9
|
customer-token="${props.customerToken}"
|
|
10
|
+
with-plaid="${props.withPlaid ?? false}"
|
|
9
11
|
is-auto-focus="${props.isAutoFocus ?? false}"
|
|
10
12
|
${props.fee ? `fee="${props.fee}"` : ''}
|
|
11
13
|
style="height: 100%"
|
|
12
14
|
`;
|
|
13
15
|
};
|
|
14
16
|
|
|
15
|
-
export const getACHCreditScript = () => {
|
|
17
|
+
export const getACHCreditScript = (appPackageName?: string) => {
|
|
16
18
|
return `
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}).catch((e) => {
|
|
22
|
-
console.log(e)
|
|
23
|
-
})
|
|
24
|
-
});
|
|
19
|
+
${LISTENERS.unitPlaidTokenCreated}
|
|
20
|
+
${appPackageName && `window.UnitMobileSDKConfig.androidPackageName='${appPackageName}'`}
|
|
21
|
+
${LISTENERS.unitPaymentCreated}
|
|
22
|
+
${DISPATCH_PLAID_RESPONSE}
|
|
25
23
|
`;
|
|
26
24
|
};
|
|
25
|
+
|
|
26
|
+
export const injectUnitPlaidResponse = (currentWeb: WebView | null, success: LinkSuccess) => {
|
|
27
|
+
const successObj = {data: { publicToken: success.publicToken, metadata: success.metadata}};
|
|
28
|
+
currentWeb?.injectJavaScript(`dispatchPlaidEvent(${JSON.stringify(successObj)})`);
|
|
29
|
+
};
|
|
@@ -6,19 +6,20 @@ import type { UNOnLoadResponse, UNACHData, UNError, UNOnLoadResponseData, UNACHO
|
|
|
6
6
|
import { HeightEvent, PageMessage } from '../../messages/webMessages/pageMessage';
|
|
7
7
|
import { Platform, View } from 'react-native';
|
|
8
8
|
import { PlaidLinkTokenData, PlaidTokenCreatedEvent, RequestExternalSdkEvent, UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
9
|
-
import { getACHDebitParams, getACHDebitScript,
|
|
10
|
-
|
|
9
|
+
import { getACHDebitParams, getACHDebitScript, injectUnitPlaidResponse } from './UNACHDebitComponent.utils';
|
|
11
10
|
import { LinkSuccess, openLink } from 'react-native-plaid-link-sdk';
|
|
12
11
|
import type WebView from 'react-native-webview';
|
|
13
12
|
|
|
14
13
|
import { PaymentMessage } from '../../messages/webMessages/paymentsMessage';
|
|
15
14
|
import type { ACHEvent } from '../../messages/webMessages/achCreditMessage';
|
|
16
15
|
import { RESPONSE_KEYS, UnitOnLoadResponseEvent } from '../../messages/webMessages/onLoadMessage';
|
|
16
|
+
import { getAndroidPackageName } from '../utils/nativeModulesInfo';
|
|
17
17
|
|
|
18
18
|
export interface UNACHDebitComponentProps {
|
|
19
19
|
accountId: string;
|
|
20
20
|
customerToken: string;
|
|
21
21
|
theme?: string;
|
|
22
|
+
language?: string;
|
|
22
23
|
isAutoFocus?: boolean;
|
|
23
24
|
fee?: number;
|
|
24
25
|
onPaymentCreated?: (data: UNACHData) => void;
|
|
@@ -42,10 +43,6 @@ export const UNACHDebitComponent = (props: UNACHDebitComponentProps) => {
|
|
|
42
43
|
setPackageNameForAndroid();
|
|
43
44
|
}, []);
|
|
44
45
|
|
|
45
|
-
const dispatchUnitPlaidResponse = (success: LinkSuccess) => {
|
|
46
|
-
injectUnitPlaidResponse(webRef.current, success);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
46
|
const handleUnitOnLoad = (response: UnitOnLoadResponseEvent) => {
|
|
50
47
|
if (!props.onLoad) {
|
|
51
48
|
return;
|
|
@@ -103,9 +100,9 @@ export const UNACHDebitComponent = (props: UNACHDebitComponentProps) => {
|
|
|
103
100
|
const externalSdkType = (message.details as RequestExternalSdkEvent).type;
|
|
104
101
|
if (externalSdkType !== 'plaid') return;
|
|
105
102
|
linkToken && openLink({
|
|
106
|
-
tokenConfig: { noLoadingState: false, token: linkToken},
|
|
107
|
-
onSuccess: (success) => {
|
|
108
|
-
|
|
103
|
+
tokenConfig: { noLoadingState: false, token: linkToken },
|
|
104
|
+
onSuccess: (success: LinkSuccess) => {
|
|
105
|
+
injectUnitPlaidResponse(webRef.current, success);
|
|
109
106
|
},
|
|
110
107
|
onExit: exit => { console.log(exit); }
|
|
111
108
|
}).catch(e => {
|
|
@@ -127,6 +124,7 @@ export const UNACHDebitComponent = (props: UNACHDebitComponentProps) => {
|
|
|
127
124
|
onMessage={(message: WebViewMessage) => handleWebViewMessage(message)}
|
|
128
125
|
isScrollable={false}
|
|
129
126
|
theme={props.theme}
|
|
127
|
+
language={props.language}
|
|
130
128
|
/>
|
|
131
129
|
);
|
|
132
130
|
};
|
|
@@ -3,9 +3,6 @@ import type { UNACHDebitComponentProps } from './UNACHDebitComponent';
|
|
|
3
3
|
|
|
4
4
|
import type WebView from 'react-native-webview';
|
|
5
5
|
import type { LinkSuccess } from 'react-native-plaid-link-sdk';
|
|
6
|
-
import { NativeModules } from 'react-native';
|
|
7
|
-
const { RNAppInfoModule } = NativeModules;
|
|
8
|
-
import { UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
9
6
|
|
|
10
7
|
export const getACHDebitParams = (props: UNACHDebitComponentProps) => {
|
|
11
8
|
return `
|
|
@@ -17,25 +14,9 @@ export const getACHDebitParams = (props: UNACHDebitComponentProps) => {
|
|
|
17
14
|
`;
|
|
18
15
|
};
|
|
19
16
|
|
|
20
|
-
export const getAndroidPackageName = async () => {
|
|
21
|
-
try {
|
|
22
|
-
const response = await RNAppInfoModule.getAppPackageName();
|
|
23
|
-
return response;
|
|
24
|
-
} catch (error) {
|
|
25
|
-
console.error(error);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
17
|
export const getACHDebitScript = (androidPackageName?: string) => {
|
|
30
18
|
return `
|
|
31
|
-
|
|
32
|
-
const response = e.detail
|
|
33
|
-
response.then((data) => {
|
|
34
|
-
postMessageToSDK({ type: "${UnitMessage.UNIT_PLAID_TOKEN_CREATED}", details: { linkToken: data.data }})
|
|
35
|
-
}).catch((e) => {
|
|
36
|
-
console.log(e)
|
|
37
|
-
})
|
|
38
|
-
});
|
|
19
|
+
${LISTENERS.unitPlaidTokenCreated}
|
|
39
20
|
${androidPackageName && `window.UnitMobileSDKConfig.androidPackageName='${androidPackageName}'`}
|
|
40
21
|
${LISTENERS.unitPaymentCreated}
|
|
41
22
|
${DISPATCH_PLAID_RESPONSE}
|
|
@@ -23,6 +23,7 @@ export interface UNAccountComponentProps {
|
|
|
23
23
|
|
|
24
24
|
// ui
|
|
25
25
|
theme?: string;
|
|
26
|
+
language?: string;
|
|
26
27
|
hideActionsMenuButton?: boolean;
|
|
27
28
|
hideSelectionMenuButton?: boolean;
|
|
28
29
|
|
|
@@ -122,6 +123,7 @@ export const UNAccountComponent = React.forwardRef<UNAccountRef, UNAccountCompon
|
|
|
122
123
|
params={getAccountParams(props)}
|
|
123
124
|
script={getAccountScript()}
|
|
124
125
|
theme={props.theme}
|
|
126
|
+
language={props.language}
|
|
125
127
|
onMessage={message => handleMessage(message)}
|
|
126
128
|
width={windowWidth}
|
|
127
129
|
isScrollable={false}
|
|
@@ -5,9 +5,10 @@ import { WebComponentType } from '../../webComponent/WebComponent';
|
|
|
5
5
|
import type { UNAccountMenuAction } from 'src/sharedTypes';
|
|
6
6
|
|
|
7
7
|
export const getAccountParams = (props: UNAccountComponentProps) => {
|
|
8
|
+
const accountIdParam = props.accountId ? `account-id="${props.accountId}"` : '';
|
|
8
9
|
return `
|
|
9
|
-
account-id="${props.accountId}"
|
|
10
10
|
customer-token="${props.customerToken}"
|
|
11
|
+
${accountIdParam}
|
|
11
12
|
hide-actions-menu-button="${props.hideActionsMenuButton || false}"
|
|
12
13
|
hide-selection-menu-button="${props.hideSelectionMenuButton || false}"
|
|
13
14
|
`;
|
|
@@ -18,12 +18,13 @@ import { ActivityMessage } from '../../messages/webMessages/activityMessage';
|
|
|
18
18
|
const DEFAULT_HEIGHT = Dimensions.get('window').height * 0.5;
|
|
19
19
|
export interface UNActivityComponentProps {
|
|
20
20
|
// inputs
|
|
21
|
-
accountId: string;
|
|
22
21
|
customerToken: string;
|
|
22
|
+
accountId?: string;
|
|
23
23
|
queryFilter?: string
|
|
24
24
|
|
|
25
25
|
// ui
|
|
26
26
|
theme?: string;
|
|
27
|
+
language?: string;
|
|
27
28
|
hideFilterButton?: boolean;
|
|
28
29
|
|
|
29
30
|
// event
|
|
@@ -43,7 +44,7 @@ export const UNActivityComponent = (props: UNActivityComponentProps) => {
|
|
|
43
44
|
};
|
|
44
45
|
|
|
45
46
|
useListenerToBus({ busEventKey: UnitMessage.UNIT_REQUEST_REFRESH, action: requestRefresh });
|
|
46
|
-
useListenerToBus({ busEventKey: ActivityMessage.UNIT_ACTIVITY_FILTERS_CHANGED, action: dispatchActivityFiltersChanged});
|
|
47
|
+
useListenerToBus({ busEventKey: ActivityMessage.UNIT_ACTIVITY_FILTERS_CHANGED, action: dispatchActivityFiltersChanged });
|
|
47
48
|
|
|
48
49
|
const handleUnitOnLoad = (response: UnitOnLoadResponseEvent) => {
|
|
49
50
|
if (!props.onLoad) {
|
|
@@ -103,6 +104,7 @@ export const UNActivityComponent = (props: UNActivityComponentProps) => {
|
|
|
103
104
|
onMessage={(message: WebViewMessage) => handleWebViewMessage(message)}
|
|
104
105
|
nestedScrollEnabled={true}
|
|
105
106
|
theme={props.theme}
|
|
107
|
+
language={props.language}
|
|
106
108
|
script={getActivityScript()}
|
|
107
109
|
/>
|
|
108
110
|
);
|
|
@@ -5,10 +5,12 @@ import { DISPATCH_REQUEST_REFRESH } from './../../scripts/html/bodyScript';
|
|
|
5
5
|
import type { UNActivityComponentProps } from './UNActivityComponent';
|
|
6
6
|
|
|
7
7
|
export const getActivityParams = (props: UNActivityComponentProps) => {
|
|
8
|
+
const accountIdParam = props.accountId ? `account-id="${props.accountId}"` : '';
|
|
8
9
|
const queryFilterParam = props.queryFilter ? `query-filter="${props.queryFilter}"` : '';
|
|
10
|
+
|
|
9
11
|
return `
|
|
10
|
-
account-id="${props.accountId}"
|
|
11
12
|
customer-token="${props.customerToken}"
|
|
13
|
+
${accountIdParam}
|
|
12
14
|
hide-filter-button="${props.hideFilterButton || false}"
|
|
13
15
|
${queryFilterParam}
|
|
14
16
|
style="height: 100%"
|
|
@@ -12,12 +12,19 @@ import type { BookPaymentEvent } from '../../messages/webMessages/bookPaymentMes
|
|
|
12
12
|
import { RESPONSE_KEYS, UnitOnLoadResponseEvent } from '../../messages/webMessages/onLoadMessage';
|
|
13
13
|
|
|
14
14
|
export interface UNBookPaymentComponentProps {
|
|
15
|
+
//inputs
|
|
15
16
|
accountId: string;
|
|
16
17
|
customerToken: string;
|
|
17
18
|
isSameCustomer: boolean;
|
|
18
19
|
counterPartyAccountId: string;
|
|
19
20
|
counterPartyName: string;
|
|
21
|
+
|
|
22
|
+
// ui
|
|
20
23
|
theme?: string;
|
|
24
|
+
language?: string;
|
|
25
|
+
isAutoFocus?: boolean;
|
|
26
|
+
|
|
27
|
+
// events
|
|
21
28
|
onPaymentCreated?: (data: UNBookPaymentData) => void;
|
|
22
29
|
onLoad?: (response: UNOnLoadResponse<UNAccountData>) => void;
|
|
23
30
|
}
|
|
@@ -77,6 +84,7 @@ export const UNBookPaymentComponent = (props: UNBookPaymentComponentProps) => {
|
|
|
77
84
|
onMessage={(message: WebViewMessage) => handleWebViewMessage(message)}
|
|
78
85
|
isScrollable={false}
|
|
79
86
|
theme={props.theme}
|
|
87
|
+
language={props.language}
|
|
80
88
|
/>
|
|
81
89
|
);
|
|
82
90
|
};
|
|
@@ -10,6 +10,7 @@ export const getBookPaymentParams = (props: UNBookPaymentComponentProps) => {
|
|
|
10
10
|
is-same-customer="${props.isSameCustomer}"
|
|
11
11
|
counterparty-account-id="${props.counterPartyAccountId}"
|
|
12
12
|
counterparty-name="${props.counterPartyName}"
|
|
13
|
+
is-auto-focus="${props.isAutoFocus || false}"
|
|
13
14
|
style="height: 100%"
|
|
14
15
|
`;
|
|
15
16
|
};
|
|
@@ -21,9 +21,11 @@ export interface UNCardComponentProps {
|
|
|
21
21
|
// inputs
|
|
22
22
|
cardId: string;
|
|
23
23
|
customerToken: string;
|
|
24
|
+
learnMoreUrl?: string;
|
|
24
25
|
|
|
25
26
|
// ui
|
|
26
27
|
theme?: string;
|
|
28
|
+
language?: string;
|
|
27
29
|
hideActionsMenuButton?: boolean;
|
|
28
30
|
hideCardTitle?: boolean;
|
|
29
31
|
hideSensitiveDataButton?: boolean;
|
|
@@ -36,10 +38,10 @@ export interface UNCardComponentProps {
|
|
|
36
38
|
}
|
|
37
39
|
export interface CardRef {
|
|
38
40
|
openActionsMenu: () => void;
|
|
39
|
-
openAction:(action: UNCardMenuAction) => void;
|
|
41
|
+
openAction: (action: UNCardMenuAction) => void;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
export const UNCardComponent = React.forwardRef<CardRef, UNCardComponentProps>(function UNCardComponent
|
|
44
|
+
export const UNCardComponent = React.forwardRef<CardRef, UNCardComponentProps>(function UNCardComponent(props, cardRef) {
|
|
43
45
|
const [height, setHeight] = useState(0);
|
|
44
46
|
const windowWidth = Dimensions.get('window').width;
|
|
45
47
|
|
|
@@ -169,6 +171,7 @@ export const UNCardComponent = React.forwardRef<CardRef, UNCardComponentProps>(f
|
|
|
169
171
|
presentationMode={PresentationMode.Default}
|
|
170
172
|
params={getCardParams(props)}
|
|
171
173
|
theme={props.theme}
|
|
174
|
+
language={props.language}
|
|
172
175
|
script={getCardScript()}
|
|
173
176
|
onMessage={message => handleMessage(message)}
|
|
174
177
|
width={windowWidth}
|
|
@@ -17,6 +17,7 @@ export const getCardParams = (props: UNCardComponentProps) => {
|
|
|
17
17
|
hide-actions-menu-button="${props.hideActionsMenuButton || false}"
|
|
18
18
|
hide-card-title="${props.hideCardTitle || false}"
|
|
19
19
|
hide-sensitive-data-button="${props.hideSensitiveDataButton || false}"
|
|
20
|
+
learn-more-url="${props.learnMoreUrl || ''}"
|
|
20
21
|
`;
|
|
21
22
|
};
|
|
22
23
|
|
|
@@ -18,6 +18,7 @@ export interface UNCheckDepositComponentProps {
|
|
|
18
18
|
fee: number;
|
|
19
19
|
customerToken: string;
|
|
20
20
|
theme?: string;
|
|
21
|
+
language?: string;
|
|
21
22
|
onLoad?: (response: UNOnLoadResponse<UNAccountData>) => void;
|
|
22
23
|
onDepositCreated?: (checkData: UNCheckDepositData) => void
|
|
23
24
|
onRestartRequest?: (checkData: UNCheckDepositData) => void
|
|
@@ -31,7 +32,7 @@ export const UNCheckDepositComponent = (props: UNCheckDepositComponentProps) =>
|
|
|
31
32
|
const requestCameraAccess = async () => {
|
|
32
33
|
try {
|
|
33
34
|
await Camera.requestAccess();
|
|
34
|
-
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
36
|
} catch (error: any) {
|
|
36
37
|
console.error(error);
|
|
37
38
|
}
|
|
@@ -95,6 +96,7 @@ export const UNCheckDepositComponent = (props: UNCheckDepositComponentProps) =>
|
|
|
95
96
|
script={getCheckDepositScript()}
|
|
96
97
|
onMessage={(message: WebViewMessage) => handleWebViewMessage(message)}
|
|
97
98
|
theme={props.theme}
|
|
99
|
+
language={props.language}
|
|
98
100
|
isScrollable={true}
|
|
99
101
|
/>
|
|
100
102
|
);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NativeModules } from 'react-native';
|
|
2
|
+
const { RNAppInfoModule } = NativeModules;
|
|
3
|
+
|
|
4
|
+
export const getAndroidPackageName = async () => {
|
|
5
|
+
try {
|
|
6
|
+
const response = await RNAppInfoModule.getAppPackageName();
|
|
7
|
+
return response;
|
|
8
|
+
} catch (error) {
|
|
9
|
+
console.error(error);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -84,7 +84,7 @@ export const LISTENERS = {
|
|
|
84
84
|
window.addEventListener("${UnitMessage.UNIT_REQUEST_EXTERNAL_SDK}", (e) => {
|
|
85
85
|
postMessageToSDK({ type: "${UnitMessage.UNIT_REQUEST_EXTERNAL_SDK}", details: e.detail })
|
|
86
86
|
});
|
|
87
|
-
`,
|
|
87
|
+
`,
|
|
88
88
|
unitPaymentCreated: `
|
|
89
89
|
window.addEventListener("${PaymentMessage.PAYMENT_CREATED}", (e) => {
|
|
90
90
|
const response = e.detail
|
|
@@ -93,8 +93,18 @@ export const LISTENERS = {
|
|
|
93
93
|
}).catch((e) => {
|
|
94
94
|
console.log(e)
|
|
95
95
|
})
|
|
96
|
-
})
|
|
97
|
-
|
|
96
|
+
});
|
|
97
|
+
`,
|
|
98
|
+
unitPlaidTokenCreated: `
|
|
99
|
+
window.addEventListener("${UnitMessage.UNIT_PLAID_TOKEN_CREATED}", (e) => {
|
|
100
|
+
const response = e.detail
|
|
101
|
+
response.then((data) => {
|
|
102
|
+
postMessageToSDK({ type: "${UnitMessage.UNIT_PLAID_TOKEN_CREATED}", details: { linkToken: data.data }})
|
|
103
|
+
}).catch((e) => {
|
|
104
|
+
console.log(e)
|
|
105
|
+
})
|
|
106
|
+
});
|
|
107
|
+
`,
|
|
98
108
|
unitAccountChanged: `
|
|
99
109
|
window.addEventListener("${AccountMessage.UNIT_ACCOUNT_CHANGED}", (e) => {
|
|
100
110
|
const response = e.detail
|
|
@@ -14,12 +14,14 @@ export const UNIT_SCRIPT_URL = {
|
|
|
14
14
|
export class UnitSDK {
|
|
15
15
|
protected static env?: UNEnvironment;
|
|
16
16
|
protected static theme?: string;
|
|
17
|
+
protected static language?: string;
|
|
17
18
|
protected static signedNonce?: string;
|
|
18
19
|
|
|
19
|
-
public static init = async (env: UNEnvironment, theme?: string) => {
|
|
20
|
+
public static init = async (env: UNEnvironment, theme?: string, language?: string) => {
|
|
20
21
|
try {
|
|
21
22
|
this.env = env;
|
|
22
23
|
this.theme = theme;
|
|
24
|
+
this.language = language;
|
|
23
25
|
await fetchUnitScript();
|
|
24
26
|
EventBus.Instance.event(SDKMessage.IS_SDK_INITIALIZED, {});
|
|
25
27
|
} catch (e) {
|
|
@@ -39,6 +41,10 @@ export class UnitSDK {
|
|
|
39
41
|
return this.theme;
|
|
40
42
|
};
|
|
41
43
|
|
|
44
|
+
public static getLanguage = () => {
|
|
45
|
+
return this.language;
|
|
46
|
+
};
|
|
47
|
+
|
|
42
48
|
public static getSignedNonce = () => {
|
|
43
49
|
return this.signedNonce;
|
|
44
50
|
};
|
|
@@ -20,6 +20,7 @@ export interface WebComponentProps {
|
|
|
20
20
|
presentationMode?: PresentationMode,
|
|
21
21
|
params?: string;
|
|
22
22
|
theme?: string;
|
|
23
|
+
language?: string;
|
|
23
24
|
onMessage?: (message: WebViewMessage) => void;
|
|
24
25
|
script?: string;
|
|
25
26
|
isScrollable?: boolean,
|
|
@@ -43,6 +44,7 @@ export const WebComponent = React.forwardRef<WebView, WebComponentProps>(functio
|
|
|
43
44
|
const [unitScript, setUnitScript] = useState<string | undefined>(globalUnitScript);
|
|
44
45
|
const [sourceHtml, setSourceHtml] = useState<string | null>(null);
|
|
45
46
|
const [componentCurrentTheme, setComponentCurrentTheme] = useState<string | undefined>(props.theme ?? UnitSDK.getTheme());
|
|
47
|
+
const [componentCurrentLanguage, setComponentCurrentLanguage] = useState<string | undefined>(props.language ?? UnitSDK.getLanguage());
|
|
46
48
|
const [baseName, setBaseName] = useState<string>();
|
|
47
49
|
const width = props.width ?? '100%';
|
|
48
50
|
|
|
@@ -52,6 +54,7 @@ export const WebComponent = React.forwardRef<WebView, WebComponentProps>(functio
|
|
|
52
54
|
|
|
53
55
|
const updateInitializedParams = () => {
|
|
54
56
|
setComponentCurrentTheme(props.theme ?? UnitSDK.getTheme());
|
|
57
|
+
setComponentCurrentLanguage(props.language ?? UnitSDK.getLanguage());
|
|
55
58
|
};
|
|
56
59
|
|
|
57
60
|
useListenerToBus({ busEventKey: SDKMessage.IS_SCRIPT_FETCHED, action: updateUnitScript });
|
|
@@ -83,11 +86,14 @@ export const WebComponent = React.forwardRef<WebView, WebComponentProps>(functio
|
|
|
83
86
|
return;
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
const
|
|
89
|
+
const themeParam = componentCurrentTheme ? ` theme="${componentCurrentTheme}"` : '';
|
|
90
|
+
const languageParam = componentCurrentLanguage ? ` language="${componentCurrentLanguage}"` : '';
|
|
91
|
+
|
|
92
|
+
const componentParams = (props.params || '') + themeParam + languageParam;
|
|
87
93
|
let newHtml = html.replace(HTML_PLACEHOLDER.BODY, getHtmlBody(props.type.valueOf(), componentParams, props.presentationMode));
|
|
88
94
|
newHtml = newHtml.replace(HTML_PLACEHOLDER.SCRIPT_FROM_NATIVE, props.script || '');
|
|
89
95
|
setSourceHtml(newHtml);
|
|
90
|
-
}, [props.params, unitScript, props.presentationMode, componentCurrentTheme, props.script]);
|
|
96
|
+
}, [props.params, unitScript, props.presentationMode, componentCurrentTheme, componentCurrentLanguage, props.script]);
|
|
91
97
|
|
|
92
98
|
const onMessage = (e: WebViewMessageEvent) => {
|
|
93
99
|
const message = JSON.parse(e.nativeEvent.data) as WebViewMessage;
|
|
@@ -133,7 +139,7 @@ export const WebComponent = React.forwardRef<WebView, WebComponentProps>(functio
|
|
|
133
139
|
onScroll={_onScroll}
|
|
134
140
|
overScrollMode="never"
|
|
135
141
|
injectedJavaScript={unitScript}
|
|
136
|
-
style={{ width: width, flex: 1, opacity: 0.99}}
|
|
142
|
+
style={{ width: width, flex: 1, opacity: 0.99, backgroundColor: "transparent" }}
|
|
137
143
|
source={{ html: sourceHtml, baseUrl: `https://${baseName}` }}
|
|
138
144
|
onMessage={onMessage}
|
|
139
145
|
androidHardwareAccelerationDisabled
|
|
Binary file
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
-
<plist version="1.0">
|
|
4
|
-
<dict>
|
|
5
|
-
<key>SchemeUserState</key>
|
|
6
|
-
<dict>
|
|
7
|
-
<key>UnitReactNativeComponents.xcscheme_^#shared#^_</key>
|
|
8
|
-
<dict>
|
|
9
|
-
<key>orderHint</key>
|
|
10
|
-
<integer>0</integer>
|
|
11
|
-
</dict>
|
|
12
|
-
</dict>
|
|
13
|
-
</dict>
|
|
14
|
-
</plist>
|