@b3dotfun/sdk 0.1.68-alpha.0 → 0.1.68-alpha.10

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.
Files changed (232) hide show
  1. package/dist/cjs/anyspend/platform/client.d.ts +35 -0
  2. package/dist/cjs/anyspend/platform/client.js +158 -0
  3. package/dist/cjs/anyspend/platform/errors.d.ts +38 -0
  4. package/dist/cjs/anyspend/platform/errors.js +77 -0
  5. package/dist/cjs/anyspend/platform/index.d.ts +87 -0
  6. package/dist/cjs/anyspend/platform/index.js +85 -0
  7. package/dist/cjs/anyspend/platform/resources/analytics.d.ts +7 -0
  8. package/dist/cjs/anyspend/platform/resources/analytics.js +12 -0
  9. package/dist/cjs/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
  10. package/dist/cjs/anyspend/platform/resources/checkout-sessions.js +27 -0
  11. package/dist/cjs/anyspend/platform/resources/customers.d.ts +19 -0
  12. package/dist/cjs/anyspend/platform/resources/customers.js +34 -0
  13. package/dist/cjs/anyspend/platform/resources/discount-codes.d.ts +29 -0
  14. package/dist/cjs/anyspend/platform/resources/discount-codes.js +31 -0
  15. package/dist/cjs/anyspend/platform/resources/events.d.ts +14 -0
  16. package/dist/cjs/anyspend/platform/resources/events.js +16 -0
  17. package/dist/cjs/anyspend/platform/resources/notifications.d.ts +18 -0
  18. package/dist/cjs/anyspend/platform/resources/notifications.js +27 -0
  19. package/dist/cjs/anyspend/platform/resources/organization.d.ts +17 -0
  20. package/dist/cjs/anyspend/platform/resources/organization.js +15 -0
  21. package/dist/cjs/anyspend/platform/resources/payment-links.d.ts +21 -0
  22. package/dist/cjs/anyspend/platform/resources/payment-links.js +49 -0
  23. package/dist/cjs/anyspend/platform/resources/products.d.ts +27 -0
  24. package/dist/cjs/anyspend/platform/resources/products.js +31 -0
  25. package/dist/cjs/anyspend/platform/resources/transactions.d.ts +11 -0
  26. package/dist/cjs/anyspend/platform/resources/transactions.js +25 -0
  27. package/dist/cjs/anyspend/platform/resources/webhooks.d.ts +14 -0
  28. package/dist/cjs/anyspend/platform/resources/webhooks.js +33 -0
  29. package/dist/cjs/anyspend/platform/resources/widgets.d.ts +38 -0
  30. package/dist/cjs/anyspend/platform/resources/widgets.js +31 -0
  31. package/dist/cjs/anyspend/platform/types.d.ts +478 -0
  32. package/dist/cjs/anyspend/platform/types.js +5 -0
  33. package/dist/cjs/anyspend/platform/utils/idempotency.d.ts +4 -0
  34. package/dist/cjs/anyspend/platform/utils/idempotency.js +17 -0
  35. package/dist/cjs/anyspend/platform/utils/pagination.d.ts +12 -0
  36. package/dist/cjs/anyspend/platform/utils/pagination.js +22 -0
  37. package/dist/cjs/anyspend/react/components/AnySpend.d.ts +5 -1
  38. package/dist/cjs/anyspend/react/components/AnySpend.js +123 -12
  39. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckout.d.ts +14 -6
  40. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckout.js +55 -8
  41. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckoutTrigger.d.ts +3 -1
  42. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckoutTrigger.js +2 -2
  43. package/dist/cjs/anyspend/react/components/checkout/CheckoutPaymentPanel.d.ts +5 -1
  44. package/dist/cjs/anyspend/react/components/checkout/CheckoutPaymentPanel.js +2 -2
  45. package/dist/cjs/anyspend/react/components/checkout/CryptoPayPanel.js +1 -1
  46. package/dist/cjs/anyspend/react/components/checkout/FiatCheckoutPanel.d.ts +5 -1
  47. package/dist/cjs/anyspend/react/components/checkout/FiatCheckoutPanel.js +48 -16
  48. package/dist/cjs/anyspend/react/components/checkout/KycGate.d.ts +11 -0
  49. package/dist/cjs/anyspend/react/components/checkout/KycGate.js +203 -0
  50. package/dist/cjs/anyspend/react/components/checkout/VariablePricingInput.d.ts +17 -0
  51. package/dist/cjs/anyspend/react/components/checkout/VariablePricingInput.js +145 -0
  52. package/dist/cjs/anyspend/react/components/index.d.ts +1 -1
  53. package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
  54. package/dist/cjs/anyspend/react/hooks/index.js +1 -0
  55. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +2 -0
  56. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +14 -0
  57. package/dist/cjs/anyspend/react/hooks/useKycStatus.d.ts +47 -0
  58. package/dist/cjs/anyspend/react/hooks/useKycStatus.js +124 -0
  59. package/dist/cjs/anyspend/services/anyspend.d.ts +4 -1
  60. package/dist/cjs/anyspend/services/anyspend.js +3 -1
  61. package/dist/cjs/global-account/react/components/B3DynamicModal.js +1 -1
  62. package/dist/cjs/global-account/react/components/ManageAccount/BottomNavigation.js +3 -3
  63. package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +1 -1
  64. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +13 -5
  65. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +1 -1
  66. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -1
  67. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +21 -24
  68. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +1 -1
  69. package/dist/cjs/global-account/react/hooks/useAuth.js +1 -1
  70. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +3 -1
  71. package/dist/cjs/global-account/react/hooks/useAuthentication.js +82 -24
  72. package/dist/cjs/global-account/react/hooks/useGetAllTWSigners.js +2 -1
  73. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +4 -0
  74. package/dist/cjs/global-account/react/stores/useModalStore.js +2 -0
  75. package/dist/cjs/global-account/react/utils/createWagmiConfig.d.ts +18 -0
  76. package/dist/cjs/global-account/react/utils/createWagmiConfig.js +17 -0
  77. package/dist/esm/anyspend/platform/client.d.ts +35 -0
  78. package/dist/esm/anyspend/platform/client.js +153 -0
  79. package/dist/esm/anyspend/platform/errors.d.ts +38 -0
  80. package/dist/esm/anyspend/platform/errors.js +67 -0
  81. package/dist/esm/anyspend/platform/index.d.ts +87 -0
  82. package/dist/esm/anyspend/platform/index.js +75 -0
  83. package/dist/esm/anyspend/platform/resources/analytics.d.ts +7 -0
  84. package/dist/esm/anyspend/platform/resources/analytics.js +8 -0
  85. package/dist/esm/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
  86. package/dist/esm/anyspend/platform/resources/checkout-sessions.js +23 -0
  87. package/dist/esm/anyspend/platform/resources/customers.d.ts +19 -0
  88. package/dist/esm/anyspend/platform/resources/customers.js +30 -0
  89. package/dist/esm/anyspend/platform/resources/discount-codes.d.ts +29 -0
  90. package/dist/esm/anyspend/platform/resources/discount-codes.js +27 -0
  91. package/dist/esm/anyspend/platform/resources/events.d.ts +14 -0
  92. package/dist/esm/anyspend/platform/resources/events.js +12 -0
  93. package/dist/esm/anyspend/platform/resources/notifications.d.ts +18 -0
  94. package/dist/esm/anyspend/platform/resources/notifications.js +23 -0
  95. package/dist/esm/anyspend/platform/resources/organization.d.ts +17 -0
  96. package/dist/esm/anyspend/platform/resources/organization.js +11 -0
  97. package/dist/esm/anyspend/platform/resources/payment-links.d.ts +21 -0
  98. package/dist/esm/anyspend/platform/resources/payment-links.js +45 -0
  99. package/dist/esm/anyspend/platform/resources/products.d.ts +27 -0
  100. package/dist/esm/anyspend/platform/resources/products.js +27 -0
  101. package/dist/esm/anyspend/platform/resources/transactions.d.ts +11 -0
  102. package/dist/esm/anyspend/platform/resources/transactions.js +21 -0
  103. package/dist/esm/anyspend/platform/resources/webhooks.d.ts +14 -0
  104. package/dist/esm/anyspend/platform/resources/webhooks.js +29 -0
  105. package/dist/esm/anyspend/platform/resources/widgets.d.ts +38 -0
  106. package/dist/esm/anyspend/platform/resources/widgets.js +27 -0
  107. package/dist/esm/anyspend/platform/types.d.ts +478 -0
  108. package/dist/esm/anyspend/platform/types.js +4 -0
  109. package/dist/esm/anyspend/platform/utils/idempotency.d.ts +4 -0
  110. package/dist/esm/anyspend/platform/utils/idempotency.js +14 -0
  111. package/dist/esm/anyspend/platform/utils/pagination.d.ts +12 -0
  112. package/dist/esm/anyspend/platform/utils/pagination.js +19 -0
  113. package/dist/esm/anyspend/react/components/AnySpend.d.ts +5 -1
  114. package/dist/esm/anyspend/react/components/AnySpend.js +124 -13
  115. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckout.d.ts +14 -6
  116. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckout.js +55 -8
  117. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckoutTrigger.d.ts +3 -1
  118. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckoutTrigger.js +2 -2
  119. package/dist/esm/anyspend/react/components/checkout/CheckoutPaymentPanel.d.ts +5 -1
  120. package/dist/esm/anyspend/react/components/checkout/CheckoutPaymentPanel.js +2 -2
  121. package/dist/esm/anyspend/react/components/checkout/CryptoPayPanel.js +1 -1
  122. package/dist/esm/anyspend/react/components/checkout/FiatCheckoutPanel.d.ts +5 -1
  123. package/dist/esm/anyspend/react/components/checkout/FiatCheckoutPanel.js +50 -18
  124. package/dist/esm/anyspend/react/components/checkout/KycGate.d.ts +11 -0
  125. package/dist/esm/anyspend/react/components/checkout/KycGate.js +167 -0
  126. package/dist/esm/anyspend/react/components/checkout/VariablePricingInput.d.ts +17 -0
  127. package/dist/esm/anyspend/react/components/checkout/VariablePricingInput.js +142 -0
  128. package/dist/esm/anyspend/react/components/index.d.ts +1 -1
  129. package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
  130. package/dist/esm/anyspend/react/hooks/index.js +1 -0
  131. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +2 -0
  132. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +14 -0
  133. package/dist/esm/anyspend/react/hooks/useKycStatus.d.ts +47 -0
  134. package/dist/esm/anyspend/react/hooks/useKycStatus.js +117 -0
  135. package/dist/esm/anyspend/services/anyspend.d.ts +4 -1
  136. package/dist/esm/anyspend/services/anyspend.js +3 -1
  137. package/dist/esm/global-account/react/components/B3DynamicModal.js +1 -1
  138. package/dist/esm/global-account/react/components/ManageAccount/BottomNavigation.js +3 -3
  139. package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +1 -1
  140. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +13 -5
  141. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +1 -1
  142. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -1
  143. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +21 -24
  144. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +1 -1
  145. package/dist/esm/global-account/react/hooks/useAuth.js +2 -2
  146. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +3 -1
  147. package/dist/esm/global-account/react/hooks/useAuthentication.js +82 -24
  148. package/dist/esm/global-account/react/hooks/useGetAllTWSigners.js +2 -1
  149. package/dist/esm/global-account/react/stores/useModalStore.d.ts +4 -0
  150. package/dist/esm/global-account/react/stores/useModalStore.js +2 -0
  151. package/dist/esm/global-account/react/utils/createWagmiConfig.d.ts +18 -0
  152. package/dist/esm/global-account/react/utils/createWagmiConfig.js +16 -0
  153. package/dist/styles/index.css +1 -1
  154. package/dist/types/anyspend/platform/client.d.ts +35 -0
  155. package/dist/types/anyspend/platform/errors.d.ts +38 -0
  156. package/dist/types/anyspend/platform/index.d.ts +87 -0
  157. package/dist/types/anyspend/platform/resources/analytics.d.ts +7 -0
  158. package/dist/types/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
  159. package/dist/types/anyspend/platform/resources/customers.d.ts +19 -0
  160. package/dist/types/anyspend/platform/resources/discount-codes.d.ts +29 -0
  161. package/dist/types/anyspend/platform/resources/events.d.ts +14 -0
  162. package/dist/types/anyspend/platform/resources/notifications.d.ts +18 -0
  163. package/dist/types/anyspend/platform/resources/organization.d.ts +17 -0
  164. package/dist/types/anyspend/platform/resources/payment-links.d.ts +21 -0
  165. package/dist/types/anyspend/platform/resources/products.d.ts +27 -0
  166. package/dist/types/anyspend/platform/resources/transactions.d.ts +11 -0
  167. package/dist/types/anyspend/platform/resources/webhooks.d.ts +14 -0
  168. package/dist/types/anyspend/platform/resources/widgets.d.ts +38 -0
  169. package/dist/types/anyspend/platform/types.d.ts +478 -0
  170. package/dist/types/anyspend/platform/utils/idempotency.d.ts +4 -0
  171. package/dist/types/anyspend/platform/utils/pagination.d.ts +12 -0
  172. package/dist/types/anyspend/react/components/AnySpend.d.ts +5 -1
  173. package/dist/types/anyspend/react/components/checkout/AnySpendCheckout.d.ts +14 -6
  174. package/dist/types/anyspend/react/components/checkout/AnySpendCheckoutTrigger.d.ts +3 -1
  175. package/dist/types/anyspend/react/components/checkout/CheckoutPaymentPanel.d.ts +5 -1
  176. package/dist/types/anyspend/react/components/checkout/FiatCheckoutPanel.d.ts +5 -1
  177. package/dist/types/anyspend/react/components/checkout/KycGate.d.ts +11 -0
  178. package/dist/types/anyspend/react/components/checkout/VariablePricingInput.d.ts +17 -0
  179. package/dist/types/anyspend/react/components/index.d.ts +1 -1
  180. package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
  181. package/dist/types/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +2 -0
  182. package/dist/types/anyspend/react/hooks/useKycStatus.d.ts +47 -0
  183. package/dist/types/anyspend/services/anyspend.d.ts +4 -1
  184. package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -1
  185. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +3 -1
  186. package/dist/types/global-account/react/stores/useModalStore.d.ts +4 -0
  187. package/dist/types/global-account/react/utils/createWagmiConfig.d.ts +18 -0
  188. package/package.json +7 -1
  189. package/src/anyspend/docs/checkout-sessions.md +20 -3
  190. package/src/anyspend/platform/client.ts +198 -0
  191. package/src/anyspend/platform/errors.ts +92 -0
  192. package/src/anyspend/platform/index.ts +129 -0
  193. package/src/anyspend/platform/resources/analytics.ts +10 -0
  194. package/src/anyspend/platform/resources/checkout-sessions.ts +36 -0
  195. package/src/anyspend/platform/resources/customers.ts +54 -0
  196. package/src/anyspend/platform/resources/discount-codes.ts +63 -0
  197. package/src/anyspend/platform/resources/events.ts +22 -0
  198. package/src/anyspend/platform/resources/notifications.ts +37 -0
  199. package/src/anyspend/platform/resources/organization.ts +24 -0
  200. package/src/anyspend/platform/resources/payment-links.ts +74 -0
  201. package/src/anyspend/platform/resources/products.ts +59 -0
  202. package/src/anyspend/platform/resources/transactions.ts +33 -0
  203. package/src/anyspend/platform/resources/webhooks.ts +47 -0
  204. package/src/anyspend/platform/resources/widgets.ts +63 -0
  205. package/src/anyspend/platform/types.ts +532 -0
  206. package/src/anyspend/platform/utils/idempotency.ts +15 -0
  207. package/src/anyspend/platform/utils/pagination.ts +32 -0
  208. package/src/anyspend/react/components/AnySpend.tsx +148 -14
  209. package/src/anyspend/react/components/checkout/AnySpendCheckout.tsx +81 -18
  210. package/src/anyspend/react/components/checkout/AnySpendCheckoutTrigger.tsx +4 -0
  211. package/src/anyspend/react/components/checkout/CheckoutPaymentPanel.tsx +8 -0
  212. package/src/anyspend/react/components/checkout/CryptoPayPanel.tsx +4 -13
  213. package/src/anyspend/react/components/checkout/FiatCheckoutPanel.tsx +86 -17
  214. package/src/anyspend/react/components/checkout/KycGate.tsx +387 -0
  215. package/src/anyspend/react/components/checkout/VariablePricingInput.tsx +247 -0
  216. package/src/anyspend/react/components/index.ts +1 -0
  217. package/src/anyspend/react/hooks/index.ts +1 -0
  218. package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +17 -0
  219. package/src/anyspend/react/hooks/useKycStatus.ts +150 -0
  220. package/src/anyspend/services/anyspend.ts +7 -0
  221. package/src/global-account/react/components/B3DynamicModal.tsx +0 -2
  222. package/src/global-account/react/components/ManageAccount/BottomNavigation.tsx +7 -7
  223. package/src/global-account/react/components/SignInWithB3/SignIn.tsx +1 -1
  224. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +13 -5
  225. package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +1 -1
  226. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +35 -25
  227. package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +1 -1
  228. package/src/global-account/react/hooks/useAuth.ts +2 -2
  229. package/src/global-account/react/hooks/useAuthentication.ts +80 -27
  230. package/src/global-account/react/hooks/useGetAllTWSigners.tsx +2 -1
  231. package/src/global-account/react/stores/useModalStore.ts +6 -0
  232. package/src/global-account/react/utils/createWagmiConfig.tsx +18 -0
