@stridge/kit 0.1.0-alpha.33 → 0.1.0-alpha.35
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.
|
@@ -21,6 +21,14 @@ interface WithdrawalFormSnapshot {
|
|
|
21
21
|
receiveTokenSymbol: string;
|
|
22
22
|
/** Receive-side chain id (EIP-155 numeric). */
|
|
23
23
|
receiveChainId: number;
|
|
24
|
+
/**
|
|
25
|
+
* Pre-formatted USD figure the form displayed under the amount input at submit time. Carried
|
|
26
|
+
* through the FSM so the in-progress / success heroes can render the same dollar value the
|
|
27
|
+
* user just saw on the form, before the indexer prices the settlement legs. Optional because
|
|
28
|
+
* the form's USD computation already returns `undefined` for invalid amounts; the snapshot
|
|
29
|
+
* mirrors that. Pre-formatted (locale-aware) — the orchestrator does not re-format.
|
|
30
|
+
*/
|
|
31
|
+
amountUsd?: string;
|
|
24
32
|
}
|
|
25
33
|
/**
|
|
26
34
|
* State machine state for the orchestrated withdraw dialog. Per-state discriminated `ctx`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{isValidAddressForChainType as e}from"../../../../shared/chains/index.js";import{useKitI18n as t}from"../../../../shared/i18n/useKitI18n.js";import{useLingui as n}from"../../../../shared/i18n/useLingui.js";import"../../../../i18n/index.js";import{useWithdrawBindingsValue as r}from"../../bindings/WithdrawBindings.js";import"../../bindings/index.js";import{useWithdrawDriverInstance as
|
|
1
|
+
"use client";import{isValidAddressForChainType as e}from"../../../../shared/chains/index.js";import{useKitI18n as t}from"../../../../shared/i18n/useKitI18n.js";import{useLingui as n}from"../../../../shared/i18n/useLingui.js";import"../../../../i18n/index.js";import{useWithdrawBindingsValue as r}from"../../bindings/WithdrawBindings.js";import"../../bindings/index.js";import{useWithdrawDriverInstance as ee,useWithdrawSnapshot as te}from"../../driver/context.js";import{useWithdrawActions as ne,useWithdrawEffectiveState as re}from"../../orchestrator/controller.js";import{formatTokenAmount as ie}from"../../../../shared/format/formatTokenAmount.js";import{useKitEmitter as ae}from"../../../../events/emit/useKitEmitter.js";import"../../../../events/emit/index.js";import{parseAmountInputValue as oe}from"../../../../shared/ui/AmountInput/utils.js";import"../../../../shared/ui/AmountInput/index.js";import{toAssetDescriptor as i}from"../../../../shared/widgets/asset-descriptor.js";import{useQuoteCountdown as se}from"../../../../shared/quote/useQuoteCountdown.js";import"../../../../shared/quote/index.js";import{WithdrawForm as a}from"./compound/WithdrawForm.js";import"./compound/index.js";import{resolveSubmitLabel as ce}from"./validation.js";import{useCallback as o,useEffect as s,useMemo as c,useRef as le,useState as l}from"react";import{jsx as u,jsxs as ue}from"react/jsx-runtime";function d(){let d=te(),f=ee(),p=re(),m=ne(),{i18n:de,_:h}=n(),g=ae(),{balance:_,suggestedRecipient:fe}=r(),[v,pe]=l(``),[me,he]=l(``),ge=p.name===`submitting`,y=p.name===`form`?p.ctx?.notice:void 0,_e=le(y);_e.current=y;let b=d.withdrawableBalances.status===`ready`||d.withdrawableBalances.status===`stale`?d.withdrawableBalances.payload[0]:void 0,x=c(()=>i(b)??{symbol:`USDC`},[b]),ve=c(()=>i(b?{symbol:b.networkName,eip155Id:b.eip155Id,isNative:!0,logoUrl:b.chainLogoUrl}:void 0)??{symbol:`BSC`},[b]),S=typeof _==`number`?_:typeof _==`object`?_.amount:void 0,ye=b?.symbol??x.symbol,C=S??b?.amount.value,be=S===void 0?b?.symbol:ye,w=C!==void 0&&be!==void 0?{amount:S===void 0?b?.amount.formatted??ie(C,de):ie(S,de),symbol:be}:void 0,T=d.receiveOptions.status===`ready`||d.receiveOptions.status===`stale`?d.receiveOptions.payload:[],E=b?.eip155Id?Number(b.eip155Id):void 0,D=b?.symbol??x.symbol,O=c(()=>{let e=new Map;for(let t of T)for(let n of t.tokens){let r=n.symbol.toUpperCase(),ee=e.get(r);ee?ee.push({chain:t,token:n}):e.set(r,[{chain:t,token:n}])}return e},[T]),k=c(()=>{if(O.size===0)return;let e=D.toUpperCase();return O.has(e)?e:O.keys().next().value},[O,D]),A=o(e=>{let t=O.get(e);if(!(!t||t.length===0))return(E===void 0?void 0:t.find(e=>e.chain.eip155Id===E))??t[0]},[O,E]),[j,M]=l(void 0),[N,P]=l(void 0);s(()=>{if(N||!k)return;let e=A(k);e&&(M(e.chain),P(e.token))},[k,A,N]);let F=o(()=>{_e.current&&m.clearNotice()},[m]),xe=o(e=>{F(),pe(e),g({type:`withdraw.recipient.changed`,flow:`withdraw`,tier:`ui`,payload:{value:e}})},[F,g]),I=t().locale,L=o(e=>{F(),he(e),g({type:`withdraw.amount.changed`,flow:`withdraw`,tier:`ui`,payload:{raw:e,numeric:oe(e,I)}})},[F,g,I]),Se=o(e=>{F();let t=e.symbol.toUpperCase(),n=O.get(t)?.find(e=>e.chain.eip155Id===j?.eip155Id)??A(t);n&&(M(n.chain),P(n.token),g({type:`withdraw.receive.token.changed`,flow:`withdraw`,tier:`ui`,payload:{token:n.token}}),n.chain.eip155Id!==j?.eip155Id&&g({type:`withdraw.receive.chain.changed`,flow:`withdraw`,tier:`ui`,payload:{chain:n.chain}}))},[F,g,O,A,j?.eip155Id]),Ce=o(e=>{F(),M(e);let t=N?.symbol.toUpperCase(),n=(t?e.tokens.find(e=>e.symbol.toUpperCase()===t):void 0)??e.tokens[0];n&&P(n),g({type:`withdraw.receive.chain.changed`,flow:`withdraw`,tier:`ui`,payload:{chain:e}}),n!==void 0&&(N===void 0||n.address!==N.address)&&g({type:`withdraw.receive.token.changed`,flow:`withdraw`,tier:`ui`,payload:{token:n}})},[F,g,N]),R=oe(me,I),z=R!==null&&R>0,we=v.trim(),Te=we.length>0,Ee=j?.chainType??`unknown`,B=e(we,Ee),V=j!==void 0&&N!==void 0,H=z&&C!==void 0&&R>C,U=d.minAmountUsd,W=d.maxAmountUsd,De=b?.amountUsd&&b.amount.value>0?b.amountUsd.value/b.amount.value:void 0,G=De!==void 0&&R!==null?R*De:void 0,K=z&&G!==void 0&&U!==void 0&&U.value>0&&G<U.value,q=z&&G!==void 0&&W!==void 0&&W.value>0&&G>W.value,[J,Oe]=l(null),Y=(d.quote.status===`ready`||d.quote.status===`stale`)&&Te&&z&&V&&J!==null&&J.recipient===v&&J.amount===R&&J.receiveChainId===j.eip155Id&&J.receiveSymbol===N.symbol?d.quote.payload:void 0,ke=c(()=>O.size===0?[x]:[...O.values()].map(e=>{let t=e[0];return i({symbol:t.token.symbol,eip155Id:t.chain.eip155Id,address:t.token.address,isNative:t.token.isNative,logoUrl:t.token.assetLogoUrl})??{symbol:t.token.symbol}}),[O,x]),Ae=c(()=>{let e=N?.symbol.toUpperCase(),t=e?O.get(e):void 0;return(t?t.map(e=>e.chain):T).map(e=>i({symbol:e.networkName,eip155Id:e.eip155Id,isNative:!0,logoUrl:e.chainLogoUrl})??{symbol:e.networkName})},[N?.symbol,O,T]),je=N?i({symbol:N.symbol,eip155Id:j?.eip155Id,address:N.address,isNative:N.isNative,logoUrl:N.assetLogoUrl}):x,Me=j?i({symbol:j.networkName,eip155Id:j.eip155Id,isNative:!0,logoUrl:j.chainLogoUrl}):ve,Ne=c(()=>{if(Y?.breakdown)return{route:Y.breakdown.selectedRoute?.label,networkCost:Y.breakdown.networkCost?.formatted,priceImpact:Y.breakdown.priceImpact?.formatted}},[Y]),X=c(()=>{if(z)return Y?.receiveAmountUsd?Y.receiveAmountUsd.formatted:`$${R.toFixed(2)}`},[R,z,Y]),Pe=Y&&z?Y.receiveAmount.formatted:void 0,Fe=Y?.receiveAmountUsd?.formatted,Ie=B&&z&&!H&&!K&&!q&&V&&Y===void 0&&d.quote.status!==`error`,Z=B&&z&&!H&&!K&&!q&&V&&Y!==void 0,Le=se({expiresAt:Y?.expiresAt,enabled:Z}),Re=Z&&Y?Y.quoteTotalSeconds:void 0,[Q,ze]=l(!1);s(()=>{ze(!1)},[v,R,j?.eip155Id,N?.symbol,p.name]),s(()=>{if(!Z||!Y||p.name!==`form`||Q)return;let e=Math.max(0,Y.expiresAt-Date.now()),t=setTimeout(()=>{ze(!0),g({type:`withdraw.quote.expired`,flow:`withdraw`,tier:`flow`,payload:{}})},e);return()=>clearTimeout(t)},[g,Z,Y,p.name,Q]),s(()=>{if(!Q||p.name!==`form`||E===void 0||!j||!N||!B||!z||H||K||q)return;let e=new AbortController,t={recipient:v,amount:R??0,receiveChainId:j.eip155Id,receiveSymbol:N.symbol},n={sourceAssetSymbol:D,sourceChainId:E,amount:R??0,receiveTokenSymbol:N.symbol,receiveChainId:j.eip155Id,recipientAddress:v};return g({type:`withdraw.quote.requested`,flow:`withdraw`,tier:`flow`,payload:{input:n}}),f.requestQuote(n,e.signal).then(()=>{e.signal.aborted||Oe(t)}).catch(()=>{}).finally(()=>{e.signal.aborted||ze(!1)}),()=>e.abort()},[g,Q,f,v,R,B,z,H,K,q,E,D,j,N,p.name]);let $=!B||!z||H||K||q||!V||Ie||Q,Be=ce({enterRecipientAddress:h({id:`nr03QI`,message:`Enter Recipient Address`}),enterValidRecipientAddress:h({id:`GZPxmc`,message:`Enter Valid Recipient Address`}),enterAmount:h({id:`yH9V_J`,message:`Enter Amount`}),insufficientBalance:h({id:`N2DUxS`,message:`Insufficient Balance`}),...U?{belowMinimumAmount:h({id:`WkRH60`,message:`Min {0}`,values:{0:U.formatted}})}:{},...W?{aboveCapAmount:h({id:`AHyker`,message:`Max {0}`,values:{0:W.formatted}})}:{},regeneratingQuote:h({id:`Ly6geA`,message:`Regenerating quote…`}),estimatingQuote:h({id:`Uevt3L`,message:`Estimating quote`})},{isRecipientFilled:Te,isRecipientValid:B,isAmountValid:z,exceedsBalance:H,belowMinimum:K,aboveCap:q,quoteEstimating:Ie,quoteRegenerating:Q}),Ve=le(null);s(()=>{if(Ve.current?.abort(),!B||!z||H||K||q||!V||p.name!==`form`||E===void 0)return;let e=new AbortController;Ve.current=e;let t={recipient:v,amount:R,receiveChainId:j.eip155Id,receiveSymbol:N.symbol},n=setTimeout(()=>{let n={sourceAssetSymbol:D,sourceChainId:E,amount:R,receiveTokenSymbol:N.symbol,receiveChainId:j.eip155Id,recipientAddress:v};g({type:`withdraw.quote.requested`,flow:`withdraw`,tier:`flow`,payload:{input:n}}),f.requestQuote(n,e.signal).then(()=>{e.signal.aborted||Oe(t)}).catch(()=>{})},400);return()=>{clearTimeout(n),e.abort()}},[g,f,v,R,B,z,H,K,q,V,E,D,j?.eip155Id,N?.symbol,p.name]);let He=o(()=>{w&&(L(w.amount),g({type:`withdraw.max.clicked`,flow:`withdraw`,tier:`ui`,payload:{}}))},[w,g,L]),Ue=o(()=>{g({type:`withdraw.submit.clicked`,flow:`withdraw`,tier:`ui`,payload:{}}),!(ge||$)&&(E===void 0||!j||!N||m.submit({sourceAssetSymbol:D,sourceChainId:E,amount:R??0,recipientAddress:v,receiveTokenSymbol:N.symbol,receiveChainId:j.eip155Id,...X?{amountUsd:X}:{}}))},[m,R,X,g,E,D,j,N,v,$,ge]),We=o(e=>{let t=T.find(t=>String(t.eip155Id)===String(e.chainId));t&&Ce(t)},[Ce,T]),Ge=o(e=>{let t=e.symbol.toUpperCase(),n=O.get(t);!n||n.length===0||Se((n.find(e=>e.chain.eip155Id===j?.eip155Id)??n[0]).token)},[Se,O,j?.eip155Id]);return p.name!==`form`&&p.name!==`submitting`?null:ue(a,{recipientAddress:v,onRecipientChange:xe,recipientChainType:Ee,...fe?{suggestedRecipient:fe}:{},amount:me,onAmountChange:L,onAmountMax:He,sourceAsset:x,sourceChain:ve,receiveAsset:je,receiveChain:Me,receiveAssetOptions:ke,onReceiveAssetChange:Ge,receiveChainOptions:Ae,onReceiveChainChange:We,balance:w,amountUsd:X,receiveAmount:Pe,receiveAmountUsd:Fe,breakdown:Ne,quoteEstimating:Ie,quoteRegenerating:Q,...Le===void 0?{}:{quoteSeconds:Le},...Re===void 0?{}:{quoteTotalSeconds:Re},submitting:ge,submitDisabled:$,submitLabel:Be,...y?{notice:y}:{},onSubmit:Ue,onBreakdownOpenChange:e=>g({type:`withdraw.breakdown.clicked`,flow:`withdraw`,tier:`ui`,payload:{open:e}}),children:[u(a.Header,{}),ue(a.Body,{children:[u(a.RecipientField,{}),u(a.AmountField,{}),u(a.ReceiveSelectors,{}),u(a.BreakdownCard,{})]}),u(a.Footer,{})]})}export{d as WithdrawForm};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useLingui as e}from"../../../../shared/i18n/useLingui.js";import"../../../../i18n/index.js";import{useWithdrawSnapshot as t}from"../../driver/context.js";import{useWithdrawEffectiveState as n}from"../../orchestrator/controller.js";import{ProcessingState as r}from"../../../../shared/widgets/processing-state/compound/ProcessingState.js";import"../../../../shared/widgets/processing-state/compound/index.js";import{toAssetDescriptor as i}from"../../../../shared/widgets/asset-descriptor.js";import{jsx as a,jsxs as o}from"react/jsx-runtime";function s(s){let c=t(),l=n(),{_:u}=e(),d=c.settlement,f=(d.status===`ready`||d.status===`stale`)&&d.payload.kind===`pending`?d.payload:void 0;if(l.name!==`inProgress`)return null;let p=l.ctx.input,m=f?.txHash?.formatted,h=f?.txExplorerUrl,g=f?.recipient.formatted,_=c.quote,v=_.status===`ready`||_.status===`stale`?_.payload:void 0,y=i(f?.receiveAsset??v?.receiveAsset)??{symbol:p.receiveTokenSymbol},b=f?.receiveAmount,x=b&&b.value>0?b.formatted:v?.receiveAmount.formatted,S=x===void 0,C=f?.receiveAmountUsd?.formatted??v?.receiveAmountUsd?.formatted,w=m?{hash:m,explorerUrl:h}:void 0;return o(r,{...s,headerTitle:u({id:`w-2VR9`,message:`Withdrawal in progress…`}),amount:x??``,...C?{amountUsd:C}:{},...S?{loading:!0}:{},creditedAsset:y,creditedTo:g,sourceTx:w,submittedAt:f?.submittedAt.formatted,children:[a(r.Header,{}),o(r.Body,{children:[a(r.Hero,{}),a(r.StatusPill,{}),o(r.Details,{children:[a(r.SourceTxRow,{label:u({id:`60ahSE`,message:`Withdrawal tx`})}),a(r.SubmittedAtRow,{})]})]})]})}export{s as WithdrawInProgress};
|
|
1
|
+
"use client";import{useLingui as e}from"../../../../shared/i18n/useLingui.js";import"../../../../i18n/index.js";import{useWithdrawSnapshot as t}from"../../driver/context.js";import{useWithdrawEffectiveState as n}from"../../orchestrator/controller.js";import{ProcessingState as r}from"../../../../shared/widgets/processing-state/compound/ProcessingState.js";import"../../../../shared/widgets/processing-state/compound/index.js";import{toAssetDescriptor as i}from"../../../../shared/widgets/asset-descriptor.js";import{jsx as a,jsxs as o}from"react/jsx-runtime";function s(s){let c=t(),l=n(),{_:u}=e(),d=c.settlement,f=(d.status===`ready`||d.status===`stale`)&&d.payload.kind===`pending`?d.payload:void 0;if(l.name!==`inProgress`)return null;let p=l.ctx.input,m=f?.txHash?.formatted,h=f?.txExplorerUrl,g=f?.recipient.formatted,_=c.quote,v=_.status===`ready`||_.status===`stale`?_.payload:void 0,y=i(f?.receiveAsset??v?.receiveAsset)??{symbol:p.receiveTokenSymbol},b=f?.receiveAmount,x=b&&b.value>0?b.formatted:v?.receiveAmount.formatted,S=x===void 0,C=f?.receiveAmountUsd?.formatted??v?.receiveAmountUsd?.formatted??p.amountUsd,w=m?{hash:m,explorerUrl:h}:void 0;return o(r,{...s,headerTitle:u({id:`w-2VR9`,message:`Withdrawal in progress…`}),amount:x??``,...C?{amountUsd:C}:{},...S?{loading:!0}:{},creditedAsset:y,creditedTo:g,sourceTx:w,submittedAt:f?.submittedAt.formatted,children:[a(r.Header,{}),o(r.Body,{children:[a(r.Hero,{}),a(r.StatusPill,{}),o(r.Details,{children:[a(r.SourceTxRow,{label:u({id:`60ahSE`,message:`Withdrawal tx`})}),a(r.SubmittedAtRow,{})]})]})]})}export{s as WithdrawInProgress};
|
package/dist/package.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=`0.1.0-alpha.
|
|
1
|
+
var e=`0.1.0-alpha.35`;export{e as version};
|