@funkit/connect-rn 1.0.0 → 1.0.3
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 +140 -13
- package/dist/index.js +26 -23
- package/dist/index.js.map +3 -3
- package/dist/src/flow/FunkitFlowProvider.d.ts.map +1 -1
- package/dist/src/providers/FunkitProvider.d.ts.map +1 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -1,24 +1,151 @@
|
|
|
1
|
-
|
|
1
|
+
# @funkit/connect-rn
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React Native bindings for Funkit Connect. **This README is for working _on_ the
|
|
4
|
+
package.** For integrating the SDK into an app (install, peer dependencies,
|
|
5
|
+
`FunkitProvider` API, `DepositFlowConfig`), see the client integration guide —
|
|
6
|
+
maintained in Notion. To run the SDK on a simulator/device, use the
|
|
7
|
+
[`with-expo`](../../apps/with-expo) playground.
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
`
|
|
8
|
-
|
|
9
|
-
[`@funkit/connect`](../connect)
|
|
9
|
+
## Architecture
|
|
10
|
+
|
|
11
|
+
`@funkit/connect-rn` is the React Native half of a three-package split. The
|
|
12
|
+
headless business logic lives once in
|
|
13
|
+
[`@funkit/connect-core`](../connect-core) and is shared by web and RN, so the two
|
|
14
|
+
platforms can't drift:
|
|
15
|
+
|
|
16
|
+
| Package | Role |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| `@funkit/connect-core` | Headless, platform-agnostic — domains, utils, query/Statsig hooks, theme factories, `FunLogger`. **No DOM, vanilla-extract, or wagmi** under `src/**`. |
|
|
19
|
+
| `@funkit/connect` | Web presentation halves (`.tsx`, vanilla-extract, Dialog/portals, iframe transport, wagmi identity). |
|
|
20
|
+
| `@funkit/connect-rn` | **This package** — the RN presentation halves over core. |
|
|
21
|
+
|
|
22
|
+
The platform halves this package supplies (mirroring connect's web halves):
|
|
10
23
|
|
|
11
24
|
- a local Shopify Restyle theme + `useFunkitTheme()` / `useColorScheme()`
|
|
12
25
|
- `FunLogger` wired to a React Native log transport
|
|
13
26
|
- `WebViewSwappedTransport` + the Swapped screen
|
|
14
|
-
- the Transfer / UDA
|
|
27
|
+
- the managed Add money → Transfer / UDA → QR flow
|
|
28
|
+
|
|
29
|
+
Core stays platform-agnostic by depending on **contracts** that each platform
|
|
30
|
+
implements: `IdentityProvider` (web wraps wagmi; RN takes host props),
|
|
31
|
+
`SwappedTransport` (web `<iframe>`; RN `WebView`), and `LogTransport` (web
|
|
32
|
+
Datadog browser-logs; RN console). The customer `theme` is a plain `ThemeVars`
|
|
33
|
+
object from core that RN maps to a Restyle theme via `toRestyleTheme(tokens)`.
|
|
34
|
+
|
|
35
|
+
**Public surface.** `index.ts` re-exports core plus an **explicit, named** set of
|
|
36
|
+
RN symbols (no barrels): the provider, the `useFunkitCheckout` entry hook, theme
|
|
37
|
+
tokens/adapter/primitives, and config types. The screens, Statsig RN bindings,
|
|
38
|
+
log transports, identity context, and transfer hooks are **internal** (mirroring
|
|
39
|
+
`@funkit/connect`, which exports none of them). When adding a public export, wire
|
|
40
|
+
it explicitly in `index.ts`.
|
|
41
|
+
|
|
42
|
+
## Peer dependencies
|
|
43
|
+
|
|
44
|
+
These are declared as **peer dependencies** (not bundled), so the host app links a
|
|
45
|
+
single copy and controls the native-module versions. Editing `peerDependencies`
|
|
46
|
+
in `package.json` is a public-API change — bump it deliberately and add a
|
|
47
|
+
changeset (a *peer* bump is a **major** change for consumers).
|
|
48
|
+
|
|
49
|
+
The authoritative list lives in `package.json` (`peerDependencies` /
|
|
50
|
+
`peerDependenciesMeta`) — it's intentionally **not** duplicated here so it can't
|
|
51
|
+
drift. Adding a peer dependency is a consumer-facing decision: every integrator
|
|
52
|
+
must install it. Before adding one:
|
|
53
|
+
|
|
54
|
+
- **Pick it carefully.** Prefer a widely-used, well-maintained library — ideally
|
|
55
|
+
one (nearly) every customer already depends on — over a niche package that adds
|
|
56
|
+
install burden for everyone. A peer dep is a tax on all consumers.
|
|
57
|
+
- **Update the client docs.** A new peer dep changes the install/setup steps
|
|
58
|
+
integrators follow, so the client integration guide (Notion) must be updated in
|
|
59
|
+
the same change.
|
|
60
|
+
- **Native modules need extra care.** A native peer (iOS/Android native code, vs
|
|
61
|
+
JS-only) can't be linked by the host without a rebuild, carries version
|
|
62
|
+
compatibility constraints against the RN core, and may be absent in some
|
|
63
|
+
runtimes. Treat it as a heavier commitment than a JS-only dep.
|
|
64
|
+
- **Prefer Expo-Go-bundled native modules.** When a native peer is needed, prefer
|
|
65
|
+
one already bundled in Expo Go (see [Expo Go compatibility](#expo-go-compatibility))
|
|
66
|
+
so the SDK keeps working in the playground without a custom dev build. This is a
|
|
67
|
+
preference, not a hard requirement — if a non-bundled native module is genuinely
|
|
68
|
+
needed, make it optional + lazy + guarded with a host override (the way
|
|
69
|
+
clipboard is).
|
|
70
|
+
- **Don't depend on the Expo SDK.** "Bundled in Expo Go" is a convenience for our
|
|
71
|
+
playground, not an assumption about consumers — many integrate via **bare React
|
|
72
|
+
Native**, not Expo. Prefer a framework-agnostic RN library over one that needs the
|
|
73
|
+
Expo SDK (the `expo` package) installed to work, so it runs either way. An
|
|
74
|
+
`expo-*` name isn't itself a red flag — those modules are *published by* Expo but
|
|
75
|
+
run fine in bare RN; the concern is a library that genuinely requires the Expo
|
|
76
|
+
runtime, like `@expo/ui`. For example, `@gorhom/bottom-sheet` is preferred over
|
|
77
|
+
`@expo/ui`'s bottom sheet.
|
|
78
|
+
|
|
79
|
+
## Expo Go compatibility
|
|
80
|
+
|
|
81
|
+
connect-rn is **designed to run in Expo Go** (no custom dev build needed) — this
|
|
82
|
+
is what lets the [`with-expo`](../../apps/with-expo) playground preview the flow
|
|
83
|
+
in Expo Go. **Keep new code Expo-Go-safe.**
|
|
84
|
+
|
|
85
|
+
Every native peer the SDK relies on is either bundled in Expo Go for the target
|
|
86
|
+
SDK (`react-native-reanimated`, `react-native-gesture-handler`,
|
|
87
|
+
`react-native-webview`, `react-native-svg`, `react-native-safe-area-context`,
|
|
88
|
+
AsyncStorage) or JS-only (`@gorhom/bottom-sheet`, `react-native-qrcode-svg`).
|
|
89
|
+
Two deliberate choices keep it that way:
|
|
90
|
+
|
|
91
|
+
- **Clipboard is optional, lazy, and guarded.** `@react-native-clipboard/clipboard`
|
|
92
|
+
is a bare-RN native module *not* in Expo Go. `src/transfer/clipboard.ts` only
|
|
93
|
+
`import()`s it **when a copy actually happens** (never at startup) inside a
|
|
94
|
+
try/catch — so in Expo Go, where `getEnforcing('RNCClipboard')` would throw, a
|
|
95
|
+
copy degrades to a no-op + warning rather than crashing. A host injects its own
|
|
96
|
+
writer via `FunkitProvider`'s `copyToClipboard` (e.g. `expo-clipboard`), and
|
|
97
|
+
that override runs instead, so the throwing path never executes.
|
|
98
|
+
- **No `react-native-device-info`.** `src/statsig/statsigMetadata.ts` vendors the
|
|
99
|
+
Statsig metadata adapter with the `react-native-device-info` dependency removed
|
|
100
|
+
(it's a native module that needs a dev build). The app-version / device-model
|
|
101
|
+
fields are left `undefined`; `systemName` and `locale` are read from RN's
|
|
102
|
+
built-in `Platform` / `NativeModules` (no extra native dep). Geo/IP resolution
|
|
103
|
+
uses plain `fetch`.
|
|
104
|
+
|
|
105
|
+
**Contributor rule:** don't add a hard top-level import of a bare-RN native
|
|
106
|
+
module that Expo Go doesn't bundle. If you genuinely need one, make it optional +
|
|
107
|
+
lazily imported + guarded with a host-injectable override, the way clipboard is.
|
|
108
|
+
|
|
109
|
+
## Local development
|
|
110
|
+
|
|
111
|
+
> No root shortcut exists for this package — use the `pnpm --filter` form (or
|
|
112
|
+
> `cd packages/connect-rn` and drop the filter).
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
pnpm --filter @funkit/connect-rn build # esbuild bundle + typecheck
|
|
116
|
+
pnpm --filter @funkit/connect-rn build:watch # rebuild on change
|
|
117
|
+
pnpm --filter @funkit/connect-rn dev # build:watch + type-gen watch in parallel
|
|
118
|
+
pnpm --filter @funkit/connect-rn typecheck # tsc --noEmit
|
|
119
|
+
pnpm --filter @funkit/connect-rn lint # oxlint (lint:fix to auto-fix)
|
|
120
|
+
pnpm --filter @funkit/connect-rn storybook # web Storybook on http://localhost:7007
|
|
121
|
+
```
|
|
15
122
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
123
|
+
Typical inner loop when changing the SDK and watching it in the app: run
|
|
124
|
+
`pnpm --filter @funkit/connect-rn dev` in one terminal and
|
|
125
|
+
`pnpm --filter with-expo start` in another. Metro watches the whole monorepo, so
|
|
126
|
+
SDK edits hot-reload in the playground.
|
|
127
|
+
|
|
128
|
+
## Testing
|
|
129
|
+
|
|
130
|
+
Tests run with **Vitest** in the **`node`** environment (no DOM — native modules
|
|
131
|
+
are stubbed). Components mount with `react-test-renderer` + `act()`, not React
|
|
132
|
+
Testing Library.
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
pnpm --filter @funkit/connect-rn test # run once
|
|
136
|
+
pnpm --filter @funkit/connect-rn test -- --watch # watch mode
|
|
137
|
+
pnpm --filter @funkit/connect-rn test -- test/providers/FunkitProvider.test.tsx # one file
|
|
138
|
+
```
|
|
20
139
|
|
|
21
|
-
|
|
140
|
+
- Config: `vitest.config.ts`. Setup: `test/setup.ts` (stubs global `fetch`,
|
|
141
|
+
enables `IS_REACT_ACT_ENVIRONMENT`).
|
|
142
|
+
- Native-module stubs live in `test/*.stub.ts(x)` (`react-native`,
|
|
143
|
+
`react-native-svg`, `react-native-reanimated`, `@gorhom/bottom-sheet`,
|
|
144
|
+
clipboard, webview, qrcode). **Pulling in a new native module? Add a stub** or
|
|
145
|
+
the import fails under node.
|
|
146
|
+
- **Mock at the `@funkit/api-base` edge** — never mock internal hooks
|
|
147
|
+
(`useTransferInit`, etc.). Snapshot tests may mock internal hooks to freeze
|
|
148
|
+
inputs. See the repo [TESTING.md](../../TESTING.md).
|
|
22
149
|
|
|
23
150
|
## Fonts
|
|
24
151
|
|
package/dist/index.js
CHANGED
|
@@ -558,6 +558,7 @@ function useFunkitColorScheme() {
|
|
|
558
558
|
// src/providers/FunkitProvider.tsx
|
|
559
559
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
560
560
|
import { useEffect as useEffect12, useMemo as useMemo10, useRef as useRef7 } from "react";
|
|
561
|
+
import { SafeAreaProvider } from "react-native-safe-area-context";
|
|
561
562
|
|
|
562
563
|
// src/flow/FunkitFlowProvider.tsx
|
|
563
564
|
import { useDynamicConfig as useDynamicConfig6 } from "@funkit/connect-core";
|
|
@@ -570,13 +571,8 @@ import {
|
|
|
570
571
|
useRef as useRef6,
|
|
571
572
|
useState as useState9
|
|
572
573
|
} from "react";
|
|
573
|
-
import {
|
|
574
|
-
|
|
575
|
-
Share,
|
|
576
|
-
StatusBar,
|
|
577
|
-
StyleSheet as StyleSheet3,
|
|
578
|
-
View as View3
|
|
579
|
-
} from "react-native";
|
|
574
|
+
import { Share, StyleSheet as StyleSheet3, View as View3 } from "react-native";
|
|
575
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
580
576
|
|
|
581
577
|
// src/geo/useCheckoutBlocked.ts
|
|
582
578
|
import { useEffect as useEffect2, useMemo as useMemo3 } from "react";
|
|
@@ -2460,7 +2456,7 @@ var addressCard = {
|
|
|
2460
2456
|
shadowRadius: 32,
|
|
2461
2457
|
elevation: 1
|
|
2462
2458
|
};
|
|
2463
|
-
var addressColumn = { gap:
|
|
2459
|
+
var addressColumn = { gap: 6 };
|
|
2464
2460
|
var addressGroup2 = { gap: 6 };
|
|
2465
2461
|
var addressText2 = { fontSize: 24, lineHeight: 34 };
|
|
2466
2462
|
var previewPill = {
|
|
@@ -3493,6 +3489,7 @@ function FunkitFlowProvider({
|
|
|
3493
3489
|
children,
|
|
3494
3490
|
copyToClipboard: copyToClipboard2 = copyToClipboard
|
|
3495
3491
|
}) {
|
|
3492
|
+
const insets = useSafeAreaInsets();
|
|
3496
3493
|
const [state, setState] = useState9(CLOSED);
|
|
3497
3494
|
const beginDeposit = useCallback5(
|
|
3498
3495
|
(config, callbacks = {}) => {
|
|
@@ -3590,7 +3587,17 @@ function FunkitFlowProvider({
|
|
|
3590
3587
|
children
|
|
3591
3588
|
}
|
|
3592
3589
|
),
|
|
3593
|
-
toastMounted ? /* @__PURE__ */ jsx21(
|
|
3590
|
+
toastMounted ? /* @__PURE__ */ jsx21(
|
|
3591
|
+
View3,
|
|
3592
|
+
{
|
|
3593
|
+
style: [
|
|
3594
|
+
toastOverlay,
|
|
3595
|
+
{ paddingTop: insets.top + TOAST_INSET_OFFSET }
|
|
3596
|
+
],
|
|
3597
|
+
pointerEvents: "none",
|
|
3598
|
+
children: copiedToastShown ? /* @__PURE__ */ jsx21(AddressCopiedToast, {}) : null
|
|
3599
|
+
}
|
|
3600
|
+
) : null
|
|
3594
3601
|
] }) });
|
|
3595
3602
|
}
|
|
3596
3603
|
var DEFAULT_EVM_CHAIN_ID = 1;
|
|
@@ -3827,16 +3834,12 @@ function FlowContent({
|
|
|
3827
3834
|
}
|
|
3828
3835
|
var TOAST_VISIBLE_MS = 1800;
|
|
3829
3836
|
var TOAST_EXIT_MS = 350;
|
|
3837
|
+
var TOAST_INSET_OFFSET = 20;
|
|
3830
3838
|
var rootContainer = { flex: 1 };
|
|
3831
|
-
var
|
|
3839
|
+
var toastOverlay = {
|
|
3832
3840
|
...StyleSheet3.absoluteFill,
|
|
3833
3841
|
zIndex: 1,
|
|
3834
|
-
alignItems: "center"
|
|
3835
|
-
paddingTop: Platform2.select({
|
|
3836
|
-
ios: 60,
|
|
3837
|
-
android: (StatusBar?.currentHeight ?? 0) + 16,
|
|
3838
|
-
default: 16
|
|
3839
|
-
}) ?? 16
|
|
3842
|
+
alignItems: "center"
|
|
3840
3843
|
};
|
|
3841
3844
|
function useFunkitFlow() {
|
|
3842
3845
|
const value = useContext3(FunkitFlowContext);
|
|
@@ -3847,7 +3850,7 @@ function useFunkitFlow() {
|
|
|
3847
3850
|
}
|
|
3848
3851
|
|
|
3849
3852
|
// src/version.ts
|
|
3850
|
-
var CONNECT_RN_VERSION = true ? "1.0.
|
|
3853
|
+
var CONNECT_RN_VERSION = true ? "1.0.3" : "0.0.0-dev";
|
|
3851
3854
|
|
|
3852
3855
|
// src/providers/FunkitStatsigProvider.tsx
|
|
3853
3856
|
import {
|
|
@@ -3992,13 +3995,13 @@ function applyNetworkFix(options) {
|
|
|
3992
3995
|
}
|
|
3993
3996
|
|
|
3994
3997
|
// src/statsig/statsigMetadata.ts
|
|
3995
|
-
import { NativeModules, Platform as
|
|
3998
|
+
import { NativeModules, Platform as Platform2 } from "react-native";
|
|
3996
3999
|
function resolveLocale() {
|
|
3997
|
-
if (
|
|
4000
|
+
if (Platform2.OS === "android") {
|
|
3998
4001
|
const i18nManager = NativeModules.I18nManager;
|
|
3999
4002
|
return i18nManager?.localeIdentifier ?? void 0;
|
|
4000
4003
|
}
|
|
4001
|
-
if (
|
|
4004
|
+
if (Platform2.OS === "ios") {
|
|
4002
4005
|
const settings = NativeModules.SettingsManager?.settings;
|
|
4003
4006
|
return settings?.AppLocale ?? settings?.AppleLanguages?.[0] ?? void 0;
|
|
4004
4007
|
}
|
|
@@ -4012,7 +4015,7 @@ function getStatsigMetadataAdditions() {
|
|
|
4012
4015
|
deviceModelName: void 0,
|
|
4013
4016
|
deviceModel: void 0,
|
|
4014
4017
|
// Available without any native module:
|
|
4015
|
-
systemName:
|
|
4018
|
+
systemName: Platform2.OS,
|
|
4016
4019
|
locale: resolveLocale()
|
|
4017
4020
|
};
|
|
4018
4021
|
}
|
|
@@ -4106,7 +4109,7 @@ function FunkitProvider({
|
|
|
4106
4109
|
""
|
|
4107
4110
|
);
|
|
4108
4111
|
}, [identity]);
|
|
4109
|
-
return /* @__PURE__ */ jsx23(
|
|
4112
|
+
return /* @__PURE__ */ jsx23(SafeAreaProvider, { children: /* @__PURE__ */ jsx23(
|
|
4110
4113
|
FunkitStatsigProvider,
|
|
4111
4114
|
{
|
|
4112
4115
|
apiKey: identity.apiKey,
|
|
@@ -4114,7 +4117,7 @@ function FunkitProvider({
|
|
|
4114
4117
|
isDevelopment: debug,
|
|
4115
4118
|
children: /* @__PURE__ */ jsx23(QueryClientProvider, { client, children: /* @__PURE__ */ jsx23(FunkitIdentityProvider, { identity, children: /* @__PURE__ */ jsx23(FunkitThemeProvider, { themes, colorScheme, children: /* @__PURE__ */ jsx23(FunkitFlowProvider, { copyToClipboard: copyToClipboard2, children }) }) }) })
|
|
4116
4119
|
}
|
|
4117
|
-
);
|
|
4120
|
+
) });
|
|
4118
4121
|
}
|
|
4119
4122
|
|
|
4120
4123
|
// src/providers/useFunkitCheckout.ts
|