@@ -0,0 +1,247 @@
1
+ "use client";
2
+
3
+ import { cn } from "@b3dotfun/sdk/shared/utils/cn";
4
+ import { formatUnits } from "@b3dotfun/sdk/shared/utils/number";
5
+ import { AnimatePresence, motion } from "motion/react";
6
+ import { useCallback, useEffect, useMemo, useState } from "react";
7
+
8
+ export interface VariablePricingConfig {
9
+ enabled: boolean;
10
+ minAmount?: string;
11
+ maxAmount?: string;
12
+ suggestedAmount?: string;
13
+ label?: string;
14
+ currency?: string;
15
+ }
16
+
17
+ interface VariablePricingInputProps {
18
+ config: VariablePricingConfig;
19
+ tokenDecimals: number;
20
+ tokenSymbol: string;
21
+ themeColor?: string;
22
+ onChange: (amountWei: string) => void;
23
+ }
24
+
25
+ export function VariablePricingInput({
26
+ config,
27
+ tokenDecimals,
28
+ tokenSymbol,
29
+ themeColor,
30
+ onChange,
31
+ }: VariablePricingInputProps) {
32
+ const currency = config.currency || tokenSymbol;
33
+
34
+ // Convert suggested amount from wei to display
35
+ const initialValue = useMemo(() => {
36
+ if (config.suggestedAmount) {
37
+ try {
38
+ return formatUnits(config.suggestedAmount, tokenDecimals);
39
+ } catch {
40
+ return "";
41
+ }
42
+ }
43
+ return "";
44
+ }, [config.suggestedAmount, tokenDecimals]);
45
+
46
+ const [displayValue, setDisplayValue] = useState(initialValue);
47
+ const [error, setError] = useState<string | null>(null);
48
+
49
+ // Min/max in display units
50
+ const minDisplay = useMemo(() => {
51
+ if (!config.minAmount) return null;
52
+ try {
53
+ return parseFloat(formatUnits(config.minAmount, tokenDecimals));
54
+ } catch {
55
+ return null;
56
+ }
57
+ }, [config.minAmount, tokenDecimals]);
58
+
59
+ const maxDisplay = useMemo(() => {
60
+ if (!config.maxAmount) return null;
61
+ try {
62
+ return parseFloat(formatUnits(config.maxAmount, tokenDecimals));
63
+ } catch {
64
+ return null;
65
+ }
66
+ }, [config.maxAmount, tokenDecimals]);
67
+
68
+ // Preset amounts
69
+ const presetAmounts = useMemo(() => {
70
+ const presets: { label: string; value: string }[] = [];
71
+
72
+ if (config.suggestedAmount) {
73
+ try {
74
+ const suggested = parseFloat(formatUnits(config.suggestedAmount, tokenDecimals));
75
+ const candidates = [suggested / 2, suggested, suggested * 2];
76
+
77
+ for (const val of candidates) {
78
+ if (val <= 0) continue;
79
+ if (minDisplay !== null && val < minDisplay) continue;
80
+ if (maxDisplay !== null && val > maxDisplay) continue;
81
+ const display = val % 1 === 0 ? val.toString() : val.toFixed(2);
82
+ presets.push({ label: `${display}`, value: display });
83
+ }
84
+ } catch {
85
+ // skip presets
86
+ }
87
+ }
88
+ return presets;
89
+ }, [config.suggestedAmount, tokenDecimals, minDisplay, maxDisplay]);
90
+
91
+ const validate = useCallback(
92
+ (value: string): string | null => {
93
+ const parsed = parseFloat(value);
94
+ if (!value || isNaN(parsed)) return "Please enter a valid number";
95
+ if (parsed <= 0) return "Please enter an amount";
96
+ if (minDisplay !== null && parsed < minDisplay) {
97
+ const display = minDisplay % 1 === 0 ? minDisplay.toString() : minDisplay.toFixed(2);
98
+ return `Minimum amount is ${display} ${currency}`;
99
+ }
100
+ if (maxDisplay !== null && parsed > maxDisplay) {
101
+ const display = maxDisplay % 1 === 0 ? maxDisplay.toString() : maxDisplay.toFixed(2);
102
+ return `Maximum amount is ${display} ${currency}`;
103
+ }
104
+ return null;
105
+ },
106
+ [minDisplay, maxDisplay, currency],
107
+ );
108
+
109
+ const convertToWei = useCallback(
110
+ (value: string): string => {
111
+ try {
112
+ const [whole, frac = ""] = value.split(".");
113
+ const paddedFrac = frac.padEnd(tokenDecimals, "0").slice(0, tokenDecimals);
114
+ const factor = BigInt(10) ** BigInt(tokenDecimals);
115
+ return (BigInt(whole || "0") * factor + BigInt(paddedFrac)).toString();
116
+ } catch {
117
+ return "0";
118
+ }
119
+ },
120
+ [tokenDecimals],
121
+ );
122
+
123
+ const handleChange = useCallback(
124
+ (value: string) => {
125
+ setDisplayValue(value);
126
+ const validationError = validate(value);
127
+ setError(validationError);
128
+
129
+ if (!validationError && value && parseFloat(value) > 0) {
130
+ onChange(convertToWei(value));
131
+ } else {
132
+ onChange("0");
133
+ }
134
+ },
135
+ [validate, convertToWei, onChange],
136
+ );
137
+
138
+ const handlePresetClick = useCallback(
139
+ (value: string) => {
140
+ setDisplayValue(value);
141
+ setError(null);
142
+ onChange(convertToWei(value));
143
+ },
144
+ [convertToWei, onChange],
145
+ );
146
+
147
+ // Notify parent with initial value on mount
148
+ useEffect(() => {
149
+ if (initialValue && !validate(initialValue)) {
150
+ onChange(convertToWei(initialValue));
151
+ }
152
+ // eslint-disable-next-line react-hooks/exhaustive-deps
153
+ }, []);
154
+
155
+ const formatHint = () => {
156
+ if (minDisplay !== null && maxDisplay !== null) {
157
+ const minStr = minDisplay % 1 === 0 ? minDisplay.toString() : minDisplay.toFixed(2);
158
+ const maxStr = maxDisplay % 1 === 0 ? maxDisplay.toString() : maxDisplay.toFixed(2);
159
+ return `${minStr} – ${maxStr} ${currency}`;
160
+ }
161
+ if (minDisplay !== null) {
162
+ const minStr = minDisplay % 1 === 0 ? minDisplay.toString() : minDisplay.toFixed(2);
163
+ return `Min: ${minStr} ${currency}`;
164
+ }
165
+ if (maxDisplay !== null) {
166
+ const maxStr = maxDisplay % 1 === 0 ? maxDisplay.toString() : maxDisplay.toFixed(2);
167
+ return `Max: ${maxStr} ${currency}`;
168
+ }
169
+ return null;
170
+ };
171
+
172
+ const hint = formatHint();
173
+
174
+ return (
175
+ <div className="anyspend-variable-pricing mb-6">
176
+ <label
177
+ htmlFor="variable-pricing-amount"
178
+ className="mb-3 block text-lg font-semibold text-gray-900 dark:text-gray-100"
179
+ >
180
+ {config.label || "Enter amount"}
181
+ </label>
182
+
183
+ {/* Preset buttons */}
184
+ {presetAmounts.length > 0 && (
185
+ <div className="mb-3 flex flex-wrap gap-2">
186
+ {presetAmounts.map(preset => (
187
+ <button
188
+ key={preset.value}
189
+ type="button"
190
+ onClick={() => handlePresetClick(preset.value)}
191
+ className={cn(
192
+ "rounded-full border px-4 py-2 text-sm font-medium transition-colors",
193
+ displayValue === preset.value
194
+ ? "border-transparent text-white"
195
+ : "border-gray-200 text-gray-700 hover:bg-gray-50 dark:border-neutral-600 dark:text-gray-300 dark:hover:bg-neutral-800",
196
+ )}
197
+ style={
198
+ displayValue === preset.value ? { backgroundColor: themeColor || "hsl(var(--as-brand))" } : undefined
199
+ }
200
+ >
201
+ {preset.label} {currency}
202
+ </button>
203
+ ))}
204
+ </div>
205
+ )}
206
+
207
+ {/* Input */}
208
+ <div className="relative">
209
+ <input
210
+ id="variable-pricing-amount"
211
+ type="text"
212
+ inputMode="decimal"
213
+ value={displayValue}
214
+ onChange={e => {
215
+ // Normalize comma decimal separators for locale compatibility
216
+ const normalized = e.target.value.replace(",", ".");
217
+ handleChange(normalized);
218
+ }}
219
+ className="w-full rounded-xl border border-gray-200 bg-gray-50 px-4 py-3.5 pr-16 text-lg font-semibold text-gray-900 placeholder:text-gray-300 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:border-neutral-600 dark:bg-neutral-800 dark:text-gray-100 dark:placeholder:text-neutral-600 dark:focus:border-blue-400"
220
+ placeholder="0.00"
221
+ />
222
+ <span className="absolute right-4 top-1/2 -translate-y-1/2 text-sm font-medium text-gray-400 dark:text-gray-500">
223
+ {currency}
224
+ </span>
225
+ </div>
226
+
227
+ {/* Hint */}
228
+ {hint && <p className="mt-1.5 text-xs text-gray-500 dark:text-gray-400">{hint}</p>}
229
+
230
+ {/* Error */}
231
+ <AnimatePresence initial={false}>
232
+ {error && (
233
+ <motion.p
234
+ key="variable-price-error"
235
+ initial={{ opacity: 0, height: 0 }}
236
+ animate={{ opacity: 1, height: "auto" }}
237
+ exit={{ opacity: 0, height: 0 }}
238
+ transition={{ duration: 0.15, ease: "easeOut" }}
239
+ className="mt-1.5 text-sm text-red-500"
240
+ >
241
+ {error}
242
+ </motion.p>
243
+ )}
244
+ </AnimatePresence>
245
+ </div>
246
+ );
247
+ }
@@ -10,6 +10,7 @@ export type {
10
10
  ShippingOption,
11
11
  DiscountResult,
12
12
  AddressData,
13
+ VariablePricingConfig,
13
14
  } from "./checkout/AnySpendCheckout";
