react-native-unit-components 1.3.0 → 1.4.0
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 +0 -375
- package/ios/Camera/Camera.swift +22 -0
- package/ios/Camera/CameraExportModule.m +7 -0
- package/ios/UNAppInfo/UNAppInfo.swift +19 -0
- package/ios/UNAppInfo/UNAppInfoExportModule.m +7 -0
- package/ios/UnitReactNativeComponentsViewManager.swift +7 -7
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.js +3 -0
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.js.map +1 -1
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.utils.js +7 -1
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.js +8 -0
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.js.map +1 -1
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.utils.js +6 -1
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.js.map +1 -1
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.js +4 -0
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.js.map +1 -1
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.js.map +1 -1
- package/lib/commonjs/components/UNCheckDepositComponent/UNCheckDepositComponent.js +97 -0
- package/lib/commonjs/components/UNCheckDepositComponent/UNCheckDepositComponent.js.map +1 -0
- package/lib/commonjs/components/UNCheckDepositComponent/UNCheckDepositComponent.utils.js +45 -0
- package/lib/commonjs/components/UNCheckDepositComponent/UNCheckDepositComponent.utils.js.map +1 -0
- package/lib/commonjs/components/index.js +11 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/hooks/listenerToBus.js +4 -1
- package/lib/commonjs/hooks/listenerToBus.js.map +1 -1
- package/lib/commonjs/messages/webMessages/activityMessage.js +12 -0
- package/lib/commonjs/messages/webMessages/activityMessage.js.map +1 -0
- package/lib/commonjs/messages/webMessages/checkMessage.js +13 -0
- package/lib/commonjs/messages/webMessages/checkMessage.js.map +1 -0
- package/lib/commonjs/messages/webMessages/index.js.map +1 -1
- package/lib/commonjs/scripts/html/bodyScript.js +20 -1
- package/lib/commonjs/scripts/html/bodyScript.js.map +1 -1
- package/lib/commonjs/sharedTypes/account.types.js +8 -1
- package/lib/commonjs/sharedTypes/account.types.js.map +1 -1
- package/lib/commonjs/sharedTypes/checkDeposit.types.js +22 -0
- package/lib/commonjs/sharedTypes/checkDeposit.types.js.map +1 -0
- package/lib/commonjs/sharedTypes/index.js +11 -0
- package/lib/commonjs/sharedTypes/index.js.map +1 -1
- package/lib/commonjs/webComponent/WebComponent.js +33 -1
- package/lib/commonjs/webComponent/WebComponent.js.map +1 -1
- package/lib/commonjs/webComponent/html.js +8 -1
- package/lib/commonjs/webComponent/html.js.map +1 -1
- package/lib/module/components/UNAccountComponent/UNAccountComponent.js +4 -1
- package/lib/module/components/UNAccountComponent/UNAccountComponent.js.map +1 -1
- package/lib/module/components/UNAccountComponent/UNAccountComponent.utils.js +5 -0
- package/lib/module/components/UNAccountComponent/UNAccountComponent.utils.js.map +1 -1
- package/lib/module/components/UNActivityComponent/UNActivityComponent.js +9 -1
- package/lib/module/components/UNActivityComponent/UNActivityComponent.js.map +1 -1
- package/lib/module/components/UNActivityComponent/UNActivityComponent.utils.js +4 -0
- package/lib/module/components/UNActivityComponent/UNActivityComponent.utils.js.map +1 -1
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.js.map +1 -1
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.js +4 -0
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.js.map +1 -1
- package/lib/module/components/UNCardComponent/UNCardComponent.js.map +1 -1
- package/lib/module/components/UNCheckDepositComponent/UNCheckDepositComponent.js +88 -0
- package/lib/module/components/UNCheckDepositComponent/UNCheckDepositComponent.js.map +1 -0
- package/lib/module/components/UNCheckDepositComponent/UNCheckDepositComponent.utils.js +37 -0
- package/lib/module/components/UNCheckDepositComponent/UNCheckDepositComponent.utils.js.map +1 -0
- package/lib/module/components/index.js +1 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/hooks/listenerToBus.js +4 -1
- package/lib/module/hooks/listenerToBus.js.map +1 -1
- package/lib/module/messages/webMessages/activityMessage.js +5 -0
- package/lib/module/messages/webMessages/activityMessage.js.map +1 -0
- package/lib/module/messages/webMessages/checkMessage.js +6 -0
- package/lib/module/messages/webMessages/checkMessage.js.map +1 -0
- package/lib/module/messages/webMessages/index.js.map +1 -1
- package/lib/module/scripts/html/bodyScript.js +17 -0
- package/lib/module/scripts/html/bodyScript.js.map +1 -1
- package/lib/module/sharedTypes/account.types.js +6 -0
- package/lib/module/sharedTypes/account.types.js.map +1 -1
- package/lib/module/sharedTypes/checkDeposit.types.js +15 -0
- package/lib/module/sharedTypes/checkDeposit.types.js.map +1 -0
- package/lib/module/sharedTypes/index.js +1 -0
- package/lib/module/sharedTypes/index.js.map +1 -1
- package/lib/module/webComponent/WebComponent.js +32 -1
- package/lib/module/webComponent/WebComponent.js.map +1 -1
- package/lib/module/webComponent/html.js +9 -2
- package/lib/module/webComponent/html.js.map +1 -1
- package/lib/typescript/components/UNAccountComponent/UNAccountComponent.d.ts +4 -0
- package/lib/typescript/components/UNAccountComponent/UNAccountComponent.utils.d.ts +2 -0
- package/lib/typescript/components/UNActivityComponent/UNActivityComponent.d.ts +2 -1
- package/lib/typescript/components/UNActivityComponent/UNActivityComponent.utils.d.ts +1 -0
- package/lib/typescript/components/UNCheckDepositComponent/UNCheckDepositComponent.d.ts +12 -0
- package/lib/typescript/components/UNCheckDepositComponent/UNCheckDepositComponent.utils.d.ts +3 -0
- package/lib/typescript/components/index.d.ts +1 -0
- package/lib/typescript/messages/webMessages/activityMessage.d.ts +5 -0
- package/lib/typescript/messages/webMessages/checkMessage.d.ts +8 -0
- package/lib/typescript/messages/webMessages/index.d.ts +4 -2
- package/lib/typescript/scripts/html/bodyScript.d.ts +3 -0
- package/lib/typescript/sharedTypes/account.types.d.ts +5 -0
- package/lib/typescript/sharedTypes/checkDeposit.types.d.ts +46 -0
- package/lib/typescript/sharedTypes/index.d.ts +1 -0
- package/lib/typescript/webComponent/WebComponent.d.ts +1 -0
- package/package.json +3 -3
- package/src/components/UNAccountComponent/UNAccountComponent.tsx +13 -1
- package/src/components/UNAccountComponent/UNAccountComponent.utils.ts +7 -0
- package/src/components/UNActivityComponent/UNActivityComponent.tsx +14 -2
- package/src/components/UNActivityComponent/UNActivityComponent.utils.ts +5 -0
- package/src/components/UNBookPaymentComponent/UNBookPaymentComponent.tsx +1 -0
- package/src/components/UNBottomSheetComponent/UNBottomSheetComponent.tsx +4 -0
- package/src/components/UNCardComponent/UNCardComponent.tsx +2 -0
- package/src/components/UNCheckDepositComponent/UNCheckDepositComponent.tsx +112 -0
- package/src/components/UNCheckDepositComponent/UNCheckDepositComponent.utils.ts +40 -0
- package/src/components/index.ts +1 -0
- package/src/hooks/listenerToBus.ts +4 -1
- package/src/messages/webMessages/activityMessage.ts +8 -0
- package/src/messages/webMessages/checkMessage.ts +14 -0
- package/src/messages/webMessages/index.ts +6 -0
- package/src/scripts/html/bodyScript.ts +20 -1
- package/src/sharedTypes/account.types.ts +13 -7
- package/src/sharedTypes/checkDeposit.types.ts +50 -0
- package/src/sharedTypes/index.ts +1 -0
- package/src/webComponent/WebComponent.tsx +33 -1
- package/src/webComponent/html.ts +9 -2
|
@@ -7,20 +7,27 @@ import { HeightEvent, PageMessage } from '../../messages/webMessages/pageMessage
|
|
|
7
7
|
import { PresentationMode } from '../../scripts/html/bodyHtml';
|
|
8
8
|
import type { UNError, UNOnLoadResponse, UNOnLoadResponseData } from '../../sharedTypes';
|
|
9
9
|
import { WebComponent, WebComponentType } from '../../webComponent/WebComponent';
|
|
10
|
-
import { getActivityParams, getActivityScript, injectRefreshEventIfNeeded } from './UNActivityComponent.utils';
|
|
10
|
+
import { getActivityParams, getActivityScript, injectFiltersChanged, injectRefreshEventIfNeeded } from './UNActivityComponent.utils';
|
|
11
11
|
import type WebView from 'react-native-webview';
|
|
12
12
|
import type { BottomSheetSlotData } from '../UNBottomSheetComponent/UNBottomSheetComponent';
|
|
13
13
|
import EventBus from '../../helpers/EventBus';
|
|
14
14
|
import type { UNActivityOnLoadData } from '../../sharedTypes/activity.types';
|
|
15
15
|
import { RESPONSE_KEYS, UnitOnLoadResponseEvent } from '../../messages/webMessages/onLoadMessage';
|
|
16
|
+
import { ActivityMessage } from '../../messages/webMessages/activityMessage';
|
|
16
17
|
|
|
17
18
|
const DEFAULT_HEIGHT = Dimensions.get('window').height * 0.5;
|
|
18
19
|
export interface UNActivityComponentProps {
|
|
20
|
+
// inputs
|
|
19
21
|
accountId: string;
|
|
20
22
|
customerToken: string;
|
|
23
|
+
queryFilter?: string
|
|
24
|
+
|
|
25
|
+
// ui
|
|
21
26
|
theme?: string;
|
|
27
|
+
hideFilterButton?: boolean;
|
|
28
|
+
|
|
29
|
+
// event
|
|
22
30
|
onLoad?: (response: UNOnLoadResponse<UNActivityOnLoadData>) => void;
|
|
23
|
-
queryFilter?: string
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
export const UNActivityComponent = (props: UNActivityComponentProps) => {
|
|
@@ -31,7 +38,12 @@ export const UNActivityComponent = (props: UNActivityComponentProps) => {
|
|
|
31
38
|
injectRefreshEventIfNeeded(webRef.current, data);
|
|
32
39
|
};
|
|
33
40
|
|
|
41
|
+
const dispatchActivityFiltersChanged = (query: string) => {
|
|
42
|
+
injectFiltersChanged(webRef.current, query);
|
|
43
|
+
};
|
|
44
|
+
|
|
34
45
|
useListenerToBus({ busEventKey: UnitMessage.UNIT_REQUEST_REFRESH, action: requestRefresh });
|
|
46
|
+
useListenerToBus({ busEventKey: ActivityMessage.UNIT_ACTIVITY_FILTERS_CHANGED, action: dispatchActivityFiltersChanged});
|
|
35
47
|
|
|
36
48
|
const handleUnitOnLoad = (response: UnitOnLoadResponseEvent) => {
|
|
37
49
|
if (!props.onLoad) {
|
|
@@ -9,6 +9,7 @@ export const getActivityParams = (props: UNActivityComponentProps) => {
|
|
|
9
9
|
return `
|
|
10
10
|
account-id="${props.accountId}"
|
|
11
11
|
customer-token="${props.customerToken}"
|
|
12
|
+
hide-filter-button="${props.hideFilterButton || false}"
|
|
12
13
|
${queryFilterParam}
|
|
13
14
|
style="height: 100%"
|
|
14
15
|
`;
|
|
@@ -23,3 +24,7 @@ export const injectRefreshEventIfNeeded = (currentWeb: WebView | null, requestRe
|
|
|
23
24
|
currentWeb?.injectJavaScript(`dispatchRefreshEvent('${JSON.stringify(requestRefreshEvent)}')`);
|
|
24
25
|
}
|
|
25
26
|
};
|
|
27
|
+
|
|
28
|
+
export const injectFiltersChanged = (currentWeb: WebView | null, query: string) => {
|
|
29
|
+
currentWeb?.injectJavaScript(`dispatchActivityFilterChangedEvent('${query}')`);
|
|
30
|
+
};
|
|
@@ -45,6 +45,7 @@ export const UNBookPaymentComponent = (props: UNBookPaymentComponentProps) => {
|
|
|
45
45
|
console.error('On Load Error: unexpected response type');
|
|
46
46
|
return;
|
|
47
47
|
};
|
|
48
|
+
|
|
48
49
|
const handleWebViewMessage = (message: WebViewMessage) => {
|
|
49
50
|
if (!message || !message.details) return;
|
|
50
51
|
|
|
@@ -24,6 +24,7 @@ import { getAccountActionType } from '../UNAccountComponent/UNAccountComponent.u
|
|
|
24
24
|
import { AccountAction } from '../UNAccountComponent/UNAccountComponent';
|
|
25
25
|
import type { AccountChangedEvent } from '../../messages/webMessages/accountMessage';
|
|
26
26
|
import { AccountMessage } from '../../messages/webMessages/accountMessage';
|
|
27
|
+
import { ActivityFiltersChangedEvent, ActivityMessage } from '../../messages/webMessages/activityMessage';
|
|
27
28
|
|
|
28
29
|
export enum ScrollState {
|
|
29
30
|
/*
|
|
@@ -183,6 +184,9 @@ export const UNBottomSheetComponent = () => {
|
|
|
183
184
|
case AccountMessage.UNIT_ACCOUNT_CHANGED:
|
|
184
185
|
EventBus.Instance.event(AccountMessage.UNIT_ACCOUNT_CHANGED, (message.details as AccountChangedEvent).account);
|
|
185
186
|
break;
|
|
187
|
+
case ActivityMessage.UNIT_ACTIVITY_FILTERS_CHANGED:
|
|
188
|
+
EventBus.Instance.event(ActivityMessage.UNIT_ACTIVITY_FILTERS_CHANGED, (message.details as ActivityFiltersChangedEvent));
|
|
189
|
+
break;
|
|
186
190
|
case UnitMessage.UNIT_REQUEST_CLOSE_FLOW:
|
|
187
191
|
handleCloseFlow();
|
|
188
192
|
break;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { View, NativeModules, Platform } from 'react-native';
|
|
3
|
+
import { WebComponent, WebComponentType } from '../../webComponent/WebComponent';
|
|
4
|
+
import { PresentationMode } from '../../scripts/html/bodyHtml';
|
|
5
|
+
import type { WebViewMessage } from '../../messages/webMessages';
|
|
6
|
+
import { HeightEvent, PageMessage } from '../../messages/webMessages/pageMessage';
|
|
7
|
+
import { UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
8
|
+
import { getCheckDepositParams, getCheckDepositScript } from './UNCheckDepositComponent.utils';
|
|
9
|
+
import { CheckMessage } from '../../messages/webMessages/checkMessage';
|
|
10
|
+
import type { UNCheckDepositData } from '../../sharedTypes/checkDeposit.types';
|
|
11
|
+
import type { UNAccountData, UNError, UNOnLoadResponse, UNOnLoadResponseData } from '../../sharedTypes';
|
|
12
|
+
import { RESPONSE_KEYS, UnitOnLoadResponseEvent } from '../../messages/webMessages/onLoadMessage';
|
|
13
|
+
|
|
14
|
+
const { Camera } = NativeModules;
|
|
15
|
+
|
|
16
|
+
export interface UNCheckDepositComponentProps {
|
|
17
|
+
accountId: string;
|
|
18
|
+
fee: number;
|
|
19
|
+
customerToken: string;
|
|
20
|
+
theme?: string;
|
|
21
|
+
onLoad?: (response: UNOnLoadResponse<UNAccountData>) => void;
|
|
22
|
+
onDepositCreated?: (checkData: UNCheckDepositData) => void
|
|
23
|
+
onRestartRequest?: (checkData: UNCheckDepositData) => void
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const UNCheckDepositComponent = (props: UNCheckDepositComponentProps) => {
|
|
27
|
+
const [height, setHeight] = useState<number>(0);
|
|
28
|
+
const [presentationMode, setPresentationMode] = useState<PresentationMode>(PresentationMode.Inherit);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const requestCameraAccess = async () => {
|
|
32
|
+
try {
|
|
33
|
+
await Camera.requestAccess();
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
} catch (error: any) {
|
|
36
|
+
console.error(error);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
if (Platform.OS == 'ios') {
|
|
41
|
+
requestCameraAccess();
|
|
42
|
+
}
|
|
43
|
+
}, []);
|
|
44
|
+
|
|
45
|
+
const handleUnitOnLoad = (response: UnitOnLoadResponseEvent) => {
|
|
46
|
+
if (!props.onLoad) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (RESPONSE_KEYS.errors in response) {
|
|
51
|
+
props.onLoad(response as UNError);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (RESPONSE_KEYS.account in response) {
|
|
56
|
+
// AccountOnLoadResponse;
|
|
57
|
+
props.onLoad(response[RESPONSE_KEYS.account] as UNOnLoadResponseData<UNAccountData>);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
console.error('On Load Error: unexpected response type');
|
|
62
|
+
return;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const handleWebViewMessage = (message: WebViewMessage) => {
|
|
66
|
+
if (!message || !message.details) return;
|
|
67
|
+
|
|
68
|
+
switch (message.type) {
|
|
69
|
+
case CheckMessage.CHECK_DEPOSIT_CREATED:
|
|
70
|
+
props.onDepositCreated && props.onDepositCreated(message.details as UNCheckDepositData);
|
|
71
|
+
break;
|
|
72
|
+
case CheckMessage.CHECK_DEPOSIT_RESTART_REQUEST:
|
|
73
|
+
props.onRestartRequest && props.onRestartRequest(message.details as UNCheckDepositData);
|
|
74
|
+
break;
|
|
75
|
+
case UnitMessage.UNIT_ON_LOAD:
|
|
76
|
+
handleUnitOnLoad(message.details as UnitOnLoadResponseEvent);
|
|
77
|
+
break;
|
|
78
|
+
case PageMessage.PAGE_HEIGHT: {
|
|
79
|
+
const currentHeight = (message.details as HeightEvent).height;
|
|
80
|
+
setHeight(currentHeight);
|
|
81
|
+
if (presentationMode === PresentationMode.Inherit && currentHeight === 0) {
|
|
82
|
+
setPresentationMode(PresentationMode.Default);
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const renderBookPaymentWebView = () => {
|
|
90
|
+
return (
|
|
91
|
+
<WebComponent
|
|
92
|
+
type={WebComponentType.checkDeposit}
|
|
93
|
+
presentationMode={presentationMode}
|
|
94
|
+
params={getCheckDepositParams(props)}
|
|
95
|
+
script={getCheckDepositScript()}
|
|
96
|
+
onMessage={(message: WebViewMessage) => handleWebViewMessage(message)}
|
|
97
|
+
theme={props.theme}
|
|
98
|
+
isScrollable={true}
|
|
99
|
+
/>
|
|
100
|
+
);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
if (presentationMode === PresentationMode.Inherit) {
|
|
104
|
+
return renderBookPaymentWebView();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<View style={{ height: height }}>
|
|
109
|
+
{renderBookPaymentWebView()}
|
|
110
|
+
</View>
|
|
111
|
+
);
|
|
112
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CheckMessage } from '../../messages/webMessages/checkMessage';
|
|
2
|
+
import type { UNCheckDepositComponentProps } from './UNCheckDepositComponent';
|
|
3
|
+
|
|
4
|
+
export const getCheckDepositParams = (props: UNCheckDepositComponentProps) => {
|
|
5
|
+
return `
|
|
6
|
+
account-id="${props.accountId}"
|
|
7
|
+
fee="${props.fee}"
|
|
8
|
+
customer-token="${props.customerToken}"
|
|
9
|
+
`;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const CHECK_DEPOSIT_LISTENERS = {
|
|
13
|
+
paymentCreated: `
|
|
14
|
+
window.addEventListener("${CheckMessage.CHECK_DEPOSIT_CREATED}", (e) => {
|
|
15
|
+
const response = e.detail
|
|
16
|
+
response.then((data) => {
|
|
17
|
+
postMessageToSDK({ type: "${CheckMessage.CHECK_DEPOSIT_CREATED}", details: data.data })
|
|
18
|
+
}).catch((e) => {
|
|
19
|
+
console.log(e)
|
|
20
|
+
})
|
|
21
|
+
});
|
|
22
|
+
`,
|
|
23
|
+
restartRequest: `
|
|
24
|
+
window.addEventListener("${CheckMessage.CHECK_DEPOSIT_RESTART_REQUEST}", (e) => {
|
|
25
|
+
const response = e.detail
|
|
26
|
+
response.then((data) => {
|
|
27
|
+
postMessageToSDK({ type: "${CheckMessage.CHECK_DEPOSIT_RESTART_REQUEST}", details: data.data })
|
|
28
|
+
}).catch((e) => {
|
|
29
|
+
console.log(e)
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
`
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const getCheckDepositScript = () => {
|
|
36
|
+
return `
|
|
37
|
+
${CHECK_DEPOSIT_LISTENERS.paymentCreated}
|
|
38
|
+
${CHECK_DEPOSIT_LISTENERS.restartRequest}
|
|
39
|
+
`;
|
|
40
|
+
};
|
package/src/components/index.ts
CHANGED
|
@@ -3,5 +3,6 @@ export * from './UNBottomSheetComponent/UNBottomSheetComponent';
|
|
|
3
3
|
export * from './UNBookPaymentComponent/UNBookPaymentComponent';
|
|
4
4
|
export * from './UNActivityComponent/UNActivityComponent';
|
|
5
5
|
export * from './UNAccountComponent/UNAccountComponent';
|
|
6
|
+
export * from './UNCheckDepositComponent/UNCheckDepositComponent';
|
|
6
7
|
export * from './UNACHDebitComponent/UNACHDebitComponent';
|
|
7
8
|
export * from './UNACHCreditComponent/UNACHCreditComponent';
|
|
@@ -23,6 +23,9 @@ export const useListenerToBus = (listener: Listener) => {
|
|
|
23
23
|
|
|
24
24
|
// Call to action when event is changed. (To be updated with the current props).
|
|
25
25
|
useEffect(() => {
|
|
26
|
-
eventData
|
|
26
|
+
if (eventData == null || eventData == undefined) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
listener.action(eventData);
|
|
27
30
|
}, [eventData]);
|
|
28
31
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { UNCheckDepositData } from '../../sharedTypes/checkDeposit.types';
|
|
2
|
+
|
|
3
|
+
export enum CheckMessage {
|
|
4
|
+
// check deposit
|
|
5
|
+
CHECK_DEPOSIT_CREATED = 'unitCheckDepositCreated',
|
|
6
|
+
CHECK_DEPOSIT_RESTART_REQUEST = 'unitCheckDepositRestartRequest'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type CheckDepositCreatedEvent = UNCheckDepositData
|
|
10
|
+
export type CheckDepositRestartRequestEvent = UNCheckDepositData
|
|
11
|
+
|
|
12
|
+
export type CheckEvent =
|
|
13
|
+
| CheckDepositCreatedEvent
|
|
14
|
+
| CheckDepositRestartRequestEvent
|
|
@@ -6,6 +6,8 @@ import type { PageEvent, PageMessage } from './pageMessage';
|
|
|
6
6
|
import type { PaymentMessage } from './paymentsMessage';
|
|
7
7
|
import type { UnitEvent, UnitMessage } from './unitMessages';
|
|
8
8
|
import type { AccountEvent, AccountMessage } from './accountMessage';
|
|
9
|
+
import type { CheckEvent, CheckMessage } from './checkMessage';
|
|
10
|
+
import type { ActivityEvent, ActivityMessage } from './activityMessage';
|
|
9
11
|
|
|
10
12
|
export type WebViewMessageType =
|
|
11
13
|
| PageMessage
|
|
@@ -13,6 +15,8 @@ export type WebViewMessageType =
|
|
|
13
15
|
| UnitMessage
|
|
14
16
|
| PaymentMessage
|
|
15
17
|
| AccountMessage
|
|
18
|
+
| CheckMessage
|
|
19
|
+
| ActivityMessage
|
|
16
20
|
|
|
17
21
|
type WebViewEvent =
|
|
18
22
|
| PageEvent
|
|
@@ -22,6 +26,8 @@ type WebViewEvent =
|
|
|
22
26
|
| PaymentMessage
|
|
23
27
|
| ACHEvent
|
|
24
28
|
| AccountEvent
|
|
29
|
+
| CheckEvent
|
|
30
|
+
| ActivityEvent
|
|
25
31
|
|
|
26
32
|
export interface WebViewMessage {
|
|
27
33
|
type: WebViewMessageType,
|
|
@@ -3,6 +3,7 @@ import { CardMessage } from '../../messages/webMessages/cardMessage';
|
|
|
3
3
|
import { PageMessage } from '../../messages/webMessages/pageMessage';
|
|
4
4
|
import { UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
5
5
|
import { AccountMessage } from '../../messages/webMessages/accountMessage';
|
|
6
|
+
import { ActivityMessage } from '../../messages/webMessages/activityMessage';
|
|
6
7
|
|
|
7
8
|
export const POST_MESSAGE_TO_SDK = `
|
|
8
9
|
const postMessageToSDK = (message) => {
|
|
@@ -84,7 +85,7 @@ export const LISTENERS = {
|
|
|
84
85
|
postMessageToSDK({ type: "${UnitMessage.UNIT_REQUEST_EXTERNAL_SDK}", details: e.detail })
|
|
85
86
|
});
|
|
86
87
|
`,
|
|
87
|
-
unitPaymentCreated
|
|
88
|
+
unitPaymentCreated: `
|
|
88
89
|
window.addEventListener("${PaymentMessage.PAYMENT_CREATED}", (e) => {
|
|
89
90
|
const response = e.detail
|
|
90
91
|
response.then((data) => {
|
|
@@ -104,6 +105,11 @@ export const LISTENERS = {
|
|
|
104
105
|
})
|
|
105
106
|
});
|
|
106
107
|
`,
|
|
108
|
+
unitActivityFiltersChanged: `
|
|
109
|
+
window.addEventListener("${ActivityMessage.UNIT_ACTIVITY_FILTERS_CHANGED}", (e) => {
|
|
110
|
+
postMessageToSDK({ type: "${ActivityMessage.UNIT_ACTIVITY_FILTERS_CHANGED}", details: e.detail })
|
|
111
|
+
});
|
|
112
|
+
`
|
|
107
113
|
};
|
|
108
114
|
|
|
109
115
|
export const DISPATCH_RENDERING_EVENT = `
|
|
@@ -120,6 +126,13 @@ export const DISPATCH_REQUEST_REFRESH = `
|
|
|
120
126
|
}
|
|
121
127
|
`;
|
|
122
128
|
|
|
129
|
+
export const DISPATCH_ACTIVITY_FILTER_CHANGED_EVENT = `
|
|
130
|
+
const dispatchActivityFilterChangedEvent = (details) => {
|
|
131
|
+
const event = new CustomEvent("${ActivityMessage.UNIT_ACTIVITY_FILTERS_CHANGED}",{ detail: details });
|
|
132
|
+
window.dispatchEvent(event);
|
|
133
|
+
}
|
|
134
|
+
`;
|
|
135
|
+
|
|
123
136
|
export const DISPATCH_PLAID_RESPONSE = `
|
|
124
137
|
const dispatchPlaidEvent = (details) => {
|
|
125
138
|
const event = new CustomEvent("${UnitMessage.UNIT_PLAID_RESPONSE}",{ detail: details })
|
|
@@ -138,3 +151,9 @@ export const DISPATCH_REQUEST_CARD_ACTION = `
|
|
|
138
151
|
document.querySelector("unit-elements-card").dispatchEvent(new CustomEvent("unitRequestCardAction", {detail: {action: action}}))
|
|
139
152
|
}
|
|
140
153
|
`;
|
|
154
|
+
|
|
155
|
+
export const DISPATCH_REQUEST_ACCOUNT_ACTION = `
|
|
156
|
+
const dispatchRequestAccountAction = (action) => {
|
|
157
|
+
document.querySelector("unit-elements-account").dispatchEvent(new CustomEvent("unitRequestAccountAction", {detail: {action: action}}))
|
|
158
|
+
}
|
|
159
|
+
`;
|
|
@@ -3,11 +3,11 @@ import type { UNRelationship, UNTags } from './types';
|
|
|
3
3
|
export type UNAccountData = UNDepositAccount | UNBatchAccount | UNCreditAccount
|
|
4
4
|
|
|
5
5
|
export type UNCounterpartyAccountData = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
id: string
|
|
7
|
+
attributes: {
|
|
8
|
+
name: string
|
|
9
|
+
tags?: { [key: string]: string }
|
|
10
|
+
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
enum UNAccountStatus {
|
|
@@ -90,7 +90,7 @@ export type UNBatchAccount = {
|
|
|
90
90
|
fraudReason?: UNFraudReason
|
|
91
91
|
closeReasonText?: string
|
|
92
92
|
freezeReason?: string
|
|
93
|
-
tags?: {[key: string]: string}
|
|
93
|
+
tags?: { [key: string]: string }
|
|
94
94
|
}
|
|
95
95
|
relationships: {
|
|
96
96
|
org: UNRelationship
|
|
@@ -111,7 +111,7 @@ export type UNCreditAccount = {
|
|
|
111
111
|
available: number
|
|
112
112
|
creditLimit: number
|
|
113
113
|
currency: string
|
|
114
|
-
tags: {[key: string]: string}
|
|
114
|
+
tags: { [key: string]: string }
|
|
115
115
|
status: UNAccountStatus
|
|
116
116
|
closeReason?: UNCloseReason
|
|
117
117
|
fraudReason?: UNFraudReason
|
|
@@ -123,3 +123,9 @@ export type UNCreditAccount = {
|
|
|
123
123
|
org: UNRelationship
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
+
|
|
127
|
+
export enum UNAccountMenuAction {
|
|
128
|
+
OpenAccountDetails = 'OpenAccountDetails',
|
|
129
|
+
OpenAccountStatements = 'OpenAccountStatements',
|
|
130
|
+
DownloadBankVerificationLetter = 'DownloadBankVerificationLetter',
|
|
131
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { UNRelationship } from './types';
|
|
2
|
+
|
|
3
|
+
export type UNCheckDepositData = {
|
|
4
|
+
id: string
|
|
5
|
+
type: string
|
|
6
|
+
attributes: UNCheckDepositAttributes
|
|
7
|
+
relationships: UNCheckDepositRelationships
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type UNCheckDepositAttributes = {
|
|
11
|
+
createdAt: Date
|
|
12
|
+
status: keyof typeof UNCheckDepositStatus
|
|
13
|
+
reason?: string
|
|
14
|
+
description: string
|
|
15
|
+
amount: Cents
|
|
16
|
+
checkNumber?: string
|
|
17
|
+
counterparty: UNCheckCounterparty
|
|
18
|
+
settlementDate?: Date
|
|
19
|
+
tags?: {[key: string]: string}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type UNCheckDepositRelationships = {
|
|
23
|
+
account: UNRelationship
|
|
24
|
+
customer?: UNRelationship
|
|
25
|
+
customers?: UNRelationship
|
|
26
|
+
org?: UNRelationship
|
|
27
|
+
transaction?: UNRelationship
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export enum UNCheckDepositStatus {
|
|
31
|
+
AwaitingImages = 'AwaitingImages',
|
|
32
|
+
AwaitingFrontImage = 'AwaitingFrontImage',
|
|
33
|
+
AwaitingBackImage = 'AwaitingBackImage',
|
|
34
|
+
PendingReview = 'PendingReview',
|
|
35
|
+
AwaitingCustomerConfirmation = 'AwaitingCustomerConfirmation',
|
|
36
|
+
Pending = 'Pending',
|
|
37
|
+
Rejected = 'Rejected',
|
|
38
|
+
Clearing = 'Clearing',
|
|
39
|
+
Sent = 'Sent',
|
|
40
|
+
Canceled = 'Canceled',
|
|
41
|
+
Returned = 'Returned',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type Cents = number
|
|
45
|
+
|
|
46
|
+
export type UNCheckCounterparty = {
|
|
47
|
+
name: string
|
|
48
|
+
accountNumber: string
|
|
49
|
+
routingNumber: string
|
|
50
|
+
}
|
package/src/sharedTypes/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import React, { useEffect, useState } from 'react';
|
|
3
|
+
import { NativeModules, Platform } from 'react-native';
|
|
3
4
|
import { WebView, WebViewMessageEvent } from 'react-native-webview';
|
|
4
5
|
import EventBus from '../helpers/EventBus';
|
|
5
6
|
import html, { HTML_PLACEHOLDER } from './html';
|
|
@@ -12,6 +13,8 @@ import type { WebViewMessage } from '../messages/webMessages';
|
|
|
12
13
|
import { SDKMessage, SdkScriptFetched } from '../messages/nativeMessages/sdkMessage';
|
|
13
14
|
import { handleRequestDownload } from './WebComponent.utils';
|
|
14
15
|
|
|
16
|
+
const { UNAppInfo } = NativeModules;
|
|
17
|
+
|
|
15
18
|
export interface WebComponentProps {
|
|
16
19
|
type: WebComponentType;
|
|
17
20
|
presentationMode?: PresentationMode,
|
|
@@ -31,6 +34,7 @@ export enum WebComponentType {
|
|
|
31
34
|
activity = 'unit-elements-activity',
|
|
32
35
|
slot = 'unit-elements-sdk-slot',
|
|
33
36
|
account = 'unit-elements-account',
|
|
37
|
+
checkDeposit = 'unit-elements-check-deposit',
|
|
34
38
|
achDebitPayment = 'unit-elements-ach-debit-payment',
|
|
35
39
|
achCreditPayment = 'unit-elements-ach-credit-payment'
|
|
36
40
|
}
|
|
@@ -39,6 +43,7 @@ export const WebComponent = React.forwardRef<WebView, WebComponentProps>(functio
|
|
|
39
43
|
const [unitScript, setUnitScript] = useState<string | undefined>(globalUnitScript);
|
|
40
44
|
const [sourceHtml, setSourceHtml] = useState<string | null>(null);
|
|
41
45
|
const [componentCurrentTheme, setComponentCurrentTheme] = useState<string | undefined>(props.theme ?? UnitSDK.getTheme());
|
|
46
|
+
const [baseName, setBaseName] = useState<string>();
|
|
42
47
|
const width = props.width ?? '100%';
|
|
43
48
|
|
|
44
49
|
const updateUnitScript = (data: SdkScriptFetched) => {
|
|
@@ -52,6 +57,26 @@ export const WebComponent = React.forwardRef<WebView, WebComponentProps>(functio
|
|
|
52
57
|
useListenerToBus({ busEventKey: SDKMessage.IS_SCRIPT_FETCHED, action: updateUnitScript });
|
|
53
58
|
useListenerToBus({ busEventKey: SDKMessage.IS_SDK_INITIALIZED, action: updateInitializedParams });
|
|
54
59
|
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
|
|
62
|
+
const getAppName = async () => {
|
|
63
|
+
// For iOS, we extend the app name from the HTML to display a prettier access request message.
|
|
64
|
+
// On Android, there is no request message sent from HTML.
|
|
65
|
+
try {
|
|
66
|
+
if (Platform.OS == 'ios') {
|
|
67
|
+
const name = await UNAppInfo.getBundleName();
|
|
68
|
+
setBaseName(name.replace(/ /g, '-'));
|
|
69
|
+
} else { // android
|
|
70
|
+
setBaseName('unit');
|
|
71
|
+
}
|
|
72
|
+
} catch (error: any) {
|
|
73
|
+
console.error(error);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
getAppName();
|
|
78
|
+
}, []);
|
|
79
|
+
|
|
55
80
|
useEffect(() => {
|
|
56
81
|
if (!unitScript) {
|
|
57
82
|
fetchUnitScript();
|
|
@@ -92,9 +117,16 @@ export const WebComponent = React.forwardRef<WebView, WebComponentProps>(functio
|
|
|
92
117
|
return null;
|
|
93
118
|
};
|
|
94
119
|
|
|
120
|
+
if (!baseName) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
95
124
|
return (
|
|
96
125
|
<WebView
|
|
97
126
|
ref={webRef}
|
|
127
|
+
originWhitelist={['*']}
|
|
128
|
+
mediaPlaybackRequiresUserAction={false}
|
|
129
|
+
allowsInlineMediaPlayback={true}
|
|
98
130
|
cacheEnabled={false}
|
|
99
131
|
scrollEnabled={props.isScrollable}
|
|
100
132
|
nestedScrollEnabled={props.nestedScrollEnabled}
|
|
@@ -102,7 +134,7 @@ export const WebComponent = React.forwardRef<WebView, WebComponentProps>(functio
|
|
|
102
134
|
overScrollMode="never"
|
|
103
135
|
injectedJavaScript={unitScript}
|
|
104
136
|
style={{ width: width, flex: 1, opacity: 0.99}}
|
|
105
|
-
source={{ html: sourceHtml }}
|
|
137
|
+
source={{ html: sourceHtml, baseUrl: `https://${baseName}` }}
|
|
106
138
|
onMessage={onMessage}
|
|
107
139
|
androidHardwareAccelerationDisabled
|
|
108
140
|
/>
|
package/src/webComponent/html.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
|
-
import { DISPATCH_RENDERING_EVENT, LISTENERS, POST_MESSAGE_TO_SDK, POST_PAGE_HEIGHT, DISPATCH_REQUEST_CARD_ACTION, DISPATCH_OPEN_ACTIONS_MENU } from '../scripts/html/bodyScript';
|
|
2
|
+
import { DISPATCH_RENDERING_EVENT, LISTENERS, POST_MESSAGE_TO_SDK, POST_PAGE_HEIGHT, DISPATCH_REQUEST_CARD_ACTION, DISPATCH_OPEN_ACTIONS_MENU, DISPATCH_REQUEST_ACCOUNT_ACTION, DISPATCH_ACTIVITY_FILTER_CHANGED_EVENT } from '../scripts/html/bodyScript';
|
|
3
3
|
|
|
4
4
|
export const HTML_PLACEHOLDER = {
|
|
5
5
|
SCRIPT_UNIT: '<SCRIPT_UNIT>',
|
|
@@ -21,7 +21,7 @@ const htmlText = `
|
|
|
21
21
|
}
|
|
22
22
|
</script>
|
|
23
23
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
|
|
24
|
-
</
|
|
24
|
+
</head>
|
|
25
25
|
|
|
26
26
|
<body style="margin: 0;">
|
|
27
27
|
${HTML_PLACEHOLDER.BODY}
|
|
@@ -51,15 +51,22 @@ const htmlText = `
|
|
|
51
51
|
|
|
52
52
|
${LISTENERS.unitAccountChanged}
|
|
53
53
|
|
|
54
|
+
${LISTENERS.unitActivityFiltersChanged}
|
|
55
|
+
|
|
54
56
|
${DISPATCH_RENDERING_EVENT}
|
|
55
57
|
|
|
56
58
|
${DISPATCH_OPEN_ACTIONS_MENU}
|
|
57
59
|
|
|
58
60
|
${DISPATCH_REQUEST_CARD_ACTION}
|
|
59
61
|
|
|
62
|
+
${DISPATCH_ACTIVITY_FILTER_CHANGED_EVENT}
|
|
63
|
+
|
|
64
|
+
${DISPATCH_REQUEST_ACCOUNT_ACTION}
|
|
65
|
+
|
|
60
66
|
${HTML_PLACEHOLDER.SCRIPT_FROM_NATIVE}
|
|
61
67
|
</script>
|
|
62
68
|
</body>
|
|
69
|
+
</html>
|
|
63
70
|
`;
|
|
64
71
|
|
|
65
72
|
export default htmlText;
|