@coinbase/cdp-react-native 0.0.83 → 0.0.84
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/dist/esm/index2.js +54 -60
- package/dist/esm/index4.js +17 -13
- package/dist/esm/index6.js +14 -5
- package/dist/types/index.d.ts +8 -4
- package/package.json +7 -7
package/dist/esm/index2.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { createEndUserApplePayOnrampOrder as
|
|
2
|
-
import { useCurrentUser as
|
|
3
|
-
import
|
|
4
|
-
import { checkUserVerification as
|
|
5
|
-
const
|
|
6
|
-
function
|
|
7
|
-
const [
|
|
1
|
+
import { createEndUserApplePayOnrampOrder as f, APIError as h } from "@coinbase/cdp-api-client";
|
|
2
|
+
import { useCurrentUser as g, useConfig as v } from "@coinbase/cdp-hooks";
|
|
3
|
+
import C, { createContext as U, useReducer as x, useCallback as n, useEffect as A } from "react";
|
|
4
|
+
import { checkUserVerification as E } from "./index5.js";
|
|
5
|
+
const I = U(null);
|
|
6
|
+
function w({ children: t, debug: a = !1 }) {
|
|
7
|
+
const [p, r] = x(P, i), { currentUser: o } = g(), { config: d } = v(), c = n(() => {
|
|
8
8
|
if (!o)
|
|
9
9
|
return r({
|
|
10
10
|
type: "validation_error",
|
|
@@ -12,7 +12,7 @@ function q({ children: t }) {
|
|
|
12
12
|
code: "user_not_authenticated"
|
|
13
13
|
}
|
|
14
14
|
}), null;
|
|
15
|
-
const { missingVerification: e } =
|
|
15
|
+
const { missingVerification: e } = E(o);
|
|
16
16
|
return e ? (r({
|
|
17
17
|
type: "validation_error",
|
|
18
18
|
error: {
|
|
@@ -20,16 +20,16 @@ function q({ children: t }) {
|
|
|
20
20
|
}
|
|
21
21
|
}), null) : (r({ type: "reset" }), o);
|
|
22
22
|
}, [o]);
|
|
23
|
-
|
|
23
|
+
A(() => {
|
|
24
24
|
c();
|
|
25
25
|
}, [c]);
|
|
26
|
-
const
|
|
26
|
+
const l = n(
|
|
27
27
|
async (e) => {
|
|
28
28
|
const u = c();
|
|
29
29
|
if (u)
|
|
30
30
|
try {
|
|
31
31
|
r({ type: "purchase_requested" });
|
|
32
|
-
const
|
|
32
|
+
const s = await f(d.projectId, u.userId, {
|
|
33
33
|
agreementAcceptedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34
34
|
// TODO: Do we need to verify the user owns the destination address?
|
|
35
35
|
destination: e.destination,
|
|
@@ -42,73 +42,67 @@ function q({ children: t }) {
|
|
|
42
42
|
},
|
|
43
43
|
isSandbox: e.isSandbox
|
|
44
44
|
});
|
|
45
|
-
r({ type: "purchase_started", data:
|
|
46
|
-
} catch (
|
|
47
|
-
|
|
45
|
+
r({ type: "purchase_started", data: s });
|
|
46
|
+
} catch (s) {
|
|
47
|
+
s instanceof h ? r({
|
|
48
48
|
type: "purchase_error",
|
|
49
49
|
error: {
|
|
50
50
|
code: "api_error",
|
|
51
|
-
correlationId:
|
|
52
|
-
message:
|
|
51
|
+
correlationId: s.correlationId,
|
|
52
|
+
message: s.errorMessage
|
|
53
53
|
}
|
|
54
54
|
}) : r({
|
|
55
55
|
type: "purchase_error",
|
|
56
56
|
error: {
|
|
57
|
-
message:
|
|
57
|
+
message: s instanceof Error ? s.message : "Failed to create order"
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
[c]
|
|
63
|
-
),
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
r({ type: "purchase_success" });
|
|
85
|
-
break;
|
|
86
|
-
case "onramp_api.cancel":
|
|
87
|
-
r({ type: "reset" });
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
}, []), m = n(() => {
|
|
63
|
+
), m = n(
|
|
64
|
+
(e) => {
|
|
65
|
+
switch (e.type) {
|
|
66
|
+
case "onramp_api.load_error":
|
|
67
|
+
case "onramp_api.commit_error":
|
|
68
|
+
case "onramp_api.polling_error":
|
|
69
|
+
r({
|
|
70
|
+
type: "purchase_error",
|
|
71
|
+
error: e.error
|
|
72
|
+
});
|
|
73
|
+
break;
|
|
74
|
+
case "onramp_api.polling_success":
|
|
75
|
+
r({ type: "purchase_success" });
|
|
76
|
+
break;
|
|
77
|
+
case "onramp_api.cancel":
|
|
78
|
+
r({ type: "reset" });
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
[a]
|
|
83
|
+
), _ = n(() => {
|
|
91
84
|
r({ type: "reset" });
|
|
92
|
-
}, []),
|
|
93
|
-
...
|
|
94
|
-
createOrder:
|
|
95
|
-
paymentEventHandler:
|
|
96
|
-
reset:
|
|
85
|
+
}, []), y = {
|
|
86
|
+
...p,
|
|
87
|
+
createOrder: l,
|
|
88
|
+
paymentEventHandler: m,
|
|
89
|
+
reset: _,
|
|
90
|
+
debug: a
|
|
97
91
|
};
|
|
98
|
-
return /* @__PURE__ */
|
|
92
|
+
return /* @__PURE__ */ C.createElement(I.Provider, { value: y }, t);
|
|
99
93
|
}
|
|
100
|
-
const
|
|
94
|
+
const i = {
|
|
101
95
|
status: "idle",
|
|
102
96
|
data: void 0,
|
|
103
97
|
error: void 0
|
|
104
98
|
};
|
|
105
|
-
function
|
|
106
|
-
switch (
|
|
99
|
+
function P(t, a) {
|
|
100
|
+
switch (a.type) {
|
|
107
101
|
case "validation_error":
|
|
108
102
|
return {
|
|
109
103
|
...t,
|
|
110
104
|
status: "error",
|
|
111
|
-
error:
|
|
105
|
+
error: a.error
|
|
112
106
|
};
|
|
113
107
|
case "purchase_requested":
|
|
114
108
|
return {
|
|
@@ -120,7 +114,7 @@ function A(t, s) {
|
|
|
120
114
|
return {
|
|
121
115
|
...t,
|
|
122
116
|
status: "pending",
|
|
123
|
-
data:
|
|
117
|
+
data: a.data,
|
|
124
118
|
error: void 0
|
|
125
119
|
};
|
|
126
120
|
case "purchase_success":
|
|
@@ -132,15 +126,15 @@ function A(t, s) {
|
|
|
132
126
|
return {
|
|
133
127
|
...t,
|
|
134
128
|
status: "error",
|
|
135
|
-
error:
|
|
129
|
+
error: a.error
|
|
136
130
|
};
|
|
137
131
|
case "reset":
|
|
138
|
-
return
|
|
132
|
+
return i;
|
|
139
133
|
default:
|
|
140
134
|
return t;
|
|
141
135
|
}
|
|
142
136
|
}
|
|
143
137
|
export {
|
|
144
|
-
|
|
145
|
-
|
|
138
|
+
I as ApplePayContext,
|
|
139
|
+
w as ApplePayProvider
|
|
146
140
|
};
|
package/dist/esm/index4.js
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
1
|
-
import
|
|
1
|
+
import i, { useContext as d, useCallback as c } from "react";
|
|
2
2
|
import { StyleSheet as p, Platform as l, View as g } from "react-native";
|
|
3
3
|
import { WebView as v } from "react-native-webview";
|
|
4
4
|
import { ApplePayContext as w } from "./index2.js";
|
|
5
5
|
import { parseWebViewMessage as f } from "./index6.js";
|
|
6
|
-
function
|
|
7
|
-
const e =
|
|
6
|
+
function S({ style: s }) {
|
|
7
|
+
const e = d(w);
|
|
8
8
|
if (!e)
|
|
9
9
|
throw new Error("ApplePayButton must be used within an ApplePayProvider");
|
|
10
|
-
const
|
|
11
|
-
(
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const n = e.data?.paymentLink.url, r = c(
|
|
11
|
+
(a) => {
|
|
12
|
+
e.debug && console.log(
|
|
13
|
+
"[ApplePayButton] Received webview event:",
|
|
14
|
+
JSON.stringify(a.nativeEvent.data, null, 2)
|
|
15
|
+
);
|
|
16
|
+
const t = f(a.nativeEvent.data);
|
|
17
|
+
e.debug && console.log("[ApplePayButton] Parsed event:", JSON.stringify(t, null, 2)), t.success && e.paymentEventHandler(t.event);
|
|
14
18
|
},
|
|
15
19
|
[e.paymentEventHandler]
|
|
16
20
|
);
|
|
17
|
-
return l.OS !== "ios" ? (__DEV__ && console.warn("ApplePayButton is only available on iOS"), null) :
|
|
21
|
+
return l.OS !== "ios" ? (__DEV__ && console.warn("ApplePayButton is only available on iOS"), null) : n ? /* @__PURE__ */ i.createElement(g, { style: [o.container, s] }, /* @__PURE__ */ i.createElement(
|
|
18
22
|
v,
|
|
19
23
|
{
|
|
20
|
-
source: { uri:
|
|
24
|
+
source: { uri: n },
|
|
21
25
|
injectedJavaScriptBeforeContentLoaded: u,
|
|
22
26
|
injectedJavaScript: m,
|
|
23
|
-
onMessage:
|
|
27
|
+
onMessage: r,
|
|
24
28
|
startInLoadingState: !0,
|
|
25
|
-
style:
|
|
29
|
+
style: o.webView,
|
|
26
30
|
originWhitelist: ["https://*", "apple-pay://*"],
|
|
27
31
|
mixedContentMode: "compatibility"
|
|
28
32
|
}
|
|
29
33
|
)) : null;
|
|
30
34
|
}
|
|
31
|
-
const
|
|
35
|
+
const o = p.create({
|
|
32
36
|
container: {
|
|
33
37
|
height: 48,
|
|
34
38
|
width: "100%",
|
|
@@ -121,5 +125,5 @@ const i = p.create({
|
|
|
121
125
|
})();
|
|
122
126
|
`;
|
|
123
127
|
export {
|
|
124
|
-
|
|
128
|
+
S as ApplePayButton
|
|
125
129
|
};
|
package/dist/esm/index6.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
const
|
|
1
|
+
const a = [
|
|
2
2
|
"onramp_api.load_pending",
|
|
3
3
|
"onramp_api.load_success",
|
|
4
4
|
"onramp_api.load_error",
|
|
5
|
+
"onramp_api.polling_start",
|
|
5
6
|
"onramp_api.polling_success",
|
|
7
|
+
"onramp_api.polling_error",
|
|
8
|
+
"onramp_api.commit_success",
|
|
6
9
|
"onramp_api.commit_error",
|
|
7
10
|
"onramp_api.cancel"
|
|
8
11
|
];
|
|
@@ -13,10 +16,10 @@ function o(s) {
|
|
|
13
16
|
} catch {
|
|
14
17
|
return { success: !1, reason: "Invalid JSON" };
|
|
15
18
|
}
|
|
16
|
-
if (!
|
|
19
|
+
if (!n(e))
|
|
17
20
|
return { success: !1, reason: "Invalid message structure" };
|
|
18
21
|
const r = e.eventName ?? e.type;
|
|
19
|
-
return r ? t(r) ? {
|
|
22
|
+
return r ? t(r) ? e.data?.errorCode || e.data?.errorMessage ? {
|
|
20
23
|
success: !0,
|
|
21
24
|
event: {
|
|
22
25
|
type: r,
|
|
@@ -26,16 +29,22 @@ function o(s) {
|
|
|
26
29
|
message: e.data?.errorMessage
|
|
27
30
|
}
|
|
28
31
|
}
|
|
32
|
+
} : {
|
|
33
|
+
success: !0,
|
|
34
|
+
event: {
|
|
35
|
+
type: r,
|
|
36
|
+
message: e.message
|
|
37
|
+
}
|
|
29
38
|
} : { success: !1, reason: "Unknown event type" } : { success: !1, reason: "Missing event type" };
|
|
30
39
|
}
|
|
31
|
-
function
|
|
40
|
+
function n(s) {
|
|
32
41
|
if (typeof s != "object" || s === null)
|
|
33
42
|
return !1;
|
|
34
43
|
const e = s;
|
|
35
44
|
return typeof e.eventName == "string" || typeof e.type == "string";
|
|
36
45
|
}
|
|
37
46
|
function t(s) {
|
|
38
|
-
return
|
|
47
|
+
return a.includes(s);
|
|
39
48
|
}
|
|
40
49
|
export {
|
|
41
50
|
o as parseWebViewMessage
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,15 +15,17 @@ export declare interface ApplePayContextValue {
|
|
|
15
15
|
status: ApplePayOnrampStatus;
|
|
16
16
|
error: OnrampError | undefined;
|
|
17
17
|
reset: () => void;
|
|
18
|
+
debug: boolean;
|
|
18
19
|
paymentEventHandler: (event: OnrampEvent) => void;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export declare type ApplePayOnrampStatus = "idle" | "pending" | "error" | "success";
|
|
22
23
|
|
|
23
|
-
export declare function ApplePayProvider({ children }: ApplePayProviderProps): JSX.Element;
|
|
24
|
+
export declare function ApplePayProvider({ children, debug }: ApplePayProviderProps): JSX.Element;
|
|
24
25
|
|
|
25
26
|
export declare interface ApplePayProviderProps {
|
|
26
27
|
children: ReactNode;
|
|
28
|
+
debug?: boolean;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
export declare interface CreateOrderOptions {
|
|
@@ -33,14 +35,16 @@ export declare interface CreateOrderOptions {
|
|
|
33
35
|
};
|
|
34
36
|
purchase: {
|
|
35
37
|
amount: string;
|
|
36
|
-
currency: "usdc" | string;
|
|
38
|
+
currency: "usdc" | (string & {});
|
|
37
39
|
};
|
|
38
40
|
payment: {
|
|
39
|
-
currency: "usd" | string;
|
|
41
|
+
currency: "usd" | (string & {});
|
|
40
42
|
};
|
|
41
43
|
isSandbox?: boolean;
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
declare const ONRAMP_EVENT_TYPES: readonly ["onramp_api.load_pending", "onramp_api.load_success", "onramp_api.load_error", "onramp_api.polling_start", "onramp_api.polling_success", "onramp_api.polling_error", "onramp_api.commit_success", "onramp_api.commit_error", "onramp_api.cancel"];
|
|
47
|
+
|
|
44
48
|
export declare interface OnrampError {
|
|
45
49
|
correlationId?: string;
|
|
46
50
|
message?: string;
|
|
@@ -60,7 +64,7 @@ declare type OnrampEvent = {
|
|
|
60
64
|
message?: string;
|
|
61
65
|
} | OnrampErrorEvent;
|
|
62
66
|
|
|
63
|
-
declare type OnrampEventType =
|
|
67
|
+
declare type OnrampEventType = (typeof ONRAMP_EVENT_TYPES)[number];
|
|
64
68
|
|
|
65
69
|
export declare function useApplePay(): UseApplePayReturn;
|
|
66
70
|
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coinbase/cdp-react-native",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.84",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"react": ">=18.2.0",
|
|
7
7
|
"react-native": ">=0.70.0",
|
|
8
8
|
"react-native-webview": ">=13.0.0",
|
|
9
|
-
"@coinbase/cdp-
|
|
10
|
-
"@coinbase/cdp-
|
|
11
|
-
"@coinbase/cdp-core": "^0.0.
|
|
9
|
+
"@coinbase/cdp-api-client": "^0.0.84",
|
|
10
|
+
"@coinbase/cdp-hooks": "^0.0.84",
|
|
11
|
+
"@coinbase/cdp-core": "^0.0.84"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@testing-library/react": "^16.0.0",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"react-dom": "^19.1.2",
|
|
18
18
|
"react-native": "^0.79.6",
|
|
19
19
|
"react-native-webview": "^13.13.5",
|
|
20
|
-
"@coinbase/cdp-api-client": "0.0.
|
|
21
|
-
"@coinbase/cdp-core": "0.0.
|
|
22
|
-
"@coinbase/cdp-hooks": "0.0.
|
|
20
|
+
"@coinbase/cdp-api-client": "0.0.84",
|
|
21
|
+
"@coinbase/cdp-core": "0.0.84",
|
|
22
|
+
"@coinbase/cdp-hooks": "0.0.84"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"dist/**",
|