14
15
  export { AnySpendCheckoutTrigger } from "./checkout/AnySpendCheckoutTrigger";
15
16
  export type { AnySpendCheckoutTriggerProps } from "./checkout/AnySpendCheckoutTrigger";
@@ -18,3 +18,4 @@ export * from "./useSigMint";
18
18
  export * from "./useStripeClientSecret";
19
19
  export * from "./useStripeSupport";
20
20
  export * from "./useWatchTransfer";
21
+ export * from "./useKycStatus";
@@ -11,7 +11,9 @@ import { useMemo } from "react";
11
11
 
12
12
  import { parseUnits } from "viem";
13
13
  import { base } from "viem/chains";
14
+ import { useAccount } from "wagmi";
14
15
  import { CreateOrderParams } from "./useAnyspendCreateOrder";
16
+ import { getCachedWalletHeaders } from "./useKycStatus";
15
17
  import { useValidatedClientReferenceId } from "./useValidatedClientReferenceId";
16
18
 
17
19
  export type OnrampOptions = {
@@ -24,6 +26,8 @@ export type OnrampOptions = {
24
26
  export type CreateOnrampOrderParams = Omit<CreateOrderParams, "srcChain" | "srcToken" | "srcAmount"> & {
25
27
  srcFiatAmount: string;
26
28
  onramp: OnrampOptions;
29
+ /** When true, fees are added on top of srcAmount (payer pays more, receiver gets exact amount) */
30
+ feeOnTop?: boolean;
27
31
  };
28
32
 
29
33
  export type UseAnyspendCreateOnrampOrderProps = {
@@ -38,6 +42,7 @@ export type UseAnyspendCreateOnrampOrderProps = {
38
42
  export function useAnyspendCreateOnrampOrder({ onSuccess, onError }: UseAnyspendCreateOnrampOrderProps = {}) {
39
43
  // Get B3 context values
40
44
  const { partnerId } = useB3Config();
45
+ const { address } = useAccount();
41
46
 
42
47
  // Get validated client reference ID from B3 context
43
48
  const createValidatedClientReferenceId = useValidatedClientReferenceId();
@@ -79,6 +84,16 @@ export function useAnyspendCreateOnrampOrder({ onSuccess, onError }: UseAnyspend
79
84
  // Create order with USDC on Base as source
80
85
  const srcAmountOnRampInWei = parseUnits(srcFiatAmount, USDC_BASE.decimals);
81
86
 
87
+ // For card payments, include wallet auth headers so the backend can verify
88
+ // KYC by the signing wallet address (may differ from the B3 JWT address).
89
+ // Only use already-cached headers — never trigger a fresh wallet signature
90
+ // here, as that would prompt the user without their explicit consent.
91
+ // KycGate pre-caches the headers in the "Continue to Verify" user-gesture.
92
+ let kycWalletHeaders: Record<string, string> | undefined;
93
+ if (onramp.vendor === "stripe-web2" && address) {
94
+ kycWalletHeaders = getCachedWalletHeaders(address);
95
+ }
96
+
82
97
  return await anyspendService.createOrder({
83
98
  recipientAddress: normalizeAddress(recipientAddress),
84
99
  type: orderType,
@@ -115,6 +130,8 @@ export function useAnyspendCreateOnrampOrder({ onSuccess, onError }: UseAnyspend
115
130
  clientReferenceId,
116
131
  visitorData,
117
132
  callbackMetadata: params.callbackMetadata,
133
+ feeOnTop: params.feeOnTop,
134
+ kycWalletHeaders,
118
135
  });
119
136
  } catch (error: any) {
120
137
  // If the error has a response with message and statusCode, throw that
@@ -0,0 +1,150 @@
1
+ "use client";
2
+
3
+ import { ANYSPEND_MAINNET_BASE_URL } from "@b3dotfun/sdk/anyspend/constants";
4
+ import { useMutation, useQuery } from "@tanstack/react-query";
5
+ import { useCallback } from "react";
6
+ import { useAccount, useSignMessage } from "wagmi";
7
+
8
+ export interface KycStatusResponse {
9
+ kycRequired: boolean;
10
+ status: "not_verified" | "pending" | "completed" | "approved" | "declined" | "needs_review" | "expired";
11
+ inquiry?: {
12
+ inquiryId: string;
13
+ sessionToken: string;
14
+ };
15
+ config?: {
16
+ templateId: string;
17
+ environment: string;
18
+ };
19
+ }
20
+
21
+ interface KycInquiryResponse {
22
+ inquiryId: string;
23
+ sessionToken: string;
24
+ }
25
+
26
+ interface KycVerifyResponse {
27
+ status: string;
28
+ }
29
+
30
+ function buildWalletAuthMessage(walletAddress: string, timestamp: number): string {
31
+ return `AnySpend wants to verify your identity for card payments.\n\nThis signature does not trigger a blockchain transaction or cost any gas.\n\nWallet: ${walletAddress.toLowerCase()}\nNonce: ${timestamp}`;
32
+ }
33
+
34
+ /** Module-level signature cache to avoid repeated wallet prompts within the 5-minute window. */
35
+ const headerCache = new Map<string, { headers: Record<string, string>; expiresAt: number }>();
36
+
37
+ /**
38
+ * Returns cached wallet auth headers without triggering a wallet signature prompt.
39
+ * Returns undefined if no valid cache exists for the given address.
40
+ */
41
+ export function getCachedWalletHeaders(address: string): Record<string, string> | undefined {
42
+ const cached = headerCache.get(address.toLowerCase());
43
+ if (cached && Date.now() < cached.expiresAt) return cached.headers;
44
+ return undefined;
45
+ }
46
+
47
+ /**
48
+ * Returns a function that builds the wallet-signature auth headers.
49
+ * Caches signatures for 4 minutes (server allows 5-minute window).
50
+ */
51
+ export function useWalletAuthHeaders() {
52
+ const { address } = useAccount();
53
+ const { signMessageAsync } = useSignMessage();
54
+
55
+ const getHeaders = useCallback(async (): Promise<Record<string, string>> => {
56
+ if (!address) throw new Error("No wallet connected");
57
+ const walletAddress = address.toLowerCase();
58
+
59
+ const cached = headerCache.get(walletAddress);
60
+ if (cached && Date.now() < cached.expiresAt) return cached.headers;
61
+
62
+ const timestamp = Math.floor(Date.now() / 1000);
63
+ const message = buildWalletAuthMessage(walletAddress, timestamp);
64
+ const signature = await signMessageAsync({ message });
65
+
66
+ const headers = {
67
+ "X-Wallet-Address": walletAddress,
68
+ "X-Wallet-Signature": signature,
69
+ "X-Wallet-Timestamp": String(timestamp),
70
+ };
71
+ // Cache for 4 minutes so repeated fetches don't re-prompt the user
72
+ headerCache.set(walletAddress, { headers, expiresAt: Date.now() + 4 * 60 * 1000 });
73
+ return headers;
74
+ }, [address, signMessageAsync]);
75
+
76
+ return { address, getHeaders };
77
+ }
78
+
79
+ export function useKycStatus(enabled = true) {
80
+ const { address, getHeaders } = useWalletAuthHeaders();
81
+
82
+ const { data, isLoading, error, refetch } = useQuery({
83
+ queryKey: ["kyc-status", address],
84
+ queryFn: async () => {
85
+ const headers = await getHeaders();
86
+ const response = await fetch(`${ANYSPEND_MAINNET_BASE_URL}/kyc/status`, { headers });
87
+ const json = await response.json();
88
+ if (!response.ok) throw new Error(json.message || "Failed to fetch KYC status");
89
+ return json.data as KycStatusResponse;
90
+ },
91
+ enabled: enabled && !!address,
92
+ staleTime: 30_000,
93
+ retry: 0,
94
+ refetchOnWindowFocus: false,
95
+ });
96
+
97
+ return {
98
+ kycStatus: data || null,
99
+ isLoadingKycStatus: isLoading,
100
+ kycStatusError: error,
101
+ refetchKycStatus: refetch,
102
+ };
103
+ }
104
+
105
+ export function useCreateKycInquiry() {
106
+ const { address, getHeaders } = useWalletAuthHeaders();
107
+
108
+ const { mutateAsync, isPending } = useMutation({
109
+ mutationFn: async () => {
110
+ if (!address) throw new Error("No wallet connected");
111
+ const headers = await getHeaders();
112
+ const response = await fetch(`${ANYSPEND_MAINNET_BASE_URL}/kyc/inquiry`, {
113
+ method: "POST",
114
+ headers: { "Content-Type": "application/json", ...headers },
115
+ });
116
+ const json = await response.json();
117
+ if (!response.ok) throw new Error(json.message || "Failed to create KYC inquiry");
118
+ return json.data as KycInquiryResponse;
119
+ },
120
+ });
121
+
122
+ return {
123
+ createInquiry: mutateAsync,
124
+ isCreatingInquiry: isPending,
125
+ };
126
+ }
127
+
128
+ export function useVerifyKyc() {
129
+ const { address, getHeaders } = useWalletAuthHeaders();
130
+
131
+ const { mutateAsync, isPending } = useMutation({
132
+ mutationFn: async (inquiryId: string) => {
133
+ if (!address) throw new Error("No wallet connected");
134
+ const headers = await getHeaders();
135
+ const response = await fetch(`${ANYSPEND_MAINNET_BASE_URL}/kyc/verify`, {
136
+ method: "POST",
137
+ headers: { "Content-Type": "application/json", ...headers },
138
+ body: JSON.stringify({ inquiryId }),
139
+ });
140
+ const json = await response.json();
141
+ if (!response.ok) throw new Error(json.message || "Failed to verify KYC");
142
+ return json.data as KycVerifyResponse;
143
+ },
144
+ });
145
+
146
+ return {
147
+ verifyKyc: mutateAsync,
148
+ isVerifying: isPending,
149
+ };
150
+ }
@@ -72,6 +72,8 @@ export const anyspendService = {
72
72
  clientReferenceId,
73
73
  visitorData,
74
74
  callbackMetadata,
75
+ feeOnTop,
76
+ kycWalletHeaders,
75
77
  }: {
76
78
  recipientAddress: string;
77
79
  type: string;
@@ -88,6 +90,9 @@ export const anyspendService = {
88
90
  clientReferenceId?: string;
89
91
  visitorData?: VisitorData;
90
92
  callbackMetadata?: Record<string, unknown>;
93
+ feeOnTop?: boolean;
94
+ /** Wallet signature auth headers for KYC lookup (stripe-web2 orders only). */
95
+ kycWalletHeaders?: Record<string, string>;
91
96
  }) => {
92
97
  const accessToken = await app.authentication.getAccessToken();
93
98
  const response = await fetch(`${ANYSPEND_MAINNET_BASE_URL}/orders`, {
@@ -97,6 +102,7 @@ export const anyspendService = {
97
102
  ...(visitorData?.requestId && { "X-Fingerprint-Request-Id": visitorData.requestId }),
98
103
  ...(visitorData?.visitorId && { "X-Fingerprint-Visitor-Id": visitorData.visitorId }),
99
104
  ...(accessToken && { Authorization: `Bearer ${accessToken}` }),
105
+ ...kycWalletHeaders,
100
106
  },
101
107
  body: JSON.stringify({
102
108
  recipientAddress,
@@ -113,6 +119,7 @@ export const anyspendService = {
113
119
  partnerId,
114
120
  ...(clientReferenceId && { clientReferenceId }),
115
121
  ...(callbackMetadata && { callbackMetadata }),
122
+ ...(feeOnTop != null && { feeOnTop }),
116
123
  }),
117
124
  });
118
125
  const data: CreateOrderResponse = await response.json();
@@ -210,8 +210,6 @@ export function B3DynamicModal() {
210
210
  hideCloseButton={hideCloseButton}
211
211
  hideGABranding={isAnySpendType}
212
212
  onEscapeKeyDown={!isClosable ? e => e.preventDefault() : undefined}
213
- onPointerDownOutside={!isClosable ? e => e.preventDefault() : undefined}
214
- onInteractOutside={!isClosable ? e => e.preventDefault() : undefined}
215
213
  >
216
214
  <ModalTitle className="sr-only hidden">{contentType?.type || "Modal"}</ModalTitle>
217
215
  <ModalDescription className="sr-only hidden">{contentType?.type || "Modal Body"}</ModalDescription>
@@ -4,8 +4,8 @@ const HomeIcon = () => {
4
4
  return (
5
5
  <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
6
6
  <path
7
- fill-rule="evenodd"
8
- clip-rule="evenodd"
7
+ fillRule="evenodd"
8
+ clipRule="evenodd"
9
9
  d="M12.5227 1.33636C12.1804 1.24368 11.8196 1.24368 11.4773 1.33636C11.08 1.44395 10.7454 1.7066 10.4784 1.91623L10.4038 1.97465L3.54376 7.31012C3.16713 7.6024 2.83532 7.85991 2.58806 8.19421C2.37107 8.48759 2.20942 8.8181 2.11106 9.1695C1.99898 9.56992 1.99943 9.98993 1.99995 10.4667L2.00002 17.8385C2 18.3657 1.99998 18.8204 2.03059 19.195C2.06289 19.5904 2.1342 19.9836 2.327 20.362C2.61462 20.9264 3.07356 21.3854 3.63805 21.673C4.01643 21.8658 4.40964 21.9371 4.80499 21.9694C5.17956 22 5.63431 22 6.16145 22H17.8386C18.3657 22 18.8205 22 19.195 21.9694C19.5904 21.9371 19.9836 21.8658 20.362 21.673C20.9265 21.3854 21.3854 20.9264 21.673 20.362C21.8658 19.9836 21.9371 19.5904 21.9694 19.195C22.0001 18.8204 22 18.3657 22 17.8386L22.0001 10.4667C22.0006 9.98993 22.0011 9.56992 21.889 9.1695C21.7906 8.8181 21.629 8.48759 21.412 8.19421C21.1647 7.8599 20.8329 7.6024 20.4563 7.31011L13.5963 1.97465L13.5216 1.91623C13.2546 1.7066 12.9201 1.44395 12.5227 1.33636ZM8.00003 16C7.44775 16 7.00003 16.4477 7.00003 17C7.00003 17.5523 7.44775 18 8.00003 18H16C16.5523 18 17 17.5523 17 17C17 16.4477 16.5523 16 16 16H8.00003Z"
10
10
  fill="currentColor"
11
11
  />
@@ -19,9 +19,9 @@ const SwapIcon = () => {
19
19
  <path
20
20
  d="M20.4533 12.893C20.1755 15.5029 18.6968 17.9487 16.2498 19.3614C12.1843 21.7086 6.98576 20.3157 4.63855 16.2502L4.38855 15.8172M3.5465 11.107C3.8243 8.49711 5.30309 6.05138 7.75007 4.63862C11.8156 2.29141 17.0141 3.68434 19.3613 7.74983L19.6113 8.18285M3.49353 18.0661L4.22558 15.334L6.95763 16.0661M17.0428 7.93401L19.7748 8.66606L20.5069 5.93401"
21
21
  stroke="currentColor"
22
- stroke-width="2"
23
- stroke-linecap="round"
24
- stroke-linejoin="round"
22
+ strokeWidth="2"
23
+ strokeLinecap="round"
24
+ strokeLinejoin="round"
25
25
  />
26
26
  </svg>
27
27
  );
@@ -31,8 +31,8 @@ const SettingsIcon = () => {
31
31
  return (
32
32
  <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
33
33
  <path
34
- fill-rule="evenodd"
35
- clip-rule="evenodd"
34
+ fillRule="evenodd"
35
+ clipRule="evenodd"
36
36
  d="M19.286 15.9606C19.2272 15.6362 19.2669 15.3016 19.4 15C19.5268 14.7042 19.7372 14.452 20.0055 14.2743C20.2738 14.0966 20.5882 14.0013 20.91 14H21C21.5304 14 22.0391 13.7893 22.4142 13.4142C22.7893 13.0391 23 12.5304 23 12C23 11.4696 22.7893 10.9609 22.4142 10.5858C22.0391 10.2107 21.5304 10 21 10H20.83C20.5082 9.99872 20.1938 9.90337 19.9255 9.72569C19.6572 9.54802 19.4468 9.29577 19.32 9V8.92C19.1869 8.61838 19.1472 8.28381 19.206 7.95941C19.2648 7.63502 19.4195 7.33568 19.65 7.1L19.71 7.04C19.896 6.85425 20.0435 6.63368 20.1441 6.39088C20.2448 6.14808 20.2966 5.88783 20.2966 5.625C20.2966 5.36217 20.2448 5.10192 20.1441 4.85912C20.0435 4.61632 19.896 4.39575 19.71 4.21C19.5243 4.02405 19.3037 3.87653 19.0609 3.77588C18.8181 3.67523 18.5578 3.62343 18.295 3.62343C18.0322 3.62343 17.7719 3.67523 17.5291 3.77588C17.2863 3.87653 17.0657 4.02405 16.88 4.21L16.82 4.27C16.5843 4.50054 16.285 4.65519 15.9606 4.714C15.6362 4.77282 15.3016 4.73312 15 4.6C14.7042 4.47324 14.452 4.26276 14.2743 3.99447C14.0966 3.72618 14.0013 3.41179 14 3.09V3C14 2.46957 13.7893 1.96086 13.4142 1.58579C13.0391 1.21071 12.5304 1 12 1C11.4696 1 10.9609 1.21071 10.5858 1.58579C10.2107 1.96086 10 2.46957 10 3V3.17C9.99872 3.49179 9.90337 3.80618 9.72569 4.07447C9.54802 4.34276 9.29577 4.55324 9 4.68H8.92C8.61838 4.81312 8.28381 4.85282 7.95941 4.794C7.63502 4.73519 7.33568 4.58054 7.1 4.35L7.04 4.29C6.85425 4.10405 6.63368 3.95653 6.39088 3.85588C6.14808 3.75523 5.88783 3.70343 5.625 3.70343C5.36217 3.70343 5.10192 3.75523 4.85912 3.85588C4.61632 3.95653 4.39575 4.10405 4.21 4.29C4.02405 4.47575 3.87653 4.69632 3.77588 4.93912C3.67523 5.18192 3.62343 5.44217 3.62343 5.705C3.62343 5.96783 3.67523 6.22808 3.77588 6.47088C3.87653 6.71368 4.02405 6.93425 4.21 7.12L4.27 7.18C4.50054 7.41568 4.65519 7.71502 4.714 8.03941C4.77282 8.36381 4.73312 8.69838 4.6 9C4.48572 9.31074 4.28059 9.5799 4.0113 9.77251C3.742 9.96512 3.42099 10.0723 3.09 10.08H3C2.46957 10.08 1.96086 10.2907 1.58579 10.6658C1.21071 11.0409 1 11.5496 1 12.08C1 12.6104 1.21071 13.1191 1.58579 13.4942C1.96086 13.8693 2.46957 14.08 3 14.08H3.17C3.49179 14.0813 3.80618 14.1766 4.07447 14.3543C4.34276 14.532 4.55324 14.7842 4.68 15.08C4.81312 15.3816 4.85282 15.7162 4.794 16.0406C4.73519 16.365 4.58054 16.6643 4.35 16.9L4.29 16.96C4.10405 17.1457 3.95653 17.3663 3.85588 17.6091C3.75523 17.8519 3.70343 18.1122 3.70343 18.375C3.70343 18.6378 3.75523 18.8981 3.85588 19.1409C3.95653 19.3837 4.10405 19.6043 4.29 19.79C4.47575 19.976 4.69632 20.1235 4.93912 20.2241C5.18192 20.3248 5.44217 20.3766 5.705 20.3766C5.96783 20.3766 6.22808 20.3248 6.47088 20.2241C6.71368 20.1235 6.93425 19.976 7.12 19.79L7.18 19.73C7.41568 19.4995 7.71502 19.3448 8.03941 19.286C8.36381 19.2272 8.69838 19.2669 9 19.4C9.31074 19.5143 9.5799 19.7194 9.77251 19.9887C9.96512 20.258 10.0723 20.579 10.08 20.91V21C10.08 21.5304 10.2907 22.0391 10.6658 22.4142C11.0409 22.7893 11.5496 23 12.08 23C12.6104 23 13.1191 22.7893 13.4942 22.4142C13.8693 22.0391 14.08 21.5304 14.08 21V20.83C14.0813 20.5082 14.1766 20.1938 14.3543 19.9255C14.532 19.6572 14.7842 19.4468 15.08 19.32C15.3816 19.1869 15.7162 19.1472 16.0406 19.206C16.365 19.2648 16.6643 19.4195 16.9 19.65L16.96 19.71C17.1457 19.896 17.3663 20.0435 17.6091 20.1441C17.8519 20.2448 18.1122 20.2966 18.375 20.2966C18.6378 20.2966 18.8981 20.2448 19.1409 20.1441C19.3837 20.0435 19.6043 19.896 19.79 19.71C19.976 19.5243 20.1235 19.3037 20.2241 19.0609C20.3248 18.8181 20.3766 18.5578 20.3766 18.295C20.3766 18.0322 20.3248 17.7719 20.2241 17.5291C20.1235 17.2863 19.976 17.0657 19.79 16.88L19.73 16.82C19.4995 16.5843 19.3448 16.285 19.286 15.9606ZM15 12C15 13.6569 13.6569 15 12 15C10.3431 15 9 13.6569 9 12C9 10.3431 10.3431 9 12 9C13.6569 9 15 10.3431 15 12Z"
37
37
  fill="currentColor"
38
38
  />
@@ -44,7 +44,7 @@ export function SignIn(props: SignInWithB3Props) {
44
44
  const { data: walletImage } = useWalletImage(connectedEOAWallet?.id);
45
45
 
46
46
  const isMobile = useIsMobile();
47
- const { logout } = useAuthentication(partnerId);
47
+ const { logout } = useAuthentication(partnerId, { skipAutoConnect: true });
48
48
  const onDisconnect = async (): Promise<void> => {
49
49
  await logout();
50
50
  };
@@ -35,16 +35,23 @@ export function SignInWithB3Flow({
35
35
  signersEnabled = false,
36
36
  }: SignInWithB3ModalProps) {
37
37
  const { automaticallySetFirstEoa } = useB3Config();
38
- const { user, logout } = useAuthentication(partnerId);
38
+ // skipAutoConnect: this component intentionally logs out on mount to show a fresh login screen.
39
+ // AuthenticationProvider is the sole owner of useAutoConnect to avoid competing auth cycles.
40
+ const { user, logout } = useAuthentication(partnerId, { skipAutoConnect: true });
39
41
 
40
- // FIXME Logout before login to ensure a clean state
42
+ // Tracks whether the pre-login logout has finished.
43
+ // We must not render ConnectEmbed until logout (wallet disconnect) completes,
44
+ // otherwise the wallet state disrupts ConnectEmbed causing a blank modal.
45
+ const [readyToShowLogin, setReadyToShowLogin] = useState(source === "requestPermissions");
41
46
  const hasLoggedOutRef = useRef(false);
42
47
  useEffect(() => {
43
48
  if (hasLoggedOutRef.current) return;
44
49
  if (source !== "requestPermissions") {
45
50
  debug("Logging out before login");
46
- logout();
47
51
  hasLoggedOutRef.current = true;
52
+ logout().finally(() => {
53
+ setReadyToShowLogin(true);
54
+ });
48
55
  }
49
56
  }, [source, logout]);
50
57
 
@@ -275,8 +282,9 @@ export function SignInWithB3Flow({
275
282
  </LoginStepContainer>
276
283
  );
277
284
  } else if (step === "login") {
278
- // Show loading spinner
279
- if (isAuthenticating || (isFetchingSigners && step === "login") || source === "requestPermissions") {
285
+ // Show loading spinner while: authenticating, waiting for pre-login logout to finish,
286
+ // or fetching signers.
287
+ if (!readyToShowLogin || isAuthenticating || isFetchingSigners) {
280
288
  content = (
281
289
  <LoginStepContainer partnerId={partnerId}>
282
290
  <div className="my-8 flex min-h-[350px] items-center justify-center">
@@ -23,7 +23,7 @@ export function SignInWithB3Privy({ onSuccess, onError, chain }: SignInWithB3Pri
23
23
  const { isLoading, connectTw, fullToken } = useHandleConnectWithPrivy(chain, onSuccess);
24
24
  const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
25
25
  const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
26
- const { logout } = useAuthentication(partnerId);
26
+ const { logout } = useAuthentication(partnerId, { skipAutoConnect: true });
27
27
 
28
28
  debug("@@SignInWithB3Privy", {
29
29
  isLoading,