Skip to content

Commit acf7f87

Browse files
updated the changelog and improved the abstraction for fetching widget urls
1 parent 3443209 commit acf7f87

3 files changed

Lines changed: 26 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919

2020
- Custom onLoadUrlInBrowser and onLoadUrlInBrowserError props
2121
- uiMessageWebviewUrlScheme is no longer supported. The default scheme of the mx widgets will be used which is "mx". clientRedirectUrl has been the recommended method for redirecting from oauth for [years](https://docs.mx.com/release-notes/2022/#february)
22+
- The proxy property has been removed from all widgets. Before a widget is rendered a widget url should be fetched and then provided to the widget.
2223

2324
### Changed
2425

example/src/app/connect.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SafeAreaView } from "react-native-safe-area-context"
44
import * as Linking from "expo-linking"
55

66
import { ConnectWidget } from "@mxenabled/react-native-widget-sdk"
7-
import { fetchWidgetUrl } from "../shared/api"
7+
import { fetchConnectWidgetUrl } from "../shared/api"
88

99
const styles = StyleSheet.create({
1010
page: {
@@ -19,7 +19,7 @@ export default function Connect() {
1919
const [url, setUrl] = useState<string | null>(null)
2020

2121
useEffect(() => {
22-
fetchWidgetUrl({ clientRedirectUrl, widgetType: "connect_widget" }).then((url) => {
22+
fetchConnectWidgetUrl(clientRedirectUrl).then((url) => {
2323
setUrl(url)
2424
})
2525
}, [clientRedirectUrl])

example/src/shared/api.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,21 @@ import { Platform } from "react-native"
33
const baseUrl = Platform.OS === "android" ? "http://10.0.2.2:8089" : "http://localhost:8089"
44
const proxyUrl = `${baseUrl}/user/widget_urls`
55

6-
interface FetchWidgetUrlProps {
7-
clientRedirectUrl: string
8-
widgetType: string
9-
}
10-
11-
export function buildWidgetConfiguration({ clientRedirectUrl, widgetType }: FetchWidgetUrlProps) {
12-
return {
13-
...(widgetType === "connect_widget"
14-
? { data_request: { products: ["identity_verification"] } }
15-
: {}),
16-
client_redirect_url: clientRedirectUrl,
17-
is_mobile_webview: true,
18-
ui_message_version: 4,
19-
widget_type: widgetType,
20-
}
21-
}
22-
236
interface WidgetUrlResponse {
247
widget_url: {
258
url: string
269
}
2710
}
2811

29-
export const fetchWidgetUrl = async (props: FetchWidgetUrlProps) => {
12+
const fetchWidgetUrl = async (widgetConfiguration: object) => {
3013
const headers: Record<string, string> = {
3114
"Accept-Version": "v20250224",
3215
"Content-Type": "application/json",
3316
}
3417

3518
const method = "POST"
3619
const body = JSON.stringify({
37-
widget_url: buildWidgetConfiguration(props),
20+
widget_url: widgetConfiguration,
3821
})
3922

4023
try {
@@ -56,3 +39,24 @@ export const fetchWidgetUrl = async (props: FetchWidgetUrlProps) => {
5639
throw error
5740
}
5841
}
42+
43+
const createWidgetConfiguration = (overrides: Record<string, any>) => {
44+
const baseWidgetConfiguration = {
45+
is_mobile_webview: true,
46+
ui_message_version: 4,
47+
}
48+
49+
return {
50+
...baseWidgetConfiguration,
51+
...overrides,
52+
}
53+
}
54+
55+
export const fetchConnectWidgetUrl = async (clientRedirectUrl: string) => {
56+
const widgetConfiguration = createWidgetConfiguration({
57+
client_redirect_url: clientRedirectUrl,
58+
widget_type: "connect_widget",
59+
})
60+
61+
return fetchWidgetUrl(widgetConfiguration)
62+
}

0 commit comments

Comments
 (0)