@stridge/kit 0.1.0-alpha.18 → 0.1.0-alpha.19

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.
@@ -1 +1 @@
1
- "use client";import{KitStorageProvider as e}from"./storage/context.js";import"./storage/index.js";import{DepositDriverProvider as t}from"./flows/deposit/driver/context.js";import{getLocaleDirection as n}from"./shared/i18n/getLocaleDirection.js";import{KitI18nProvider as r}from"./shared/i18n/KitI18nProvider.js";import"./i18n/index.js";import{GatewayController as i}from"./flows/deposit/orchestrator/controller.js";import{WithdrawDriverProvider as a}from"./flows/withdraw/driver/context.js";import{WithdrawDialogBindingsProvider as o}from"./flows/withdraw/dialog/WithdrawDialogBindingsContext.js";import{WithdrawControllerProvider as s}from"./flows/withdraw/orchestrator/controller.js";import{KitScope as c}from"./scope/KitScope.js";import"./scope/index.js";import{SupportConfigContext as l}from"./shared/support/SupportConfigContext.js";import{useMemo as u}from"react";import{jsx as d}from"react/jsx-runtime";function f({children:f,i18n:p,direction:m,deposit:h,withdraw:g,storage:_,storageNamespace:v,support:y,merchantContext:b,attribution:x=`visible`,...S}){let C=n(p?.locale),w=f;g&&(w=d(o,{children:d(a,{driver:g,children:d(s,{children:w})})})),h&&(w=d(t,{driver:h,children:d(i,{children:w})}));let T=u(()=>({config:y,merchantContext:b??null}),[y,b]),E=y!==void 0||b!==void 0,D=d(r,{locale:p?.locale,messages:p?.messages,children:d(c,{...S,direction:m??C,locale:p?.locale,attribution:x,children:d(e,{storage:_,namespace:v,children:w})})});return E?d(l.Provider,{value:T,children:D}):D}export{f as KitProvider};
1
+ "use client";import{KitStorageProvider as e}from"./storage/context.js";import"./storage/index.js";import{DepositDriverProvider as t}from"./flows/deposit/driver/context.js";import{getLocaleDirection as n}from"./shared/i18n/getLocaleDirection.js";import{KitI18nProvider as r}from"./shared/i18n/KitI18nProvider.js";import"./i18n/index.js";import{GatewayController as i}from"./flows/deposit/orchestrator/controller.js";import{WithdrawBindingsProvider as a}from"./flows/withdraw/bindings/WithdrawBindings.js";import"./flows/withdraw/bindings/index.js";import{WithdrawDriverProvider as o}from"./flows/withdraw/driver/context.js";import{WithdrawControllerProvider as s}from"./flows/withdraw/orchestrator/controller.js";import{KitScope as c}from"./scope/KitScope.js";import"./scope/index.js";import{SupportConfigContext as l}from"./shared/support/SupportConfigContext.js";import{useMemo as u}from"react";import{jsx as d}from"react/jsx-runtime";function f({children:f,i18n:p,direction:m,deposit:h,withdraw:g,storage:_,storageNamespace:v,support:y,merchantContext:b,attribution:x=`visible`,...S}){let C=n(p?.locale),w=f;g&&(w=d(a,{children:d(o,{driver:g,children:d(s,{children:w})})})),h&&(w=d(t,{driver:h,children:d(i,{children:w})}));let T=u(()=>({config:y,merchantContext:b??null}),[y,b]),E=y!==void 0||b!==void 0,D=d(r,{locale:p?.locale,messages:p?.messages,children:d(c,{...S,direction:m??C,locale:p?.locale,attribution:x,children:d(e,{storage:_,namespace:v,children:w})})});return E?d(l.Provider,{value:T,children:D}):D}export{f as KitProvider};
@@ -0,0 +1,92 @@
1
+ import { WithdrawSubmitCallback } from "../orchestrator/types.js";
2
+ import { ReactNode } from "react";
3
+ //#region src/flows/withdraw/bindings/WithdrawBindings.d.ts
4
+ /**
5
+ * Withdrawable balance the host surfaces to the withdraw form. Two accepted forms:
6
+ *
7
+ * - `number` — bare amount in display units (kit infers symbol from the provider-level
8
+ * `asset.symbol`; USD value is derived for known stablecoins or hidden otherwise).
9
+ * - `{ amount, amountUsd? }` — explicit amount plus optional pre-computed USD value.
10
+ *
11
+ * `undefined` represents the loading state — the kit renders a skeleton / em-dashes instead
12
+ * of a value.
13
+ */
14
+ type WithdrawBalanceInput = number | {
15
+ amount: number;
16
+ amountUsd?: number;
17
+ };
18
+ /**
19
+ * Trusted-recipient prefill chip surfaced next to the recipient address input. The kit no
20
+ * longer auto-derives a chip from `wagmi.address` — that misled users on embedded-wallet
21
+ * integrations, where `wagmi.address` is the integration's generated wallet rather than the
22
+ * user's primary self-custodial wallet. Hosts that have a verified, user-trusted address (a
23
+ * saved wallet on the user's profile, a KYC-bound payout destination, a whitelisted withdrawal
24
+ * address) pass it via {@link useWithdrawBindings} (or the `<WithdrawDialog>` prop of the same
25
+ * name); the chip's `aria-label` reads off `label` so the affordance is unambiguous about which
26
+ * address the user is filling with.
27
+ */
28
+ interface WithdrawSuggestedRecipient {
29
+ /** Address that fills the recipient input when the chip is clicked. */
30
+ address: string;
31
+ /**
32
+ * Short human label for the chip — used as the accessible name (`aria-label`) so screen
33
+ * readers and click targets describe the saved address concretely (e.g. `"Saved wallet"`,
34
+ * `"Your verified address"`). When omitted, the chip falls back to a generic kit-default.
35
+ */
36
+ label?: string;
37
+ /**
38
+ * Receive-side chain id this address belongs to (EIP-155 numeric). When set, the chip is
39
+ * surfaced only while the form's selected receive chain matches — prevents the user from
40
+ * one-click-filling an Ethereum address while routing to BSC, etc. When omitted, the chip
41
+ * is surfaced unconditionally and address-chain compatibility is the integrator's concern.
42
+ */
43
+ chainId?: number;
44
+ }
45
+ /**
46
+ * Render-time inputs the host supplies to the withdraw flow. Whoever renders the withdraw UI —
47
+ * the kit's `<WithdrawDialog>` or a fully custom headless surface — publishes these via
48
+ * {@link useWithdrawBindings}. Form widgets read the display values reactively; the orchestrator's
49
+ * submit action reads `onSubmit` at submit time to fire the host's callback.
50
+ */
51
+ interface WithdrawBindings {
52
+ /** Host-supplied source-side balance the form renders. */
53
+ balance?: WithdrawBalanceInput;
54
+ /**
55
+ * Host-supplied submit handler. Fired when the user submits the form (after the kit has
56
+ * prepared a fresh UDA target). The host calls the supplied actions to advance the FSM at
57
+ * the points its backend reaches the matching state.
58
+ */
59
+ onSubmit?: WithdrawSubmitCallback;
60
+ /**
61
+ * Trusted recipient address surfaced as a prefill chip on the recipient field. See
62
+ * {@link WithdrawSuggestedRecipient}.
63
+ */
64
+ suggestedRecipient?: WithdrawSuggestedRecipient;
65
+ }
66
+ /**
67
+ * Publish the host's render-time withdraw inputs (`balance`, `onSubmit`, `suggestedRecipient`)
68
+ * into the kit's withdraw scope. Call it once from whatever component renders the withdraw UI:
69
+ *
70
+ * - The kit's `<WithdrawDialog>` calls it internally with its render-time props.
71
+ * - A **headless** host that renders fully custom withdraw UI from `useWithdraw()` /
72
+ * `useWithdrawState()` / `useWithdrawSnapshot()` calls it directly — it's the supported way
73
+ * to wire `onSubmit` (and the optional display inputs) without mounting the dialog.
74
+ *
75
+ * Writes synchronously to the bridge ref during render so the controller's submit action always
76
+ * reads the latest `onSubmit`; a deferred `setState` updates the reactive state read by display
77
+ * widgets. Clears the bridge on unmount.
78
+ *
79
+ * @example Headless usage
80
+ * ```tsx
81
+ * useWithdrawBindings({
82
+ * balance: walletBalance,
83
+ * onSubmit: async (input, actions) => {
84
+ * const txHash = await backend.broadcastWithdrawal(input.depositTarget);
85
+ * actions.beginProcessing({ hash: txHash });
86
+ * },
87
+ * });
88
+ * ```
89
+ */
90
+ declare function useWithdrawBindings(bindings: WithdrawBindings): void;
91
+ //#endregion
92
+ export { WithdrawBalanceInput, WithdrawBindings, WithdrawSuggestedRecipient, useWithdrawBindings };
@@ -0,0 +1 @@
1
+ "use client";import{createContext as e,use as t,useEffect as n,useMemo as r,useRef as i,useState as a}from"react";import{jsx as o}from"react/jsx-runtime";const s=e(null);s.displayName=`WithdrawBindingsContext`;function c({children:e}){let[t,n]=a({}),c=i({});return o(s,{value:r(()=>({bindings:t,setBindings:n,ref:c}),[t]),children:e})}function l(){return t(s)?.bindings??{}}function u(){let e=t(s),n=i({});return e?.ref??n}function d(e){let r=t(s),a=e.balance,o=e.onSubmit,c=e.suggestedRecipient;r&&(r.ref.current={...a===void 0?{}:{balance:a},...o?{onSubmit:o}:{},...c?{suggestedRecipient:c}:{}});let l=i(r?.setBindings);l.current=r?.setBindings;let u=i(r?.ref);u.current=r?.ref,n(()=>{let e=l.current;if(e)return e({...a===void 0?{}:{balance:a},...o?{onSubmit:o}:{},...c?{suggestedRecipient:c}:{}}),()=>{let e=l.current,t=u.current;t&&(t.current={}),e&&e({})}},[a,o,c])}export{c as WithdrawBindingsProvider,d as useWithdrawBindings,u as useWithdrawBindingsRef,l as useWithdrawBindingsValue};
@@ -0,0 +1 @@
1
+ import { WithdrawBalanceInput, WithdrawBindings, WithdrawSuggestedRecipient, useWithdrawBindings } from "./WithdrawBindings.js";
@@ -0,0 +1 @@
1
+ import"./WithdrawBindings.js";
@@ -3,7 +3,7 @@ import { WithdrawalQuotePayload, WithdrawalSettlementFailurePayload, WithdrawalS
3
3
  import { PrepareWithdrawalInput } from "../driver/types.js";
4
4
  import { FailureInfo } from "../../../shared/orchestrator/types.js";
5
5
  import { WithdrawStateName, WithdrawSubmitCallback } from "../orchestrator/types.js";
6
- import { WithdrawBalanceInput, WithdrawSuggestedRecipient } from "./WithdrawDialogBindingsContext.js";
6
+ import { WithdrawBalanceInput, WithdrawSuggestedRecipient } from "../bindings/WithdrawBindings.js";
7
7
  import { WithdrawFormEventCallbacks } from "./WithdrawDialogEventsContext.js";
8
8
  import { ErrorInfo } from "react";
9
9
  import * as _$react_jsx_runtime0 from "react/jsx-runtime";
@@ -1 +1 @@
1
- "use client";import{useDialogLifecycle as e}from"../../../shared/orchestrator/useDialogLifecycle.js";import"../../../shared/orchestrator/index.js";import{useWithdrawSnapshot as t}from"../driver/context.js";import{usePublishWithdrawDialogBindings as n}from"./WithdrawDialogBindingsContext.js";import{useWithdrawEffectiveState as r,useWithdrawState as i}from"../orchestrator/controller.js";import{useWithdraw as a}from"../orchestrator/useWithdraw.js";import"../orchestrator/index.js";import{useIntercomShutdownOnUnmount as o}from"../../../shared/support/useIntercomShutdownOnUnmount.js";import"../../../shared/support/index.js";import{Dialog as s}from"../../../shared/ui/Dialog/Dialog.js";import"../../../shared/ui/Dialog/index.js";import{StepTransition as c}from"../../../shared/dialog/StepTransition.js";import{GatewayKitBoundary as l}from"../../../shared/error-handling/components/GatewayKitBoundary.js";import"../../../shared/error-handling/index.js";import{WithdrawError as u}from"../widgets/withdraw-error/WithdrawError.js";import{WithdrawDialogEventsProvider as d}from"./WithdrawDialogEventsContext.js";import{WithdrawForm as f}from"../widgets/withdraw-form/WithdrawForm.js";import{WithdrawInProgress as p}from"../widgets/withdraw-in-progress/WithdrawInProgress.js";import{WithdrawSuccess as m}from"../widgets/withdraw-success/WithdrawSuccess.js";import"../../../_internal/withdraw/widgets/index.js";import{useRef as h}from"react";import{jsx as g,jsxs as _}from"react/jsx-runtime";function v({container:e,onError:h,onOpened:v,onClosed:b,onStepChanged:x,events:S,balance:C,onSubmit:w,suggestedRecipient:T}={}){let E=i(),D=r(),{close:O}=a(),k=t(),A=E.name!==`closed`;y(E,k.settlement,k.quote,{onOpened:v,onClosed:b,onStepChanged:x,events:S}),o(),n({...C===void 0?{}:{balance:C},...w?{onSubmit:w}:{},...T?{suggestedRecipient:T}:{}});let j=D.name===`submitting`?`form`:D.name;return g(s,{open:A,onOpenChange:e=>e?void 0:O(),children:g(s.Content,{container:e,children:g(l,{onError:h,onReset:O,children:g(d,{events:S??{},children:_(c,{stateKey:j,children:[D.name===`form`||D.name===`submitting`?g(f,{}):null,D.name===`inProgress`?g(p,{}):null,D.name===`success`?g(m,{}):null,D.name===`error`?g(u,{}):null]})})})})})}function y(t,n,r,i){let a=h(i);a.current=i,e({state:t,settlement:n,quote:r,fireFsm:(e,t)=>b(e,t,a.current),fireSettlement:(e,t)=>x(t,a.current),fireQuote:(e,t)=>{if(t.status===e)return;let n=a.current.events;t.status===`ready`&&n?.onQuoteResolved?.(t.payload),t.status===`error`&&n?.onQuoteFailed?.({reason:t.error.message||`Quote failed.`,...t.error.name?{code:t.error.name}:{}})}})}function b(e,t,n){let{onOpened:r,onClosed:i,onStepChanged:a,events:o}=n,s=e.name===`form`&&!!e.ctx?.notice;if(t.name===`form`&&t.ctx?.notice&&!s&&o?.onSignatureDeclined?.(),e.name!==t.name&&(e.name===`closed`&&t.name!==`closed`&&r?.(),e.name!==`closed`&&t.name===`closed`&&i?.(e.name),a?.({from:e.name,to:t.name}),e.name===`form`&&t.name===`submitting`&&o?.onWithdrawalConfirmed?.(),e.name===`submitting`&&t.name===`inProgress`&&t.ctx.tx&&o?.onWithdrawalSubmitted?.({input:t.ctx.input,tx:t.ctx.tx}),t.name===`error`)){let e=t.ctx.failure;e!==void 0&&t.ctx.tx===void 0&&e&&(o?.onSubmissionFailed?.(e),o?.onFailed?.(e))}}function x(e,t){if(e.status!==`ready`&&e.status!==`stale`)return;let n=e.payload,r=t.events;if(r){if(n.kind===`pending`){r.onProcessingProgress?.(n);return}if(n.kind===`succeeded`){r.onSucceeded?.(n);return}n.kind===`failed`&&r.onFailed?.(n)}}export{v as WithdrawDialog};
1
+ "use client";import{useDialogLifecycle as e}from"../../../shared/orchestrator/useDialogLifecycle.js";import"../../../shared/orchestrator/index.js";import{useWithdrawBindings as t}from"../bindings/WithdrawBindings.js";import"../bindings/index.js";import{useWithdrawSnapshot as n}from"../driver/context.js";import{useWithdrawEffectiveState as r,useWithdrawState as i}from"../orchestrator/controller.js";import{useWithdraw as a}from"../orchestrator/useWithdraw.js";import"../orchestrator/index.js";import{useIntercomShutdownOnUnmount as o}from"../../../shared/support/useIntercomShutdownOnUnmount.js";import"../../../shared/support/index.js";import{Dialog as s}from"../../../shared/ui/Dialog/Dialog.js";import"../../../shared/ui/Dialog/index.js";import{StepTransition as c}from"../../../shared/dialog/StepTransition.js";import{GatewayKitBoundary as l}from"../../../shared/error-handling/components/GatewayKitBoundary.js";import"../../../shared/error-handling/index.js";import{WithdrawError as u}from"../widgets/withdraw-error/WithdrawError.js";import{WithdrawDialogEventsProvider as d}from"./WithdrawDialogEventsContext.js";import{WithdrawForm as f}from"../widgets/withdraw-form/WithdrawForm.js";import{WithdrawInProgress as p}from"../widgets/withdraw-in-progress/WithdrawInProgress.js";import{WithdrawSuccess as m}from"../widgets/withdraw-success/WithdrawSuccess.js";import"../../../_internal/withdraw/widgets/index.js";import{useRef as h}from"react";import{jsx as g,jsxs as _}from"react/jsx-runtime";function v({container:e,onError:h,onOpened:v,onClosed:b,onStepChanged:x,events:S,balance:C,onSubmit:w,suggestedRecipient:T}={}){let E=i(),D=r(),{close:O}=a(),k=n(),A=E.name!==`closed`;y(E,k.settlement,k.quote,{onOpened:v,onClosed:b,onStepChanged:x,events:S}),o(),t({...C===void 0?{}:{balance:C},...w?{onSubmit:w}:{},...T?{suggestedRecipient:T}:{}});let j=D.name===`submitting`?`form`:D.name;return g(s,{open:A,onOpenChange:e=>e?void 0:O(),children:g(s.Content,{container:e,children:g(l,{onError:h,onReset:O,children:g(d,{events:S??{},children:_(c,{stateKey:j,children:[D.name===`form`||D.name===`submitting`?g(f,{}):null,D.name===`inProgress`?g(p,{}):null,D.name===`success`?g(m,{}):null,D.name===`error`?g(u,{}):null]})})})})})}function y(t,n,r,i){let a=h(i);a.current=i,e({state:t,settlement:n,quote:r,fireFsm:(e,t)=>b(e,t,a.current),fireSettlement:(e,t)=>x(t,a.current),fireQuote:(e,t)=>{if(t.status===e)return;let n=a.current.events;t.status===`ready`&&n?.onQuoteResolved?.(t.payload),t.status===`error`&&n?.onQuoteFailed?.({reason:t.error.message||`Quote failed.`,...t.error.name?{code:t.error.name}:{}})}})}function b(e,t,n){let{onOpened:r,onClosed:i,onStepChanged:a,events:o}=n,s=e.name===`form`&&!!e.ctx?.notice;if(t.name===`form`&&t.ctx?.notice&&!s&&o?.onSignatureDeclined?.(),e.name!==t.name&&(e.name===`closed`&&t.name!==`closed`&&r?.(),e.name!==`closed`&&t.name===`closed`&&i?.(e.name),a?.({from:e.name,to:t.name}),e.name===`form`&&t.name===`submitting`&&o?.onWithdrawalConfirmed?.(),e.name===`submitting`&&t.name===`inProgress`&&t.ctx.tx&&o?.onWithdrawalSubmitted?.({input:t.ctx.input,tx:t.ctx.tx}),t.name===`error`)){let e=t.ctx.failure;e!==void 0&&t.ctx.tx===void 0&&e&&(o?.onSubmissionFailed?.(e),o?.onFailed?.(e))}}function x(e,t){if(e.status!==`ready`&&e.status!==`stale`)return;let n=e.payload,r=t.events;if(r){if(n.kind===`pending`){r.onProcessingProgress?.(n);return}if(n.kind===`succeeded`){r.onSucceeded?.(n);return}n.kind===`failed`&&r.onFailed?.(n)}}export{v as WithdrawDialog};
@@ -1 +1 @@
1
- "use client";import{useLingui as e}from"../../../shared/i18n/useLingui.js";import"../../../i18n/index.js";import{toFailure as t}from"../../../shared/orchestrator/toFailure.js";import{useDriverSettlementListener as n}from"../../../shared/orchestrator/useDriverSettlementListener.js";import{useEffectiveState as r}from"../../../shared/orchestrator/useEffectiveState.js";import{useSettlementWatcher as i}from"../../../shared/orchestrator/useSettlementWatcher.js";import"../../../shared/orchestrator/index.js";import{useWithdrawDriverInstance as a}from"../driver/context.js";import{useWithdrawDialogBindingsRef as o}from"../dialog/WithdrawDialogBindingsContext.js";import{initialState as s,reducer as c}from"./reducer.js";import{createContext as l,use as u,useCallback as d,useMemo as f,useReducer as p,useRef as m}from"react";import{jsx as h}from"react/jsx-runtime";const g={id:`ldK3jJ`,message:`Failed to submit withdrawal.`},_={id:`kUFhUv`,message:`Withdrawal failed.`},v=l(null);v.displayName=`WithdrawControllerContext`;function y(){let e=u(v);if(!e)throw Error(`useWithdraw / WithdrawControllerProvider must be used inside <KitProvider withdraw={…} />. Mount KitProvider once at the host's app root with a withdraw driver.`);return e}function b(){return y().state}function x(){return y().effectiveState}function S(){return y().actions}function C({children:e}){let t=a(),[n,o]=p(c,s),l=T(n,o,t),u=n.name===`inProgress`?{form:n.ctx.input,submittedAt:n.ctx.submittedAt,...n.ctx.tx?{tx:n.ctx.tx}:{}}:void 0;i(t,u,u?`${u.submittedAt}|${u.tx?.hash??``}`:void 0),E(n,o,t);let d=r(n),m=w(o,l);return h(v,{value:f(()=>({state:n,effectiveState:d,dispatch:o,controller:m,actions:l}),[n,d,m,l]),children:e})}function w(e,t){let n=d(()=>{e({type:`OPEN`})},[e]),r=d(()=>{e({type:`CLOSE`})},[e]);return f(()=>({open:n,close:r,actions:t}),[n,r,t])}function T(n,r,i){let a=m(n);a.current=n;let s=m(i);s.current=i;let c=m(r);c.current=r;let{i18n:l}=e(),u=m(l);u.current=l;let p=o(),h=d(e=>{let n=s.current;c.current({type:`SUBMIT`,input:e});let r=new AbortController,i={sourceAssetSymbol:e.sourceAssetSymbol,sourceChainId:e.sourceChainId,amount:e.amount,receiveTokenSymbol:e.receiveTokenSymbol,receiveChainId:e.receiveChainId,recipientAddress:e.recipientAddress},a={beginProcessing(e){c.current({type:`BEGIN_PROCESSING`,submittedAt:Date.now(),...e?{tx:e}:{}})},setTxHash(e){c.current({type:`SET_TX_HASH`,tx:e,submittedAt:Date.now()})},fail(e){c.current({type:`MARK_FAILED`,...e?{failure:e}:{}})},succeed(){c.current({type:`MARK_SUCCEEDED`})}};n.prepareWithdrawal(i,r.signal).then(i=>{if(r.signal.aborted)return;let o=p.current.onSubmit;if(!o){c.current({type:`SUBMIT_FAILED`,failure:t(Error(`WithdrawDialog onSubmit is missing.`),u.current._(g)),input:e});return}let s=n.getSnapshot().quote,l=s.status===`ready`||s.status===`stale`?s.payload:void 0;try{let n=o({form:e,depositTarget:i.depositTarget,correlation:i.correlation,...l?{quote:l}:{}},a,r.signal);n&&typeof n.catch==`function`&&n.catch(n=>{r.signal.aborted||c.current({type:`SUBMIT_FAILED`,failure:t(n,u.current._(g)),input:e})})}catch(n){if(r.signal.aborted)return;c.current({type:`SUBMIT_FAILED`,failure:t(n,u.current._(g)),input:e})}}).catch(n=>{r.signal.aborted||c.current({type:`SUBMIT_FAILED`,failure:t(n,u.current._(g)),input:e})})},[]),_=d(()=>{c.current({type:`CLOSE`})},[]),v=d(()=>{c.current({type:`RESET`})},[]),y=d(()=>{c.current({type:`CLEAR_NOTICE`})},[]);return f(()=>({submit:h,close:_,reset:v,clearNotice:y}),[h,_,v,y])}function E(t,r,i){let a=m(t);a.current=t;let{i18n:o}=e(),s=m(o);s.current=o,n(i,(e,t)=>{if(a.current.name===`inProgress`){if(e===`succeeded`){r({type:`SETTLEMENT_SUCCEEDED`});return}if(e===`failed`){let e=t.settlement,n=e.status===`ready`||e.status===`stale`?e.payload:null,i=n&&n.kind===`failed`?{reason:s.current._(_),code:n.failureKind}:void 0;r({type:`SETTLEMENT_FAILED`,...i?{failure:i}:{}})}}})}export{C as WithdrawControllerProvider,y as useControllerContext,S as useWithdrawActions,x as useWithdrawEffectiveState,b as useWithdrawState};
1
+ "use client";import{useLingui as e}from"../../../shared/i18n/useLingui.js";import"../../../i18n/index.js";import{toFailure as t}from"../../../shared/orchestrator/toFailure.js";import{useDriverSettlementListener as n}from"../../../shared/orchestrator/useDriverSettlementListener.js";import{useEffectiveState as r}from"../../../shared/orchestrator/useEffectiveState.js";import{useSettlementWatcher as i}from"../../../shared/orchestrator/useSettlementWatcher.js";import"../../../shared/orchestrator/index.js";import{useWithdrawBindingsRef as a}from"../bindings/WithdrawBindings.js";import"../bindings/index.js";import{useWithdrawDriverInstance as o}from"../driver/context.js";import{initialState as s,reducer as c}from"./reducer.js";import{createContext as l,use as u,useCallback as d,useMemo as f,useReducer as p,useRef as m}from"react";import{jsx as h}from"react/jsx-runtime";const g={id:`ldK3jJ`,message:`Failed to submit withdrawal.`},_={id:`kUFhUv`,message:`Withdrawal failed.`},v=l(null);v.displayName=`WithdrawControllerContext`;function y(){let e=u(v);if(!e)throw Error(`useWithdraw / WithdrawControllerProvider must be used inside <KitProvider withdraw={…} />. Mount KitProvider once at the host's app root with a withdraw driver.`);return e}function b(){return y().state}function x(){return y().effectiveState}function S(){return y().actions}function C({children:e}){let t=o(),[n,a]=p(c,s),l=T(n,a,t),u=n.name===`inProgress`?{form:n.ctx.input,submittedAt:n.ctx.submittedAt,...n.ctx.tx?{tx:n.ctx.tx}:{}}:void 0;i(t,u,u?`${u.submittedAt}|${u.tx?.hash??``}`:void 0),E(n,a,t);let d=r(n),m=w(a,l);return h(v,{value:f(()=>({state:n,effectiveState:d,dispatch:a,controller:m,actions:l}),[n,d,m,l]),children:e})}function w(e,t){let n=d(()=>{e({type:`OPEN`})},[e]),r=d(()=>{e({type:`CLOSE`})},[e]);return f(()=>({open:n,close:r,actions:t}),[n,r,t])}function T(n,r,i){let o=m(n);o.current=n;let s=m(i);s.current=i;let c=m(r);c.current=r;let{i18n:l}=e(),u=m(l);u.current=l;let p=a(),h=d(e=>{let n=s.current;c.current({type:`SUBMIT`,input:e});let r=new AbortController,i={sourceAssetSymbol:e.sourceAssetSymbol,sourceChainId:e.sourceChainId,amount:e.amount,receiveTokenSymbol:e.receiveTokenSymbol,receiveChainId:e.receiveChainId,recipientAddress:e.recipientAddress},a={beginProcessing(e){c.current({type:`BEGIN_PROCESSING`,submittedAt:Date.now(),...e?{tx:e}:{}})},setTxHash(e){c.current({type:`SET_TX_HASH`,tx:e,submittedAt:Date.now()})},fail(e){c.current({type:`MARK_FAILED`,...e?{failure:e}:{}})},succeed(){c.current({type:`MARK_SUCCEEDED`})}};n.prepareWithdrawal(i,r.signal).then(i=>{if(r.signal.aborted)return;let o=p.current.onSubmit;if(!o){c.current({type:`SUBMIT_FAILED`,failure:t(Error(`WithdrawDialog onSubmit is missing.`),u.current._(g)),input:e});return}let s=n.getSnapshot().quote,l=s.status===`ready`||s.status===`stale`?s.payload:void 0;try{let n=o({form:e,depositTarget:i.depositTarget,correlation:i.correlation,...l?{quote:l}:{}},a,r.signal);n&&typeof n.catch==`function`&&n.catch(n=>{r.signal.aborted||c.current({type:`SUBMIT_FAILED`,failure:t(n,u.current._(g)),input:e})})}catch(n){if(r.signal.aborted)return;c.current({type:`SUBMIT_FAILED`,failure:t(n,u.current._(g)),input:e})}}).catch(n=>{r.signal.aborted||c.current({type:`SUBMIT_FAILED`,failure:t(n,u.current._(g)),input:e})})},[]),_=d(()=>{c.current({type:`CLOSE`})},[]),v=d(()=>{c.current({type:`RESET`})},[]),y=d(()=>{c.current({type:`CLEAR_NOTICE`})},[]);return f(()=>({submit:h,close:_,reset:v,clearNotice:y}),[h,_,v,y])}function E(t,r,i){let a=m(t);a.current=t;let{i18n:o}=e(),s=m(o);s.current=o,n(i,(e,t)=>{if(a.current.name===`inProgress`){if(e===`succeeded`){r({type:`SETTLEMENT_SUCCEEDED`});return}if(e===`failed`){let e=t.settlement,n=e.status===`ready`||e.status===`stale`?e.payload:null,i=n&&n.kind===`failed`?{reason:s.current._(_),code:n.failureKind}:void 0;r({type:`SETTLEMENT_FAILED`,...i?{failure:i}:{}})}}})}export{C as WithdrawControllerProvider,y as useControllerContext,S as useWithdrawActions,x as useWithdrawEffectiveState,b as useWithdrawState};
@@ -1 +1 @@
1
- "use client";import{useKitI18n as e}from"../../../../shared/i18n/useKitI18n.js";import{useLingui as t}from"../../../../shared/i18n/useLingui.js";import"../../../../i18n/index.js";import{useWithdrawDriverInstance as n,useWithdrawSnapshot as r}from"../../driver/context.js";import{useWithdrawDialogBindings as i}from"../../dialog/WithdrawDialogBindingsContext.js";import{useWithdrawActions as ee,useWithdrawEffectiveState as te}from"../../orchestrator/controller.js";import{formatTokenAmount as ne}from"../../../../shared/format/formatTokenAmount.js";import{parseAmountInputValue as re}from"../../../../shared/ui/AmountInput/utils.js";import"../../../../shared/ui/AmountInput/index.js";import{toAssetDescriptor as a}from"../../../../shared/widgets/asset-descriptor.js";import{useQuoteCountdown as ie}from"../../../../shared/quote/useQuoteCountdown.js";import"../../../../shared/quote/index.js";import{WithdrawForm as o}from"./compound/WithdrawForm.js";import"./compound/index.js";import{useWithdrawDialogEvents as ae}from"../../dialog/WithdrawDialogEventsContext.js";import{isValidEvmAddress as oe,resolveSubmitLabel as se}from"./validation.js";import{useCallback as s,useEffect as c,useMemo as l,useRef as u,useState as d}from"react";import{jsx as f,jsxs as ce}from"react/jsx-runtime";function p({events:p}){let m=r(),h=n(),g=te(),_=ee(),{i18n:le,_:v}=t(),ue=ae(),de=l(()=>({...ue,...p??{}}),[ue,p]),y=u(de);y.current=de;let{balance:b,suggestedRecipient:fe}=i(),[x,pe]=d(``),[me,he]=d(``),S=g.name===`submitting`,C=g.name===`form`?g.ctx?.notice:void 0,ge=u(C);ge.current=C;let w=m.withdrawableBalances.status===`ready`||m.withdrawableBalances.status===`stale`?m.withdrawableBalances.payload[0]:void 0,T=l(()=>a(w)??{symbol:`USDC`},[w]),_e=l(()=>a(w?{symbol:w.networkName,eip155Id:w.eip155Id,isNative:!0,logoUrl:w.chainLogoUrl}:void 0)??{symbol:`BSC`},[w]),E=typeof b==`number`?b:typeof b==`object`?b.amount:void 0,ve=w?.symbol??T.symbol,D=E??w?.amount.value,ye=E===void 0?w?.symbol:ve,O=D!==void 0&&ye!==void 0?{amount:E===void 0?w?.amount.formatted??ne(D,le):ne(E,le),symbol:ye}:void 0,k=m.receiveOptions.status===`ready`||m.receiveOptions.status===`stale`?m.receiveOptions.payload:[],A=w?.eip155Id?Number(w.eip155Id):void 0,j=w?.symbol??T.symbol,M=l(()=>{let e=new Map;for(let t of k)for(let n of t.tokens){let r=n.symbol.toUpperCase(),i=e.get(r);i?i.push({chain:t,token:n}):e.set(r,[{chain:t,token:n}])}return e},[k]),N=l(()=>{if(M.size===0)return;let e=j.toUpperCase();return M.has(e)?e:M.keys().next().value},[M,j]),P=s(e=>{let t=M.get(e);if(!(!t||t.length===0))return(A===void 0?void 0:t.find(e=>e.chain.eip155Id===A))??t[0]},[M,A]),[F,I]=d(void 0),[L,R]=d(void 0);c(()=>{if(L||!N)return;let e=P(N);e&&(I(e.chain),R(e.token))},[N,P,L]);let z=s(()=>{ge.current&&_.clearNotice()},[_]),be=s(e=>{z(),pe(e),y.current.onRecipientChanged?.(e)},[z]),B=e().locale,V=s(e=>{z(),he(e);let t=re(e,B);y.current.onAmountChanged?.({raw:e,numeric:t})},[z,B]),xe=s(e=>{z();let t=e.symbol.toUpperCase(),n=M.get(t)?.find(e=>e.chain.eip155Id===F?.eip155Id)??P(t);n&&(I(n.chain),R(n.token),y.current.onReceiveTokenChanged?.(n.token),n.chain.eip155Id!==F?.eip155Id&&y.current.onReceiveChainChanged?.(n.chain))},[z,M,P,F?.eip155Id]),Se=s(e=>{z(),I(e);let t=L?.symbol.toUpperCase(),n=(t?e.tokens.find(e=>e.symbol.toUpperCase()===t):void 0)??e.tokens[0];n&&R(n),y.current.onReceiveChainChanged?.(e),n&&n.symbol!==L?.symbol&&y.current.onReceiveTokenChanged?.(n)},[z,L?.symbol]),H=re(me,B),U=H!==null&&H>0,Ce=x.trim(),we=Ce.length>0,W=oe(Ce),G=F!==void 0&&L!==void 0,K=U&&D!==void 0&&H>D,[q,Te]=d(null),J=(m.quote.status===`ready`||m.quote.status===`stale`)&&we&&U&&G&&q!==null&&q.recipient===x&&q.amount===H&&q.receiveChainId===F.eip155Id&&q.receiveSymbol===L.symbol?m.quote.payload:void 0,Ee=l(()=>M.size===0?[T]:[...M.values()].map(e=>{let t=e[0];return a({symbol:t.token.symbol,eip155Id:t.chain.eip155Id,address:t.token.address,isNative:t.token.isNative,logoUrl:t.token.assetLogoUrl})??{symbol:t.token.symbol}}),[M,T]),De=l(()=>{let e=L?.symbol.toUpperCase(),t=e?M.get(e):void 0;return(t?t.map(e=>e.chain):k).map(e=>a({symbol:e.networkName,eip155Id:e.eip155Id,isNative:!0,logoUrl:e.chainLogoUrl})??{symbol:e.networkName})},[L?.symbol,M,k]),Oe=L?a({symbol:L.symbol,eip155Id:F?.eip155Id,address:L.address,isNative:L.isNative,logoUrl:L.assetLogoUrl}):T,ke=F?a({symbol:F.networkName,eip155Id:F.eip155Id,isNative:!0,logoUrl:F.chainLogoUrl}):_e,Ae=l(()=>{if(J?.breakdown)return{route:J.breakdown.selectedRoute?.label,networkCost:J.breakdown.networkCost?.formatted,priceImpact:J.breakdown.priceImpact?.formatted}},[J]),je=l(()=>{if(U)return J?.receiveAmountUsd?J.receiveAmountUsd.formatted:`$${H.toFixed(2)}`},[H,U,J]),Me=J&&U?J.receiveAmount.formatted:void 0,Ne=J?.receiveAmountUsd?.formatted,Y=W&&U&&!K&&G&&J===void 0&&m.quote.status!==`error`,X=W&&U&&!K&&G&&J!==void 0,Pe=ie({expiresAt:J?.expiresAt,enabled:X}),Fe=X&&J?J.quoteTotalSeconds:void 0,[Z,Q]=d(!1);c(()=>{Q(!1)},[x,H,F?.eip155Id,L?.symbol,g.name]),c(()=>{if(!X||!J||g.name!==`form`||Z)return;let e=Math.max(0,J.expiresAt-Date.now()),t=setTimeout(()=>{Q(!0)},e);return()=>clearTimeout(t)},[X,J,g.name,Z]),c(()=>{if(!Z||g.name!==`form`||A===void 0||!F||!L||!W||!U||K)return;let e=new AbortController,t={recipient:x,amount:H??0,receiveChainId:F.eip155Id,receiveSymbol:L.symbol},n={sourceAssetSymbol:j,sourceChainId:A,amount:H??0,receiveTokenSymbol:L.symbol,receiveChainId:F.eip155Id,recipientAddress:x};return y.current.onQuoteRequested?.(n),h.requestQuote(n,e.signal).then(()=>{e.signal.aborted||Te(t)}).catch(()=>{}).finally(()=>{e.signal.aborted||Q(!1)}),()=>e.abort()},[Z,h,x,H,W,U,K,A,j,F,L,g.name]);let $=!W||!U||K||!G||Y||Z,Ie=se({enterRecipientAddress:v({id:`nr03QI`,message:`Enter Recipient Address`}),enterValidRecipientAddress:v({id:`GZPxmc`,message:`Enter Valid Recipient Address`}),enterAmount:v({id:`yH9V_J`,message:`Enter Amount`}),insufficientBalance:v({id:`N2DUxS`,message:`Insufficient Balance`}),regeneratingQuote:v({id:`Ly6geA`,message:`Regenerating quote…`}),estimatingQuote:v({id:`Uevt3L`,message:`Estimating quote`})},{isRecipientFilled:we,isRecipientValid:W,isAmountValid:U,exceedsBalance:K,quoteEstimating:Y,quoteRegenerating:Z}),Le=u(null);c(()=>{if(Le.current?.abort(),!W||!U||K||!G||g.name!==`form`||A===void 0)return;let e=new AbortController;Le.current=e;let t={recipient:x,amount:H,receiveChainId:F.eip155Id,receiveSymbol:L.symbol},n=setTimeout(()=>{let n={sourceAssetSymbol:j,sourceChainId:A,amount:H,receiveTokenSymbol:L.symbol,receiveChainId:F.eip155Id,recipientAddress:x};y.current.onQuoteRequested?.(n),h.requestQuote(n,e.signal).then(()=>{e.signal.aborted||Te(t)}).catch(()=>{})},400);return()=>{clearTimeout(n),e.abort()}},[h,x,H,W,U,K,G,A,j,F?.eip155Id,L?.symbol,g.name]);let Re=s(()=>{O&&V(O.amount)},[O,V]),ze=s(()=>{S||$||A===void 0||!F||!L||_.submit({sourceAssetSymbol:j,sourceChainId:A,amount:H??0,recipientAddress:x,receiveTokenSymbol:L.symbol,receiveChainId:F.eip155Id})},[_,H,A,j,F,L,x,$,S]),Be=s(e=>{let t=k.find(t=>String(t.eip155Id)===String(e.chainId));t&&Se(t)},[Se,k]),Ve=s(e=>{let t=e.symbol.toUpperCase(),n=M.get(t);!n||n.length===0||xe((n.find(e=>e.chain.eip155Id===F?.eip155Id)??n[0]).token)},[xe,M,F?.eip155Id]);return g.name!==`form`&&g.name!==`submitting`?null:ce(o,{recipientAddress:x,onRecipientChange:be,...fe?{suggestedRecipient:fe}:{},amount:me,onAmountChange:V,onAmountMax:Re,sourceAsset:T,sourceChain:_e,receiveAsset:Oe,receiveChain:ke,receiveAssetOptions:Ee,onReceiveAssetChange:Ve,receiveChainOptions:De,onReceiveChainChange:Be,balance:O,amountUsd:je,receiveAmount:Me,receiveAmountUsd:Ne,breakdown:Ae,quoteEstimating:Y,quoteRegenerating:Z,...Pe===void 0?{}:{quoteSeconds:Pe},...Fe===void 0?{}:{quoteTotalSeconds:Fe},submitting:S,submitDisabled:$,submitLabel:Ie,...C?{notice:C}:{},onSubmit:ze,children:[f(o.Header,{}),ce(o.Body,{children:[f(o.RecipientField,{}),f(o.AmountField,{}),f(o.ReceiveSelectors,{}),f(o.BreakdownCard,{})]}),f(o.Footer,{})]})}export{p as WithdrawForm};
1
+ "use client";import{useKitI18n as e}from"../../../../shared/i18n/useKitI18n.js";import{useLingui as t}from"../../../../shared/i18n/useLingui.js";import"../../../../i18n/index.js";import{useWithdrawBindingsValue as n}from"../../bindings/WithdrawBindings.js";import"../../bindings/index.js";import{useWithdrawDriverInstance as r,useWithdrawSnapshot as i}from"../../driver/context.js";import{useWithdrawActions as ee,useWithdrawEffectiveState as te}from"../../orchestrator/controller.js";import{formatTokenAmount as ne}from"../../../../shared/format/formatTokenAmount.js";import{parseAmountInputValue as re}from"../../../../shared/ui/AmountInput/utils.js";import"../../../../shared/ui/AmountInput/index.js";import{toAssetDescriptor as a}from"../../../../shared/widgets/asset-descriptor.js";import{useQuoteCountdown as ie}from"../../../../shared/quote/useQuoteCountdown.js";import"../../../../shared/quote/index.js";import{WithdrawForm as o}from"./compound/WithdrawForm.js";import"./compound/index.js";import{useWithdrawDialogEvents as ae}from"../../dialog/WithdrawDialogEventsContext.js";import{isValidEvmAddress as oe,resolveSubmitLabel as se}from"./validation.js";import{useCallback as s,useEffect as c,useMemo as l,useRef as u,useState as d}from"react";import{jsx as f,jsxs as ce}from"react/jsx-runtime";function p({events:p}){let m=i(),h=r(),g=te(),_=ee(),{i18n:le,_:v}=t(),ue=ae(),de=l(()=>({...ue,...p??{}}),[ue,p]),y=u(de);y.current=de;let{balance:b,suggestedRecipient:fe}=n(),[x,pe]=d(``),[me,he]=d(``),S=g.name===`submitting`,C=g.name===`form`?g.ctx?.notice:void 0,ge=u(C);ge.current=C;let w=m.withdrawableBalances.status===`ready`||m.withdrawableBalances.status===`stale`?m.withdrawableBalances.payload[0]:void 0,T=l(()=>a(w)??{symbol:`USDC`},[w]),_e=l(()=>a(w?{symbol:w.networkName,eip155Id:w.eip155Id,isNative:!0,logoUrl:w.chainLogoUrl}:void 0)??{symbol:`BSC`},[w]),E=typeof b==`number`?b:typeof b==`object`?b.amount:void 0,ve=w?.symbol??T.symbol,D=E??w?.amount.value,ye=E===void 0?w?.symbol:ve,O=D!==void 0&&ye!==void 0?{amount:E===void 0?w?.amount.formatted??ne(D,le):ne(E,le),symbol:ye}:void 0,k=m.receiveOptions.status===`ready`||m.receiveOptions.status===`stale`?m.receiveOptions.payload:[],A=w?.eip155Id?Number(w.eip155Id):void 0,j=w?.symbol??T.symbol,M=l(()=>{let e=new Map;for(let t of k)for(let n of t.tokens){let r=n.symbol.toUpperCase(),i=e.get(r);i?i.push({chain:t,token:n}):e.set(r,[{chain:t,token:n}])}return e},[k]),N=l(()=>{if(M.size===0)return;let e=j.toUpperCase();return M.has(e)?e:M.keys().next().value},[M,j]),P=s(e=>{let t=M.get(e);if(!(!t||t.length===0))return(A===void 0?void 0:t.find(e=>e.chain.eip155Id===A))??t[0]},[M,A]),[F,I]=d(void 0),[L,R]=d(void 0);c(()=>{if(L||!N)return;let e=P(N);e&&(I(e.chain),R(e.token))},[N,P,L]);let z=s(()=>{ge.current&&_.clearNotice()},[_]),be=s(e=>{z(),pe(e),y.current.onRecipientChanged?.(e)},[z]),B=e().locale,V=s(e=>{z(),he(e);let t=re(e,B);y.current.onAmountChanged?.({raw:e,numeric:t})},[z,B]),xe=s(e=>{z();let t=e.symbol.toUpperCase(),n=M.get(t)?.find(e=>e.chain.eip155Id===F?.eip155Id)??P(t);n&&(I(n.chain),R(n.token),y.current.onReceiveTokenChanged?.(n.token),n.chain.eip155Id!==F?.eip155Id&&y.current.onReceiveChainChanged?.(n.chain))},[z,M,P,F?.eip155Id]),Se=s(e=>{z(),I(e);let t=L?.symbol.toUpperCase(),n=(t?e.tokens.find(e=>e.symbol.toUpperCase()===t):void 0)??e.tokens[0];n&&R(n),y.current.onReceiveChainChanged?.(e),n&&n.symbol!==L?.symbol&&y.current.onReceiveTokenChanged?.(n)},[z,L?.symbol]),H=re(me,B),U=H!==null&&H>0,Ce=x.trim(),we=Ce.length>0,W=oe(Ce),G=F!==void 0&&L!==void 0,K=U&&D!==void 0&&H>D,[q,Te]=d(null),J=(m.quote.status===`ready`||m.quote.status===`stale`)&&we&&U&&G&&q!==null&&q.recipient===x&&q.amount===H&&q.receiveChainId===F.eip155Id&&q.receiveSymbol===L.symbol?m.quote.payload:void 0,Ee=l(()=>M.size===0?[T]:[...M.values()].map(e=>{let t=e[0];return a({symbol:t.token.symbol,eip155Id:t.chain.eip155Id,address:t.token.address,isNative:t.token.isNative,logoUrl:t.token.assetLogoUrl})??{symbol:t.token.symbol}}),[M,T]),De=l(()=>{let e=L?.symbol.toUpperCase(),t=e?M.get(e):void 0;return(t?t.map(e=>e.chain):k).map(e=>a({symbol:e.networkName,eip155Id:e.eip155Id,isNative:!0,logoUrl:e.chainLogoUrl})??{symbol:e.networkName})},[L?.symbol,M,k]),Oe=L?a({symbol:L.symbol,eip155Id:F?.eip155Id,address:L.address,isNative:L.isNative,logoUrl:L.assetLogoUrl}):T,ke=F?a({symbol:F.networkName,eip155Id:F.eip155Id,isNative:!0,logoUrl:F.chainLogoUrl}):_e,Ae=l(()=>{if(J?.breakdown)return{route:J.breakdown.selectedRoute?.label,networkCost:J.breakdown.networkCost?.formatted,priceImpact:J.breakdown.priceImpact?.formatted}},[J]),je=l(()=>{if(U)return J?.receiveAmountUsd?J.receiveAmountUsd.formatted:`$${H.toFixed(2)}`},[H,U,J]),Me=J&&U?J.receiveAmount.formatted:void 0,Ne=J?.receiveAmountUsd?.formatted,Y=W&&U&&!K&&G&&J===void 0&&m.quote.status!==`error`,X=W&&U&&!K&&G&&J!==void 0,Pe=ie({expiresAt:J?.expiresAt,enabled:X}),Fe=X&&J?J.quoteTotalSeconds:void 0,[Z,Q]=d(!1);c(()=>{Q(!1)},[x,H,F?.eip155Id,L?.symbol,g.name]),c(()=>{if(!X||!J||g.name!==`form`||Z)return;let e=Math.max(0,J.expiresAt-Date.now()),t=setTimeout(()=>{Q(!0)},e);return()=>clearTimeout(t)},[X,J,g.name,Z]),c(()=>{if(!Z||g.name!==`form`||A===void 0||!F||!L||!W||!U||K)return;let e=new AbortController,t={recipient:x,amount:H??0,receiveChainId:F.eip155Id,receiveSymbol:L.symbol},n={sourceAssetSymbol:j,sourceChainId:A,amount:H??0,receiveTokenSymbol:L.symbol,receiveChainId:F.eip155Id,recipientAddress:x};return y.current.onQuoteRequested?.(n),h.requestQuote(n,e.signal).then(()=>{e.signal.aborted||Te(t)}).catch(()=>{}).finally(()=>{e.signal.aborted||Q(!1)}),()=>e.abort()},[Z,h,x,H,W,U,K,A,j,F,L,g.name]);let $=!W||!U||K||!G||Y||Z,Ie=se({enterRecipientAddress:v({id:`nr03QI`,message:`Enter Recipient Address`}),enterValidRecipientAddress:v({id:`GZPxmc`,message:`Enter Valid Recipient Address`}),enterAmount:v({id:`yH9V_J`,message:`Enter Amount`}),insufficientBalance:v({id:`N2DUxS`,message:`Insufficient Balance`}),regeneratingQuote:v({id:`Ly6geA`,message:`Regenerating quote…`}),estimatingQuote:v({id:`Uevt3L`,message:`Estimating quote`})},{isRecipientFilled:we,isRecipientValid:W,isAmountValid:U,exceedsBalance:K,quoteEstimating:Y,quoteRegenerating:Z}),Le=u(null);c(()=>{if(Le.current?.abort(),!W||!U||K||!G||g.name!==`form`||A===void 0)return;let e=new AbortController;Le.current=e;let t={recipient:x,amount:H,receiveChainId:F.eip155Id,receiveSymbol:L.symbol},n=setTimeout(()=>{let n={sourceAssetSymbol:j,sourceChainId:A,amount:H,receiveTokenSymbol:L.symbol,receiveChainId:F.eip155Id,recipientAddress:x};y.current.onQuoteRequested?.(n),h.requestQuote(n,e.signal).then(()=>{e.signal.aborted||Te(t)}).catch(()=>{})},400);return()=>{clearTimeout(n),e.abort()}},[h,x,H,W,U,K,G,A,j,F?.eip155Id,L?.symbol,g.name]);let Re=s(()=>{O&&V(O.amount)},[O,V]),ze=s(()=>{S||$||A===void 0||!F||!L||_.submit({sourceAssetSymbol:j,sourceChainId:A,amount:H??0,recipientAddress:x,receiveTokenSymbol:L.symbol,receiveChainId:F.eip155Id})},[_,H,A,j,F,L,x,$,S]),Be=s(e=>{let t=k.find(t=>String(t.eip155Id)===String(e.chainId));t&&Se(t)},[Se,k]),Ve=s(e=>{let t=e.symbol.toUpperCase(),n=M.get(t);!n||n.length===0||xe((n.find(e=>e.chain.eip155Id===F?.eip155Id)??n[0]).token)},[xe,M,F?.eip155Id]);return g.name!==`form`&&g.name!==`submitting`?null:ce(o,{recipientAddress:x,onRecipientChange:be,...fe?{suggestedRecipient:fe}:{},amount:me,onAmountChange:V,onAmountMax:Re,sourceAsset:T,sourceChain:_e,receiveAsset:Oe,receiveChain:ke,receiveAssetOptions:Ee,onReceiveAssetChange:Ve,receiveChainOptions:De,onReceiveChainChange:Be,balance:O,amountUsd:je,receiveAmount:Me,receiveAmountUsd:Ne,breakdown:Ae,quoteEstimating:Y,quoteRegenerating:Z,...Pe===void 0?{}:{quoteSeconds:Pe},...Fe===void 0?{}:{quoteTotalSeconds:Fe},submitting:S,submitDisabled:$,submitLabel:Ie,...C?{notice:C}:{},onSubmit:ze,children:[f(o.Header,{}),ce(o.Body,{children:[f(o.RecipientField,{}),f(o.AmountField,{}),f(o.ReceiveSelectors,{}),f(o.BreakdownCard,{})]}),f(o.Footer,{})]})}export{p as WithdrawForm};
@@ -1,6 +1,6 @@
1
1
  import { DialogShellControls } from "../../../../../shared/dialog/DialogShell.js";
2
2
  import { AssetDescriptor } from "../../../../../shared/widgets/asset-descriptor.js";
3
- import { WithdrawSuggestedRecipient } from "../../../dialog/WithdrawDialogBindingsContext.js";
3
+ import { WithdrawSuggestedRecipient } from "../../../bindings/WithdrawBindings.js";
4
4
  import { ComponentProps, ReactNode } from "react";
5
5
 
6
6
  //#region src/flows/withdraw/widgets/withdraw-form/compound/types.d.ts
package/dist/index.d.ts CHANGED
@@ -13,7 +13,8 @@ import { DEFAULT_KIT_STORAGE_NAMESPACE, KitStorageProvider, useKitStorage, useKi
13
13
  import { StridgeEnvironment } from "./drivers/stridge/types.js";
14
14
  import { FailureInfo } from "./shared/orchestrator/types.js";
15
15
  import { DepositActions, DepositController, DepositMethod, DepositState, DepositStateName, OpenInput } from "./flows/deposit/orchestrator/types.js";
16
- import { WithdrawActions, WithdrawController, WithdrawState, WithdrawStateName, WithdrawalFormSnapshot } from "./flows/withdraw/orchestrator/types.js";
16
+ import { WithdrawActions, WithdrawController, WithdrawState, WithdrawStateName, WithdrawSubmitActions, WithdrawSubmitCallback, WithdrawSubmitInput, WithdrawalFormSnapshot } from "./flows/withdraw/orchestrator/types.js";
17
+ import { WithdrawBalanceInput, WithdrawBindings, WithdrawSuggestedRecipient, useWithdrawBindings } from "./flows/withdraw/bindings/WithdrawBindings.js";
17
18
  import { ChainInput, ChainSlug, chains } from "./shared/chains/index.js";
18
19
  import { ChainLogoMeta } from "./shared/utils/logos/chains.js";
19
20
  import { ChainLogoInput, TokenLogoInput } from "./shared/utils/logos/types.js";
@@ -25,4 +26,4 @@ import { useWithdrawState } from "./flows/withdraw/orchestrator/controller.js";
25
26
  import { useWithdraw } from "./flows/withdraw/orchestrator/useWithdraw.js";
26
27
  import { useOptionalStridge, useStridge } from "./stridge/StridgeContext.js";
27
28
  import { StridgeAppearance, StridgeAsset, StridgeDepositDestination, StridgeDepositFlowConfig, StridgeFlowOwner, StridgeProvider, StridgeStorageConfig, StridgeWithdrawFlowConfig } from "./stridge/StridgeProvider.js";
28
- export { type BannerAckBucket, type ChainInput, type ChainLogoInput, type ChainLogoMeta, type ChainSlug, DEFAULT_KIT_STORAGE_NAMESPACE, type DepositActions, type DepositController, type DepositMethod, type OpenInput as DepositOpenInput, type DepositSnapshot, type DepositState, type DepositStateName, type FailureInfo, type IntercomMerchantContext, KitPortalScope, KitStorageProvider, type LogosNamespace, type StridgeAppearance, type StridgeAsset, type StridgeDepositDestination, type StridgeDepositFlowConfig, type StridgeEnvironment, type StridgeFlowOwner, StridgeProvider, type StridgeStorageConfig, type StridgeWithdrawFlowConfig, type SupportConfig, type SupportOpenContext, type TokenLogoInput, type TxRef, type WithdrawActions, type WithdrawController, type WithdrawSnapshot, type WithdrawState, type WithdrawStateName, type WithdrawalFormSnapshot, bannerAckStorageKey, bucketFromSettlement, chains, createKitStorage, createLocalStorageAdapter, createMemoryStorageAdapter, createSessionStorageAdapter, logos, resolveStorageAdapter, useBannerAck, useBannerAckForSettlement, useDeposit, useDepositSnapshot, useDepositState, useKitConfig, useKitStorage, useKitStorageValue, useOptionalStridge, useStridge, useWithdraw, useWithdrawSnapshot, useWithdrawState };
29
+ export { type BannerAckBucket, type ChainInput, type ChainLogoInput, type ChainLogoMeta, type ChainSlug, DEFAULT_KIT_STORAGE_NAMESPACE, type DepositActions, type DepositController, type DepositMethod, type OpenInput as DepositOpenInput, type DepositSnapshot, type DepositState, type DepositStateName, type FailureInfo, type IntercomMerchantContext, KitPortalScope, KitStorageProvider, type LogosNamespace, type StridgeAppearance, type StridgeAsset, type StridgeDepositDestination, type StridgeDepositFlowConfig, type StridgeEnvironment, type StridgeFlowOwner, StridgeProvider, type StridgeStorageConfig, type StridgeWithdrawFlowConfig, type SupportConfig, type SupportOpenContext, type TokenLogoInput, type TxRef, type WithdrawActions, type WithdrawBalanceInput, type WithdrawBindings, type WithdrawController, type WithdrawSnapshot, type WithdrawState, type WithdrawStateName, type WithdrawSubmitActions, type WithdrawSubmitCallback, type WithdrawSubmitInput, type WithdrawSuggestedRecipient, type WithdrawalFormSnapshot, bannerAckStorageKey, bucketFromSettlement, chains, createKitStorage, createLocalStorageAdapter, createMemoryStorageAdapter, createSessionStorageAdapter, logos, resolveStorageAdapter, useBannerAck, useBannerAckForSettlement, useDeposit, useDepositSnapshot, useDepositState, useKitConfig, useKitStorage, useKitStorageValue, useOptionalStridge, useStridge, useWithdraw, useWithdrawBindings, useWithdrawSnapshot, useWithdrawState };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{chains as e}from"./shared/chains/index.js";import{logos as t}from"./shared/utils/logos/api.js";import"./shared/utils/logos/index.js";import{createLocalStorageAdapter as n,createMemoryStorageAdapter as r,createSessionStorageAdapter as i,resolveStorageAdapter as a}from"./storage/adapters.js";import{createKitStorage as o}from"./storage/createKitStorage.js";import{DEFAULT_KIT_STORAGE_NAMESPACE as s,KitStorageProvider as c,useKitStorage as l,useKitStorageValue as u}from"./storage/context.js";import"./storage/index.js";import{bannerAckStorageKey as d,bucketFromSettlement as f,useBannerAck as p,useBannerAckForSettlement as m}from"./banners/useBannerAck.js";import"./banners/index.js";import{useDepositSnapshot as h}from"./flows/deposit/driver/context.js";import{useDepositState as g}from"./flows/deposit/orchestrator/controller.js";import{useDeposit as _}from"./flows/deposit/orchestrator/useDeposit.js";import{useWithdrawSnapshot as v}from"./flows/withdraw/driver/context.js";import{useWithdrawState as y}from"./flows/withdraw/orchestrator/controller.js";import{useWithdraw as b}from"./flows/withdraw/orchestrator/useWithdraw.js";import"./flows/withdraw/orchestrator/index.js";import{useKitConfig as x}from"./scope/context.js";import{KitPortalScope as S}from"./scope/KitPortalScope.js";import{useOptionalStridge as C,useStridge as w}from"./stridge/StridgeContext.js";import{StridgeProvider as T}from"./stridge/StridgeProvider.js";export{s as DEFAULT_KIT_STORAGE_NAMESPACE,S as KitPortalScope,c as KitStorageProvider,T as StridgeProvider,d as bannerAckStorageKey,f as bucketFromSettlement,e as chains,o as createKitStorage,n as createLocalStorageAdapter,r as createMemoryStorageAdapter,i as createSessionStorageAdapter,t as logos,a as resolveStorageAdapter,p as useBannerAck,m as useBannerAckForSettlement,_ as useDeposit,h as useDepositSnapshot,g as useDepositState,x as useKitConfig,l as useKitStorage,u as useKitStorageValue,C as useOptionalStridge,w as useStridge,b as useWithdraw,v as useWithdrawSnapshot,y as useWithdrawState};
1
+ import{chains as e}from"./shared/chains/index.js";import{logos as t}from"./shared/utils/logos/api.js";import"./shared/utils/logos/index.js";import{createLocalStorageAdapter as n,createMemoryStorageAdapter as r,createSessionStorageAdapter as i,resolveStorageAdapter as a}from"./storage/adapters.js";import{createKitStorage as o}from"./storage/createKitStorage.js";import{DEFAULT_KIT_STORAGE_NAMESPACE as s,KitStorageProvider as c,useKitStorage as l,useKitStorageValue as u}from"./storage/context.js";import"./storage/index.js";import{bannerAckStorageKey as d,bucketFromSettlement as f,useBannerAck as p,useBannerAckForSettlement as m}from"./banners/useBannerAck.js";import"./banners/index.js";import{useDepositSnapshot as h}from"./flows/deposit/driver/context.js";import{useDepositState as g}from"./flows/deposit/orchestrator/controller.js";import{useDeposit as _}from"./flows/deposit/orchestrator/useDeposit.js";import{useWithdrawBindings as v}from"./flows/withdraw/bindings/WithdrawBindings.js";import"./flows/withdraw/bindings/index.js";import{useWithdrawSnapshot as y}from"./flows/withdraw/driver/context.js";import{useWithdrawState as b}from"./flows/withdraw/orchestrator/controller.js";import{useWithdraw as x}from"./flows/withdraw/orchestrator/useWithdraw.js";import"./flows/withdraw/orchestrator/index.js";import{useKitConfig as S}from"./scope/context.js";import{KitPortalScope as C}from"./scope/KitPortalScope.js";import{useOptionalStridge as w,useStridge as T}from"./stridge/StridgeContext.js";import{StridgeProvider as E}from"./stridge/StridgeProvider.js";export{s as DEFAULT_KIT_STORAGE_NAMESPACE,C as KitPortalScope,c as KitStorageProvider,E as StridgeProvider,d as bannerAckStorageKey,f as bucketFromSettlement,e as chains,o as createKitStorage,n as createLocalStorageAdapter,r as createMemoryStorageAdapter,i as createSessionStorageAdapter,t as logos,a as resolveStorageAdapter,p as useBannerAck,m as useBannerAckForSettlement,_ as useDeposit,h as useDepositSnapshot,g as useDepositState,S as useKitConfig,l as useKitStorage,u as useKitStorageValue,w as useOptionalStridge,T as useStridge,x as useWithdraw,v as useWithdrawBindings,y as useWithdrawSnapshot,b as useWithdrawState};
package/dist/package.js CHANGED
@@ -1 +1 @@
1
- var e=`0.1.0-alpha.18`;export{e as version};
1
+ var e=`0.1.0-alpha.19`;export{e as version};
package/dist/types.d.ts CHANGED
@@ -9,7 +9,8 @@ import { KitStorageAdapter, KitStoragePersistence } from "./storage/types.js";
9
9
  import { KitStorage } from "./storage/createKitStorage.js";
10
10
  import { FailureInfo } from "./shared/orchestrator/types.js";
11
11
  import { ConfirmDepositPhase, DepositActions, DepositController, DepositMethod, DepositState, DepositStateName, GatewayEvent, OpenInput, ResolvedOpenInput, RetryTargetSpec } from "./flows/deposit/orchestrator/types.js";
12
- import { WithdrawActions, WithdrawController, WithdrawEvent, WithdrawState, WithdrawStateName, WithdrawalFormSnapshot } from "./flows/withdraw/orchestrator/types.js";
12
+ import { WithdrawActions, WithdrawController, WithdrawEvent, WithdrawState, WithdrawStateName, WithdrawSubmitActions, WithdrawSubmitCallback, WithdrawSubmitInput, WithdrawalFormSnapshot } from "./flows/withdraw/orchestrator/types.js";
13
+ import { WithdrawBalanceInput, WithdrawBindings, WithdrawSuggestedRecipient } from "./flows/withdraw/bindings/WithdrawBindings.js";
13
14
  import { BannerAckBucket } from "./banners/useBannerAck.js";
14
15
  import { STEPS_WITH_OWN_SETTLEMENT_VIEW, stepRendersSettlement } from "./flows/deposit/orchestrator/steps.js";
15
- export { type AcceptedAssetPayload, type AddressItemPayload, type AssetPayload, type BalanceItemPayload, type BannerAckBucket, type BrandPayload, type ChainPayload, type ConfirmDepositPhase, type DepositActions, type DepositController, type DepositMethod, type DepositSnapshot, type DepositState, type DepositStateName, type Entity, type FailureInfo, type GatewayEvent, type KitConfig, type KitDirection, type KitRadius, type KitStorage, type KitStorageAdapter, type KitStoragePersistence, type KitTarget, type KitTheme, type OpenInput, type QuoteBreakdownPayload, type QuotePayload, type QuoteRoutePayload, type ReceiveChainPayload, type ReceiveOptionDto, type ReceiveOptionsResponse, type ReceiveTokenOptionPayload, type ResolvedOpenInput, type RetryTargetSpec, STEPS_WITH_OWN_SETTLEMENT_VIEW, type SettlementFailureKind, type SettlementFailurePayload, type SettlementPayload, type SettlementPendingPayload, type SettlementSuccessPayload, type SourceWalletPayload, type TargetPayload, type TxRef, type WalletInfo, type WalletPayload, type WithdrawActions, type WithdrawController, type WithdrawEvent, type WithdrawSnapshot, type WithdrawState, type WithdrawStateName, type WithdrawableBalanceDto, type WithdrawableBalanceItemPayload, type WithdrawableBalancesResponse, type WithdrawalFormSnapshot, type WithdrawalQuoteBreakdownPayload, type WithdrawalQuoteDto, type WithdrawalQuotePayload, type WithdrawalQuoteResponse, type WithdrawalReceiveAssetPayload, type WithdrawalSettlementDto, type WithdrawalSettlementFailurePayload, type WithdrawalSettlementPayload, type WithdrawalSettlementPendingPayload, type WithdrawalSettlementResponse, type WithdrawalSettlementSuccessPayload, stepRendersSettlement };
16
+ export { type AcceptedAssetPayload, type AddressItemPayload, type AssetPayload, type BalanceItemPayload, type BannerAckBucket, type BrandPayload, type ChainPayload, type ConfirmDepositPhase, type DepositActions, type DepositController, type DepositMethod, type DepositSnapshot, type DepositState, type DepositStateName, type Entity, type FailureInfo, type GatewayEvent, type KitConfig, type KitDirection, type KitRadius, type KitStorage, type KitStorageAdapter, type KitStoragePersistence, type KitTarget, type KitTheme, type OpenInput, type QuoteBreakdownPayload, type QuotePayload, type QuoteRoutePayload, type ReceiveChainPayload, type ReceiveOptionDto, type ReceiveOptionsResponse, type ReceiveTokenOptionPayload, type ResolvedOpenInput, type RetryTargetSpec, STEPS_WITH_OWN_SETTLEMENT_VIEW, type SettlementFailureKind, type SettlementFailurePayload, type SettlementPayload, type SettlementPendingPayload, type SettlementSuccessPayload, type SourceWalletPayload, type TargetPayload, type TxRef, type WalletInfo, type WalletPayload, type WithdrawActions, type WithdrawBalanceInput, type WithdrawBindings, type WithdrawController, type WithdrawEvent, type WithdrawSnapshot, type WithdrawState, type WithdrawStateName, type WithdrawSubmitActions, type WithdrawSubmitCallback, type WithdrawSubmitInput, type WithdrawSuggestedRecipient, type WithdrawableBalanceDto, type WithdrawableBalanceItemPayload, type WithdrawableBalancesResponse, type WithdrawalFormSnapshot, type WithdrawalQuoteBreakdownPayload, type WithdrawalQuoteDto, type WithdrawalQuotePayload, type WithdrawalQuoteResponse, type WithdrawalReceiveAssetPayload, type WithdrawalSettlementDto, type WithdrawalSettlementFailurePayload, type WithdrawalSettlementPayload, type WithdrawalSettlementPendingPayload, type WithdrawalSettlementResponse, type WithdrawalSettlementSuccessPayload, stepRendersSettlement };
@@ -1,4 +1,4 @@
1
1
  import { WithdrawSubmitActions, WithdrawSubmitCallback, WithdrawSubmitInput } from "../../flows/withdraw/orchestrator/types.js";
2
- import { WithdrawBalanceInput, WithdrawSuggestedRecipient } from "../../flows/withdraw/dialog/WithdrawDialogBindingsContext.js";
2
+ import { WithdrawBalanceInput, WithdrawBindings, WithdrawSuggestedRecipient } from "../../flows/withdraw/bindings/WithdrawBindings.js";
3
3
  import { WithdrawDialog } from "../../flows/withdraw/dialog/WithdrawDialog.js";
4
- export { type WithdrawBalanceInput, WithdrawDialog, type WithdrawSubmitActions, type WithdrawSubmitCallback, type WithdrawSubmitInput, type WithdrawSuggestedRecipient };
4
+ export { type WithdrawBalanceInput, type WithdrawBindings, WithdrawDialog, type WithdrawSubmitActions, type WithdrawSubmitCallback, type WithdrawSubmitInput, type WithdrawSuggestedRecipient };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stridge/kit",
3
- "version": "0.1.0-alpha.18",
3
+ "version": "0.1.0-alpha.19",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,44 +0,0 @@
1
- import { ReactNode } from "react";
2
- //#region src/flows/withdraw/dialog/WithdrawDialogBindingsContext.d.ts
3
- /**
4
- * Withdrawable balance the host surfaces to the dialog. Two accepted forms:
5
- *
6
- * - `number` — bare amount in display units (kit infers symbol from the provider-level
7
- * `asset.symbol`; USD value is derived for known stablecoins or hidden otherwise).
8
- * - `{ amount, amountUsd? }` — explicit amount plus optional pre-computed USD value.
9
- *
10
- * `undefined` represents the loading state — the kit renders a skeleton / em-dashes instead
11
- * of a value.
12
- */
13
- type WithdrawBalanceInput = number | {
14
- amount: number;
15
- amountUsd?: number;
16
- };
17
- /**
18
- * Trusted-recipient prefill chip surfaced next to the recipient address input. The kit no
19
- * longer auto-derives a chip from `wagmi.address` — that misled users on embedded-wallet
20
- * integrations, where `wagmi.address` is the integration's generated wallet rather than the
21
- * user's primary self-custodial wallet. Hosts that have a verified, user-trusted address (a
22
- * saved wallet on the user's profile, a KYC-bound payout destination, a whitelisted withdrawal
23
- * address) pass it via the dialog's `suggestedRecipient` prop; the chip's `aria-label` reads
24
- * off `label` so the affordance is unambiguous about which address the user is filling with.
25
- */
26
- interface WithdrawSuggestedRecipient {
27
- /** Address that fills the recipient input when the chip is clicked. */
28
- address: string;
29
- /**
30
- * Short human label for the chip — used as the accessible name (`aria-label`) so screen
31
- * readers and click targets describe the saved address concretely (e.g. `"Saved wallet"`,
32
- * `"Your verified address"`). When omitted, the chip falls back to a generic kit-default.
33
- */
34
- label?: string;
35
- /**
36
- * Receive-side chain id this address belongs to (EIP-155 numeric). When set, the chip is
37
- * surfaced only while the form's selected receive chain matches — prevents the user from
38
- * one-click-filling an Ethereum address while routing to BSC, etc. When omitted, the chip
39
- * is surfaced unconditionally and address-chain compatibility is the integrator's concern.
40
- */
41
- chainId?: number;
42
- }
43
- //#endregion
44
- export { WithdrawBalanceInput, WithdrawSuggestedRecipient };
@@ -1 +0,0 @@
1
- "use client";import{createContext as e,use as t,useEffect as n,useMemo as r,useRef as i,useState as a}from"react";import{jsx as o}from"react/jsx-runtime";const s=e(null);s.displayName=`WithdrawDialogBindingsContext`;function c({children:e}){let[t,n]=a({}),c=i({});return o(s,{value:r(()=>({bindings:t,setBindings:n,ref:c}),[t]),children:e})}function l(){return t(s)?.bindings??{}}function u(){let e=t(s),n=i({});return e?.ref??n}function d(e){let r=t(s),a=e.balance,o=e.onSubmit,c=e.suggestedRecipient;r&&(r.ref.current={...a===void 0?{}:{balance:a},...o?{onSubmit:o}:{},...c?{suggestedRecipient:c}:{}});let l=i(r?.setBindings);l.current=r?.setBindings;let u=i(r?.ref);u.current=r?.ref,n(()=>{let e=l.current;if(e)return e({...a===void 0?{}:{balance:a},...o?{onSubmit:o}:{},...c?{suggestedRecipient:c}:{}}),()=>{let e=l.current,t=u.current;t&&(t.current={}),e&&e({})}},[a,o,c])}export{c as WithdrawDialogBindingsProvider,d as usePublishWithdrawDialogBindings,l as useWithdrawDialogBindings,u as useWithdrawDialogBindingsRef};