@orbs-network/spot-react 1.1.28 → 1.1.29
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,8 +1,9 @@
|
|
|
1
|
-
import { Order } from '../../../spot-ui/src/index.ts';
|
|
1
|
+
import { Order, OrderFill } from '../../../spot-ui/src/index.ts';
|
|
2
2
|
import { Token } from '../types';
|
|
3
3
|
export declare const useDerivedHistoryOrder: (order: Order, srcToken?: Token, dstToken?: Token) => {
|
|
4
4
|
original: Order;
|
|
5
5
|
fills: {
|
|
6
|
+
rawFill: OrderFill;
|
|
6
7
|
srcToken: Token;
|
|
7
8
|
dstToken: Token;
|
|
8
9
|
srcAmount: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-history-order.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-history-order.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,
|
|
1
|
+
{"version":3,"file":"use-history-order.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-history-order.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,EACL,SAAS,EACV,MAAM,uBAAuB,CAAC;AAS/B,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AA8BjC,eAAO,MAAM,sBAAsB,GACjC,OAAO,KAAK,EACZ,WAAW,KAAK,EAChB,WAAW,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aA4EjB,CAAC"}
|
package/dist/spot-react.js
CHANGED
|
@@ -2759,7 +2759,7 @@ const Oi = async ({
|
|
|
2759
2759
|
partner: s == null ? void 0 : s.partner,
|
|
2760
2760
|
isDev: o
|
|
2761
2761
|
})
|
|
2762
|
-
]).then(([p, x]) => [...p, ...x])).sort((p, x) => x.createdAt - p.createdAt), ki = "1.1.
|
|
2762
|
+
]).then(([p, x]) => [...p, ...x])).sort((p, x) => x.createdAt - p.createdAt), ki = "1.1.29", Bi = {
|
|
2763
2763
|
version: ki
|
|
2764
2764
|
}, Dr = (e) => {
|
|
2765
2765
|
let t;
|
|
@@ -6230,6 +6230,7 @@ const Ms = ir(null), Ec = new Do({
|
|
|
6230
6230
|
}, xc = (e, t, n) => {
|
|
6231
6231
|
const r = pr();
|
|
6232
6232
|
return k(() => e == null ? void 0 : e.map((s) => ({
|
|
6233
|
+
rawFill: s,
|
|
6233
6234
|
srcToken: t,
|
|
6234
6235
|
dstToken: n,
|
|
6235
6236
|
srcAmount: Se(s.inAmount, t == null ? void 0 : t.decimals),
|
package/dist/spot-react.umd.cjs
CHANGED
|
@@ -61,4 +61,4 @@
|
|
|
61
61
|
dollarValueOut
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
`,extractResults:E=>{var x;return(((x=E.data)==null?void 0:x.orderFilleds)||[]).map(v=>({...v,timestamp:new Date(v.timestamp).getTime()}))}})};class oa extends Error{constructor(){super("No graph endpoint found"),this.name="NoGraphEndpointError"}}const ca=async({chainId:e,signal:t,page:n,limit:r,filters:s})=>{try{const i=await sa({chainId:e,signal:t,page:n,limit:r,filters:s}),[o,d]=await Promise.all([aa({chainId:e,orders:i,signal:t}),ia({chainId:e,orders:i,signal:t})]),h=i.map(C=>{const E=o==null?void 0:o.filter(x=>x.TWAP_id===Number(C.Contract_id)&&yt(x.exchange,C.exchange)&&yt(x.twapAddress,C.twapAddress));return na(C,e,E,ua(C,E||[],d))}).sort((C,E)=>E.createdAt-C.createdAt),f=new Set;return h.filter(C=>f.has(C.id)?!1:(f.add(C.id),!0))}catch{return[]}},ua=(e,t,n)=>{var d;const r=(d=n==null?void 0:n.find(h=>h.twapId===e.Contract_id.toString()&&yt(h.twapAddress,e.twapAddress)))==null?void 0:d.status,i=$r(t).reduce((h,f)=>h.plus(f.inAmount),new S(0)).toFixed(),o=zr(e.ask_srcAmount,i);return da(o,e.ask_deadline*1e3,r)},zr=(e,t)=>{if(!t||!e)return 0;const n=S(t).dividedBy(e).toNumber();return n>=.99?100:n<=0?0:Number((n*100).toFixed(2))},da=(e,t,n)=>e===100?pe.Completed:n==="CANCELLED"?pe.Cancelled:n==="COMPLETED"?pe.Completed:t>Date.now()?pe.Open:pe.Expired,la=async({signal:e,page:t,chainId:n,limit:r,config:s,account:i,isDev:o=!1})=>(await Promise.all([s?ca({chainId:n,signal:e,page:t,limit:r,filters:{accounts:[i],configs:s.twapConfig?[s.twapConfig]:[]}}):Promise.resolve([]),ea({chainId:n,signal:e,account:i,exchange:s==null?void 0:s.adapter,partner:s==null?void 0:s.partner,isDev:o})]).then(([f,C])=>[...f,...C])).sort((f,C)=>C.createdAt-f.createdAt),fa={version:"1.1.28"},Vr=e=>{let t;const n=new Set,r=(f,C)=>{const E=typeof f=="function"?f(t):f;if(!Object.is(E,t)){const x=t;t=C??(typeof E!="object"||E===null)?E:Object.assign({},t,E),n.forEach(v=>v(t,x))}},s=()=>t,d={setState:r,getState:s,getInitialState:()=>h,subscribe:f=>(n.add(f),()=>n.delete(f))},h=t=e(r,s,d);return d},ha=(e=>e?Vr(e):Vr),pa=e=>e;function ma(e,t=pa){const n=F.useSyncExternalStore(e.subscribe,F.useCallback(()=>t(e.getState()),[e,t]),F.useCallback(()=>t(e.getInitialState()),[e,t]));return F.useDebugValue(n),n}const Gr=e=>{const t=ha(e),n=r=>ma(t,r);return Object.assign(n,t),n},ya=(e=>e?Gr(e):Gr),gn={},Xr={currentTime:Date.now(),cancelOrders:{},swapExecutions:[gn],swapExecutionIndex:0},Q=ya((e,t)=>({state:Xr,updateState:n=>e(r=>({state:{...r.state,...n}})),updateSwapExecutionAtIndex:(n,r)=>e(s=>{const i=[...s.state.swapExecutions];return i[n]={...i[n]??gn,...r},{state:{...s.state,swapExecutions:i}}}),resetSwapExecutionAtIndex:()=>e(n=>{const r=[...n.state.swapExecutions];return r[n.state.swapExecutionIndex]=gn,{state:{...n.state,swapExecutions:r}}}),resetState:()=>{const n=t().state;e({state:{...Xr,currentTime:Date.now(),isMarketOrder:n.isMarketOrder,swapExecutions:[...n.swapExecutions,gn],swapExecutionIndex:n.swapExecutionIndex+1}})}}));var Se=(e=>(e[e.LOADING=1]="LOADING",e[e.SUCCESS=2]="SUCCESS",e[e.FAILED=3]="FAILED",e))(Se||{}),Jt=(e=>(e.TRIGGER_MARKET_PRICE="triggerMarketPriceDisclaimer",e.MARKET_PRICE="marketOrderDisclaimer",e.LIMIT_PRICE="limitOrderDisclaimer",e))(Jt||{}),tt=(e=>(e.WRAP="wrap",e.APPROVE="approve",e.CREATE="create",e))(tt||{});const Et=(e,t)=>!t||!e||S(e).isNaN()?"":S(e).multipliedBy(S(10).pow(t)).toFixed(0),Ee=(e,t)=>{try{return!t||!e||S(e).isNaN()?"":S(e).dividedBy(S(10).pow(t)).toFixed()}catch(n){return console.error(n),""}},ga=e=>{const t="An error occurred.";if(!e||!e.message)return t;try{return e.message.toLowerCase().includes("rejected")?"Transaction Rejected":t}catch{return t}},Vn=e=>{var t,n,r,s;if(e!=null&&e.message)return((n=(t=e.message)==null?void 0:t.toLowerCase())==null?void 0:n.includes("rejected"))||((s=(r=e.message)==null?void 0:r.toLowerCase())==null?void 0:s.includes("denied"))},Zr=(e,t)=>{const n=At(t);return n&&Ut(e.address)?n.wToken:e};function Gn(e){return e?e/864e5:0}function An(e){return e?e/6e4:0}const Aa=(e,t)=>e?V.TWAP_MARKET:t===1?V.LIMIT:V.TWAP_LIMIT,Xn=(e,t,n)=>{const r=At(n);return Ut((e==null?void 0:e.address)||"")&&yt((t==null?void 0:t.address)||"",(r==null?void 0:r.wToken.address)||"")},Zn=(e,t,n)=>{const r=At(n);return yt((e==null?void 0:e.address)||"",(r==null?void 0:r.wToken.address)||"")&&Ut((t==null?void 0:t.address)||"")},Rt=(e,t)=>{if(!t)return"";const n=At(t);return`${n==null?void 0:n.explorer}/tx/${e}`},Yn=(e,t)=>F.useMemo(()=>Et(t,e),[e,t]),en=(e,t)=>F.useMemo(()=>Ee(t,e),[e,t]),En=()=>{const{chainId:e}=q();return F.useMemo(()=>At(e),[e])},Ea=e=>{const t=En();return F.useMemo(()=>{if(!(!e||!t))return Rt(e,t.id)},[e,t])},nt=(e,t)=>F.useMemo(()=>!e||!t||S(e||"0").isZero()||S(t||"0").isZero()?"":S(e||"0").times(t).toFixed(),[e,t]),ba=()=>{const{srcToken:e,dstToken:t,chainId:n}=q();return F.useMemo(()=>Xn(e,t,n),[e,t,n])},Ta=()=>{const{srcToken:e,dstToken:t,chainId:n}=q();return F.useMemo(()=>Zn(e,t,n),[e,t,n])},wa=()=>{const e=ba(),t=Ta();return e||t},rt=()=>{const{srcToken:e,typedInputAmount:t}=q();return{amount:Yn(e==null?void 0:e.decimals,t),amountUI:t,error:S(t||0).isZero()?"enterAmount":void 0}},Ca=(e,t)=>{const{module:n,srcUsd1Token:r,marketPrice:s,minChunkSizeUsd:i,typedInputAmount:o}=q();return F.useMemo(()=>{if(S(o||"0").isZero()||!s||S(r||"0").isZero())return;if(!e)return{type:me.MIN_CHUNKS,value:1,args:{minChunks:"1"}};const{isError:d}=Ri(e,t,n);if(d)return{type:me.MAX_CHUNKS,value:t,args:{maxChunks:`${t}`}};const{isError:h,value:f}=Ui(o||"",r||"",i||0);if(h)return{type:me.MIN_TRADE_SIZE,value:f,args:{minTradeSize:`${f}`}}},[e,t,n,o,r,i,s])},qe=()=>{const{srcToken:e,srcUsd1Token:t,module:n,minChunkSizeUsd:r}=q(),s=Q(O=>O.state.typedChunks),i=Q(O=>O.updateState),{amount:o,amountUI:d}=rt(),h=F.useMemo(()=>xi(d||"",t||"",r||0),[d,t,r]),f=F.useMemo(()=>Ci(h,n,s),[h,s,n]),C=F.useCallback(O=>i({typedChunks:O}),[i]),E=F.useMemo(()=>Fi(o||"",f),[o,f]),x=en(e==null?void 0:e.decimals,E),v=F.useMemo(()=>t?S(x||"0").times(t||0).toString():"0",[x,t]);return{totalTrades:f,maxTrades:h,amountPerTradeUI:x,amountPerTrade:E,amountPerTradeUsd:v,onChange:C,error:Ca(f,h)}},xa=()=>{const{srcToken:e,dstToken:t}=q(),{onChange:n,totalTrades:r,amountPerTradeUsd:s,amountPerTradeUI:i,error:o,maxTrades:d,amountPerTrade:h}=qe();return{error:o,maxTrades:d,totalTrades:r,amountPerTradeUI:i,amountPerTrade:h,onChange:n,amountPerTradeUsd:s,fromToken:e,toToken:t}},Yr=e=>{const t=Gn(e);if(t>=1)return`${t.toFixed(t%1?1:0)} ${t===1?"day":"days"}`;const n=An(e)/60;if(n>=1)return`${n.toFixed(n%1?1:0)} ${n===1?"hour":"hours"}`;const r=An(e);return`${r.toFixed(r%1?1:0)} ${r===1?"minute":"minutes"}`},Sa=e=>{const{totalTrades:t}=qe(),{marketPrice:n,typedInputAmount:r}=q(),s=F.useMemo(()=>{const{isError:o,value:d}=Bi(e);if(!(!o||S(r||"0").isZero()||!n))return{type:me.MIN_FILL_DELAY,value:d,args:{fillDelay:Yr(d)}}},[e,r,n]),i=F.useMemo(()=>{const{isError:o,value:d}=Pi(e,t);if(!(!o||S(r||"0").isZero()||!n))return{type:me.MAX_FILL_DELAY,value:d,args:{fillDelay:Yr(d)}}},[e,r,n,t]);return s||i},Lt=()=>{const{callbacks:e}=q(),t=Q(i=>i.state.typedFillDelay),n=Q(i=>i.updateState),r=F.useMemo(()=>t||Bn,[t]),s=Sa(r);return{fillDelay:r,onChange:F.useCallback(i=>{var o;n({typedFillDelay:i}),(o=e==null?void 0:e.onFillDelayChange)==null||o.call(e,i)},[n,e]),error:s,milliseconds:r.unit*r.value}},va=()=>{const{onChange:e,fillDelay:t,error:n}=Lt(),r=F.useCallback(i=>e({unit:t.unit,value:Number(i)}),[e,t]),s=F.useCallback(i=>e({unit:i,value:t.value}),[e,t]);return{onInputChange:r,onUnitSelect:s,onChange:e,milliseconds:t.unit*t.value,fillDelay:t,error:n}},Fa=e=>{const{module:t,marketPrice:n}=q();return F.useMemo(()=>{const r=ki(t,e),s=_i(e);if(n){if(r.isError)return{type:me.MAX_ORDER_DURATION,value:r.value,args:{duration:`${Math.floor(Gn(r.value)).toFixed(0)} days`}};if(s.isError)return{type:me.MIN_ORDER_DURATION,value:s.value,args:{duration:`${Math.floor(An(s.value)).toFixed(0)} minutes`}}}},[e,t,n])},Jn=()=>{const{module:e,callbacks:t}=q(),n=Q(h=>h.state.typedDuration),r=Q(h=>h.updateState),s=qe().totalTrades,i=Lt().fillDelay,o=F.useMemo(()=>wi(e,s,i,n),[s,i,n,e]),d=Fa(o);return{duration:o,setDuration:F.useCallback(h=>{var f;r({typedDuration:h}),(f=t==null?void 0:t.onDurationChange)==null||f.call(t,h)},[r,t]),error:d}},Pa=()=>{const{duration:e,setDuration:t,error:n}=Jn(),r=F.useCallback(i=>{t({unit:e.unit,value:Number(i)})},[t,e]),s=F.useCallback(i=>{t({unit:i,value:e.value})},[t,e]);return{duration:e,onChange:t,milliseconds:e.unit*e.value,onInputChange:r,onUnitSelect:s,error:n}},Da=()=>{const{module:e}=q();return F.useMemo(()=>e===z.STOP_LOSS?ci:ui,[e])},er=()=>{const{module:e}=q(),t=Q(n=>n.state.isMarketOrder);return F.useMemo(()=>e!==z.STOP_LOSS&&e!==z.TAKE_PROFIT||t?void 0:e===z.STOP_LOSS?di:li,[e,t])},bn=()=>{const{srcToken:e,dstToken:t,marketPriceLoading:n}=q(),r=Q(f=>f.updateState),s=Q(f=>f.state.isInvertedTrade),i=Q(f=>f.state.typedTriggerPrice),o=Q(f=>f.state.typedLimitPrice),d=Q(f=>f.state.isMarketOrder);return{onInvert:F.useCallback(()=>{i!==void 0&&r({typedTriggerPrice:S(1).div(i).toFixed()}),o!==void 0&&r({typedLimitPrice:S(1).div(o).toFixed()}),r({isInvertedTrade:!s})},[r,s,i,o,n]),isInverted:s,fromToken:s?t:e,toToken:s?e:t,isMarketPrice:d}},Jr=({typedValue:e,tokenDecimals:t=18,initialPrice:n="0",percentage:r,setValue:s,setPercentage:i})=>{const{srcUsd1Token:o,dstUsd1Token:d}=q(),{isInverted:h}=bn(),f=F.useMemo(()=>S((()=>{if(e!==void 0){const k=h?S(e).isZero()?S(0):S(1).div(e):S(e);return Et(k.toFixed(),t)}if(r!==void 0&&S(n||"0").gt(0)&&!S(n||"0").isNaN()){const k=S(n||"0"),B=S(r||0).div(100);return k.plus(k.multipliedBy(B)).decimalPlaces(0).toFixed()}return S(n).gt(0)?n:""})()).decimalPlaces(0).toFixed(),[e,r,t,n,h]),C=F.useCallback(I=>{s(I),i(null)},[s,i]),E=F.useCallback(I=>{s(void 0),i(I)},[s,i]),x=F.useMemo(()=>{if(!n||S(n).isZero())return"";if(r!=null)return r;if(f){const I=S(n),B=S(f).minus(I).div(I).multipliedBy(100).decimalPlaces(2).toString();return S(B||"0").isZero()?"":B}return""},[f,n,r]),v=F.useMemo(()=>{let I="";if(e!==void 0)I=e;else{const k=Ee(f,t);if(S(k||"0").isZero())return"";I=h?S(1).div(k).toFixed():k}return I},[e,t,f,h]),O=nt(h?o:d,v||"0");return{amount:S(f).isNaN()?"":f,amountUI:S(v).isNaN()?"":v,selectedPercentage:x,onChange:C,onPercentageChange:E,isInverted:h,usd:S(O).isNaN()?"":O,isTypedValue:e!==void 0}},Oa=(e="")=>{const{module:t,marketPrice:n,typedInputAmount:r}=q();return F.useMemo(()=>{if(S(r||"0").isZero()||!n||t!==z.STOP_LOSS&&t!==z.TAKE_PROFIT)return;const s=Di(n||"",e||"",t);if(s!=null&&s.isError)return{type:me.STOP_LOSS_TRIGGER_PRICE_GREATER_THAN_MARKET_PRICE,value:s.value};const i=Oi(n||"",e||"",t);if(i!=null&&i.isError)return{type:me.TAKE_PROFIT_TRIGGER_PRICE_LESS_THAN_MARKET_PRICE,value:i.value};if(!e||S(e||0).isZero())return{type:me.EMPTY_TRIGGER_PRICE,value:e}},[n,e,t,r])},Ia=e=>{const{srcToken:t,dstToken:n,module:r,dstUsd1Token:s}=q(),i=qe().amountPerTrade,o=Q(f=>f.state.isMarketOrder),d=F.useMemo(()=>Ti(r,i,e,(t==null?void 0:t.decimals)||0),[e,i,o,t==null?void 0:t.decimals,r]),h=en((n==null?void 0:n.decimals)||0,d);return{amount:d,amountUI:h,usd:nt(h,s)}},bt=()=>{const{dstToken:e,marketPrice:t,module:n,callbacks:r}=q(),s=Q(O=>O.updateState),i=Da(),o=Q(O=>O.state.triggerPricePercent),d=o===void 0?i:o,h=n===z.STOP_LOSS||n===z.TAKE_PROFIT,f=Jr({typedValue:Q(O=>O.state.typedTriggerPrice),percentage:d,tokenDecimals:(e==null?void 0:e.decimals)||18,initialPrice:h?t:void 0,setValue:F.useCallback(O=>{var I;s({typedTriggerPrice:O}),(I=r==null?void 0:r.onTriggerPriceChange)==null||I.call(r,O||"")},[s,r]),setPercentage:F.useCallback(O=>{var I;s({triggerPricePercent:O}),(I=r==null?void 0:r.onTriggerPricePercentChange)==null||I.call(r,O||"")},[s,r])}),C=Oa(f.amount),{amount:E,amountUI:x,usd:v}=Ia(f.amount);return F.useMemo(()=>({...f,error:C,pricePerChunk:E,pricePerChunkUI:x,pricePerChunkUsd:v}),[f,C,E,x,v])},Ma=e=>{const{module:t,marketPrice:n,typedInputAmount:r}=q(),{amount:s}=bt(),i=Q(o=>o.state.isMarketOrder);return F.useMemo(()=>{if(S(r||"0").isZero()||!s||!n)return;const o=Ii(s,e,i,t),d=Mi(s,e,i,t);if(o!=null&&o.isError)return{type:me.TRIGGER_LIMIT_PRICE_GREATER_THAN_TRIGGER_PRICE,value:o.value};if(d!=null&&d.isError)return{type:me.TRIGGER_LIMIT_PRICE_GREATER_THAN_TRIGGER_PRICE,value:d.value};if(e&&S(e||0).isZero())return{type:me.MISSING_LIMIT_PRICE,value:e||""}},[e,s,t,i,r,n])},Tn=()=>{const{dstToken:e,marketPrice:t,callbacks:n}=q(),r=Q(f=>f.updateState),s=er(),i=Q(f=>f.state.limitPricePercent),o=i===void 0?s:i,d=Jr({typedValue:Q(f=>f.state.typedLimitPrice),percentage:o,tokenDecimals:(e==null?void 0:e.decimals)||18,initialPrice:t,setValue:F.useCallback(f=>{var C;r({typedLimitPrice:f}),(C=n==null?void 0:n.onLimitPriceChange)==null||C.call(n,f||"")},[r,n]),setPercentage:F.useCallback(f=>{var C;r({limitPricePercent:f}),(C=n==null?void 0:n.onLimitPricePercentChange)==null||C.call(n,f||"")},[r,n])}),h=Ma(d.amount);return F.useMemo(()=>({...d,error:h}),[d,h])},ka=()=>{const{module:e}=q(),t=Q(d=>d.updateState),n=Q(d=>d.state.isMarketOrder),r=er(),s=Q(d=>d.state.triggerPricePercent)||0,i=e===z.LIMIT,o=F.useCallback(()=>{!n&&e===z.STOP_LOSS&&t({limitPricePercent:r}),t({isMarketOrder:!n})},[t,s,e,n,r]);return{isLimitPrice:!n,toggleLimitPrice:o,hide:i}},_a=()=>{const{module:e,marketPriceLoading:t,srcToken:n,dstToken:r}=q(),{amount:s,amountUI:i,onChange:o,onPercentageChange:d,usd:h,selectedPercentage:f,error:C,isTypedValue:E}=Tn(),x=Q(K=>K.updateState),v=er(),{isLimitPrice:O,toggleLimitPrice:I}=ka(),{fromToken:k,toToken:B}=bn(),P=F.useCallback(()=>{x({typedLimitPrice:void 0}),x({limitPricePercent:v})},[x,e,v]);return{price:s,priceUI:i,error:C,onInputChange:o,onPercentageChange:d,onReset:P,usd:h,srcToken:n,dstToken:r,invertedSrcToken:k,invertedDstToken:B,percentage:f,isLoading:t,isLimitPrice:O,toggleLimitPrice:I,isTypedValue:E}},Ba=()=>{const{marketPrice:e,marketPriceLoading:t,srcToken:n,dstToken:r}=q(),{amount:s,amountUI:i,onChange:o,onPercentageChange:d,usd:h,selectedPercentage:f,error:C,pricePerChunk:E,pricePerChunkUI:x,pricePerChunkUsd:v,isTypedValue:O}=bt(),I=Q(K=>K.updateState),{fromToken:k,toToken:B}=bn(),P=F.useCallback(()=>{I({triggerPricePercent:void 0,typedTriggerPrice:void 0})},[I]);return{price:s,priceUI:i,amountPerChunk:E,amountPerChunkUI:x,amountPerChunkUsd:v,error:C,onInputChange:o,onPercentageChange:d,percentage:f,onReset:P,usd:h,srcToken:n,dstToken:r,invertedSrcToken:k,invertedDstToken:B,isLoading:t||!e,isTypedValue:O}},es=()=>{const{module:e,marketPrice:t}=q(),n=Tn().amount,r=bt().amount,s=Q(i=>i.state.isMarketOrder);return e===z.LIMIT||!s?n||"":e===z.STOP_LOSS||e===z.TAKE_PROFIT?r||"":t||""},wn=()=>{const{srcToken:e,dstToken:t,dstUsd1Token:n}=q(),r=es(),s=rt().amount,i=F.useMemo(()=>Ei(s||"",r,(e==null?void 0:e.decimals)||0),[s,r,e==null?void 0:e.decimals]),o=en(t==null?void 0:t.decimals,i);return{amount:i,amountUI:o,usd:nt(o,n)}},tr=()=>{const{srcToken:e,dstToken:t,dstUsd1Token:n}=q(),r=es(),s=qe().amountPerTrade,i=Q(h=>h.state.isMarketOrder),o=F.useMemo(()=>bi(s,r,!!i,(e==null?void 0:e.decimals)||0),[s,r,i,e==null?void 0:e.decimals]),d=en(t==null?void 0:t.decimals,o);return{amount:o,amountUI:d,usd:nt(d,n)}},Ua=()=>{const{typedInputAmount:e,marketPriceLoading:t,dstToken:n}=q(),{amountUI:r,usd:s}=wn(),o=wa()?e:r,d=Yn(n==null?void 0:n.decimals,o);return{value:o,valueWei:d,isLoading:t,usd:s}},Ra=()=>{const e=Q(s=>s.state.isMarketOrder),{module:t}=q(),n=F.useMemo(()=>{if(e&&t===z.STOP_LOSS)return Jt.TRIGGER_MARKET_PRICE},[e,t]),r=F.useMemo(()=>{if(!(t!==z.LIMIT&&t!==z.TWAP))return e?Jt.MARKET_PRICE:Jt.LIMIT_PRICE},[e,t]);return n||r},La=()=>{const{minChunkSizeUsd:e,typedInputAmount:t,srcUsd1Token:n}=q(),r=nt(t,n);return F.useMemo(()=>S(e).gt(S(r||"0"))?{type:me.MIN_TRADE_SIZE_ERROR,value:e}:void 0,[e,r])};function ts(){const{marketPrice:e,marketPriceLoading:t,typedInputAmount:n,srcUsd1Token:r,srcBalance:s,chainId:i}=q(),{error:o}=bt(),{error:d}=Tn(),{error:h}=qe(),{error:f}=Lt(),{error:C}=Jn(),E=La(),x=rt().amount,v=F.useMemo(()=>{if(s&&S(x).gt(s))return{type:me.INSUFFICIENT_BALANCE,value:s||""}},[s,x,i]);return F.useMemo(()=>Ni({marketPrice:e,typedInputAmount:n,srcUsd1Token:r,marketPriceLoading:t,triggerPriceError:o,limitPriceError:d,tradesError:h,fillDelayError:f,durationError:C,balanceError:v,minTradeSizeError:E}),[e,t,n,o,d,h,f,C,v,r,E])}var Nt=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},Na={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},qa=(Is=class{constructor(){N(this,Ke,Na);N(this,xt,!1)}setTimeoutProvider(e){process.env.NODE_ENV!=="production"&&l(this,xt)&&e!==l(this,Ke)&&console.error("[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.",{previous:l(this,Ke),provider:e}),_(this,Ke,e),process.env.NODE_ENV!=="production"&&_(this,xt,!1)}setTimeout(e,t){return process.env.NODE_ENV!=="production"&&_(this,xt,!0),l(this,Ke).setTimeout(e,t)}clearTimeout(e){l(this,Ke).clearTimeout(e)}setInterval(e,t){return process.env.NODE_ENV!=="production"&&_(this,xt,!0),l(this,Ke).setInterval(e,t)}clearInterval(e){l(this,Ke).clearInterval(e)}},Ke=new WeakMap,xt=new WeakMap,Is),Tt=new qa;function Ka(e){setTimeout(e,0)}var wt=typeof window>"u"||"Deno"in globalThis;function be(){}function Ha(e,t){return typeof e=="function"?e(t):e}function nr(e){return typeof e=="number"&&e>=0&&e!==1/0}function ns(e,t){return Math.max(e+(t||0)-Date.now(),0)}function st(e,t){return typeof e=="function"?e(t):e}function Me(e,t){return typeof e=="function"?e(t):e}function rs(e,t){const{type:n="all",exact:r,fetchStatus:s,predicate:i,queryKey:o,stale:d}=e;if(o){if(r){if(t.queryHash!==rr(o,t.options))return!1}else if(!tn(t.queryKey,o))return!1}if(n!=="all"){const h=t.isActive();if(n==="active"&&!h||n==="inactive"&&h)return!1}return!(typeof d=="boolean"&&t.isStale()!==d||s&&s!==t.state.fetchStatus||i&&!i(t))}function ss(e,t){const{exact:n,status:r,predicate:s,mutationKey:i}=e;if(i){if(!t.options.mutationKey)return!1;if(n){if(Ct(t.options.mutationKey)!==Ct(i))return!1}else if(!tn(t.options.mutationKey,i))return!1}return!(r&&t.state.status!==r||s&&!s(t))}function rr(e,t){return((t==null?void 0:t.queryKeyHashFn)||Ct)(e)}function Ct(e){return JSON.stringify(e,(t,n)=>ir(n)?Object.keys(n).sort().reduce((r,s)=>(r[s]=n[s],r),{}):n)}function tn(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?Object.keys(t).every(n=>tn(e[n],t[n])):!1}var Wa=Object.prototype.hasOwnProperty;function sr(e,t){if(e===t)return e;const n=is(e)&&is(t);if(!n&&!(ir(e)&&ir(t)))return t;const s=(n?e:Object.keys(e)).length,i=n?t:Object.keys(t),o=i.length,d=n?new Array(o):{};let h=0;for(let f=0;f<o;f++){const C=n?f:i[f],E=e[C],x=t[C];if(E===x){d[C]=E,(n?f<s:Wa.call(e,C))&&h++;continue}if(E===null||x===null||typeof E!="object"||typeof x!="object"){d[C]=x;continue}const v=sr(E,x);d[C]=v,v===E&&h++}return s===o&&h===s?e:d}function Cn(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(e[n]!==t[n])return!1;return!0}function is(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function ir(e){if(!as(e))return!1;const t=e.constructor;if(t===void 0)return!0;const n=t.prototype;return!(!as(n)||!n.hasOwnProperty("isPrototypeOf")||Object.getPrototypeOf(e)!==Object.prototype)}function as(e){return Object.prototype.toString.call(e)==="[object Object]"}function Qa(e){return new Promise(t=>{Tt.setTimeout(t,e)})}function ar(e,t,n){if(typeof n.structuralSharing=="function")return n.structuralSharing(e,t);if(n.structuralSharing!==!1){if(process.env.NODE_ENV!=="production")try{return sr(e,t)}catch(r){throw console.error(`Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${n.queryHash}]: ${r}`),r}return sr(e,t)}return t}function $a(e,t,n=0){const r=[...e,t];return n&&r.length>n?r.slice(1):r}function ja(e,t,n=0){const r=[t,...e];return n&&r.length>n?r.slice(0,-1):r}var xn=Symbol();function os(e,t){return process.env.NODE_ENV!=="production"&&e.queryFn===xn&&console.error(`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${e.queryHash}'`),!e.queryFn&&(t!=null&&t.initialPromise)?()=>t.initialPromise:!e.queryFn||e.queryFn===xn?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function cs(e,t){return typeof e=="function"?e(...t):!!e}var za=(Ms=class extends Nt{constructor(){super();N(this,St);N(this,at);N(this,qt);_(this,qt,t=>{if(!wt&&window.addEventListener){const n=()=>t();return window.addEventListener("visibilitychange",n,!1),()=>{window.removeEventListener("visibilitychange",n)}}})}onSubscribe(){l(this,at)||this.setEventListener(l(this,qt))}onUnsubscribe(){var t;this.hasListeners()||((t=l(this,at))==null||t.call(this),_(this,at,void 0))}setEventListener(t){var n;_(this,qt,t),(n=l(this,at))==null||n.call(this),_(this,at,t(r=>{typeof r=="boolean"?this.setFocused(r):this.onFocus()}))}setFocused(t){l(this,St)!==t&&(_(this,St,t),this.onFocus())}onFocus(){const t=this.isFocused();this.listeners.forEach(n=>{n(t)})}isFocused(){var t;return typeof l(this,St)=="boolean"?l(this,St):((t=globalThis.document)==null?void 0:t.visibilityState)!=="hidden"}},St=new WeakMap,at=new WeakMap,qt=new WeakMap,Ms),or=new za;function cr(){let e,t;const n=new Promise((s,i)=>{e=s,t=i});n.status="pending",n.catch(()=>{});function r(s){Object.assign(n,s),delete n.resolve,delete n.reject}return n.resolve=s=>{r({status:"fulfilled",value:s}),e(s)},n.reject=s=>{r({status:"rejected",reason:s}),t(s)},n}var Va=Ka;function Ga(){let e=[],t=0,n=d=>{d()},r=d=>{d()},s=Va;const i=d=>{t?e.push(d):s(()=>{n(d)})},o=()=>{const d=e;e=[],d.length&&s(()=>{r(()=>{d.forEach(h=>{n(h)})})})};return{batch:d=>{let h;t++;try{h=d()}finally{t--,t||o()}return h},batchCalls:d=>(...h)=>{i(()=>{d(...h)})},schedule:i,setNotifyFunction:d=>{n=d},setBatchNotifyFunction:d=>{r=d},setScheduler:d=>{s=d}}}var ue=Ga(),Xa=(ks=class extends Nt{constructor(){super();N(this,Kt,!0);N(this,ot);N(this,Ht);_(this,Ht,t=>{if(!wt&&window.addEventListener){const n=()=>t(!0),r=()=>t(!1);return window.addEventListener("online",n,!1),window.addEventListener("offline",r,!1),()=>{window.removeEventListener("online",n),window.removeEventListener("offline",r)}}})}onSubscribe(){l(this,ot)||this.setEventListener(l(this,Ht))}onUnsubscribe(){var t;this.hasListeners()||((t=l(this,ot))==null||t.call(this),_(this,ot,void 0))}setEventListener(t){var n;_(this,Ht,t),(n=l(this,ot))==null||n.call(this),_(this,ot,t(this.setOnline.bind(this)))}setOnline(t){l(this,Kt)!==t&&(_(this,Kt,t),this.listeners.forEach(r=>{r(t)}))}isOnline(){return l(this,Kt)}},Kt=new WeakMap,ot=new WeakMap,Ht=new WeakMap,ks),Sn=new Xa;function Za(e){return Math.min(1e3*2**e,3e4)}function us(e){return(e??"online")==="online"?Sn.isOnline():!0}var ur=class extends Error{constructor(e){super("CancelledError"),this.revert=e==null?void 0:e.revert,this.silent=e==null?void 0:e.silent}};function ds(e){let t=!1,n=0,r;const s=cr(),i=()=>s.status!=="pending",o=I=>{var k;if(!i()){const B=new ur(I);x(B),(k=e.onCancel)==null||k.call(e,B)}},d=()=>{t=!0},h=()=>{t=!1},f=()=>or.isFocused()&&(e.networkMode==="always"||Sn.isOnline())&&e.canRun(),C=()=>us(e.networkMode)&&e.canRun(),E=I=>{i()||(r==null||r(),s.resolve(I))},x=I=>{i()||(r==null||r(),s.reject(I))},v=()=>new Promise(I=>{var k;r=B=>{(i()||f())&&I(B)},(k=e.onPause)==null||k.call(e)}).then(()=>{var I;r=void 0,i()||(I=e.onContinue)==null||I.call(e)}),O=()=>{if(i())return;let I;const k=n===0?e.initialPromise:void 0;try{I=k??e.fn()}catch(B){I=Promise.reject(B)}Promise.resolve(I).then(E).catch(B=>{var Y;if(i())return;const P=e.retry??(wt?0:3),K=e.retryDelay??Za,U=typeof K=="function"?K(n,B):K,Z=P===!0||typeof P=="number"&&n<P||typeof P=="function"&&P(n,B);if(t||!Z){x(B);return}n++,(Y=e.onFail)==null||Y.call(e,n,B),Qa(U).then(()=>f()?void 0:v()).then(()=>{t?x(B):O()})})};return{promise:s,status:()=>s.status,cancel:o,continue:()=>(r==null||r(),s),cancelRetry:d,continueRetry:h,canStart:C,start:()=>(C()?O():v().then(O),s)}}var ls=(_s=class{constructor(){N(this,vt)}destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),nr(this.gcTime)&&_(this,vt,Tt.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(wt?1/0:300*1e3))}clearGcTimeout(){l(this,vt)&&(Tt.clearTimeout(l(this,vt)),_(this,vt,void 0))}},vt=new WeakMap,_s),Ya=(Bs=class extends ls{constructor(t){super();N(this,Le);N(this,Ft);N(this,Wt);N(this,ke);N(this,Pt);N(this,he);N(this,rn);N(this,Dt);_(this,Dt,!1),_(this,rn,t.defaultOptions),this.setOptions(t.options),this.observers=[],_(this,Pt,t.client),_(this,ke,l(this,Pt).getQueryCache()),this.queryKey=t.queryKey,this.queryHash=t.queryHash,_(this,Ft,ps(this.options)),this.state=t.state??l(this,Ft),this.scheduleGc()}get meta(){return this.options.meta}get promise(){var t;return(t=l(this,he))==null?void 0:t.promise}setOptions(t){if(this.options={...l(this,rn),...t},this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){const n=ps(this.options);n.data!==void 0&&(this.setState(hs(n.data,n.dataUpdatedAt)),_(this,Ft,n))}}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&l(this,ke).remove(this)}setData(t,n){const r=ar(this.state.data,t,this.options);return $(this,Le,Je).call(this,{data:r,type:"success",dataUpdatedAt:n==null?void 0:n.updatedAt,manual:n==null?void 0:n.manual}),r}setState(t,n){$(this,Le,Je).call(this,{type:"setState",state:t,setStateOptions:n})}cancel(t){var r,s;const n=(r=l(this,he))==null?void 0:r.promise;return(s=l(this,he))==null||s.cancel(t),n?n.then(be).catch(be):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(l(this,Ft))}isActive(){return this.observers.some(t=>Me(t.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===xn||this.state.dataUpdateCount+this.state.errorUpdateCount===0}isStatic(){return this.getObserversCount()>0?this.observers.some(t=>st(t.options.staleTime,this)==="static"):!1}isStale(){return this.getObserversCount()>0?this.observers.some(t=>t.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(t=0){return this.state.data===void 0?!0:t==="static"?!1:this.state.isInvalidated?!0:!ns(this.state.dataUpdatedAt,t)}onFocus(){var n;const t=this.observers.find(r=>r.shouldFetchOnWindowFocus());t==null||t.refetch({cancelRefetch:!1}),(n=l(this,he))==null||n.continue()}onOnline(){var n;const t=this.observers.find(r=>r.shouldFetchOnReconnect());t==null||t.refetch({cancelRefetch:!1}),(n=l(this,he))==null||n.continue()}addObserver(t){this.observers.includes(t)||(this.observers.push(t),this.clearGcTimeout(),l(this,ke).notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){this.observers.includes(t)&&(this.observers=this.observers.filter(n=>n!==t),this.observers.length||(l(this,he)&&(l(this,Dt)?l(this,he).cancel({revert:!0}):l(this,he).cancelRetry()),this.scheduleGc()),l(this,ke).notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||$(this,Le,Je).call(this,{type:"invalidate"})}async fetch(t,n){var h,f,C,E,x,v,O,I,k,B,P,K;if(this.state.fetchStatus!=="idle"&&((h=l(this,he))==null?void 0:h.status())!=="rejected"){if(this.state.data!==void 0&&(n!=null&&n.cancelRefetch))this.cancel({silent:!0});else if(l(this,he))return l(this,he).continueRetry(),l(this,he).promise}if(t&&this.setOptions(t),!this.options.queryFn){const U=this.observers.find(Z=>Z.options.queryFn);U&&this.setOptions(U.options)}process.env.NODE_ENV!=="production"&&(Array.isArray(this.options.queryKey)||console.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"));const r=new AbortController,s=U=>{Object.defineProperty(U,"signal",{enumerable:!0,get:()=>(_(this,Dt,!0),r.signal)})},i=()=>{const U=os(this.options,n),Y=(()=>{const oe={client:l(this,Pt),queryKey:this.queryKey,meta:this.meta};return s(oe),oe})();return _(this,Dt,!1),this.options.persister?this.options.persister(U,Y,this):U(Y)},d=(()=>{const U={fetchOptions:n,options:this.options,queryKey:this.queryKey,client:l(this,Pt),state:this.state,fetchFn:i};return s(U),U})();(f=this.options.behavior)==null||f.onFetch(d,this),_(this,Wt,this.state),(this.state.fetchStatus==="idle"||this.state.fetchMeta!==((C=d.fetchOptions)==null?void 0:C.meta))&&$(this,Le,Je).call(this,{type:"fetch",meta:(E=d.fetchOptions)==null?void 0:E.meta}),_(this,he,ds({initialPromise:n==null?void 0:n.initialPromise,fn:d.fetchFn,onCancel:U=>{U instanceof ur&&U.revert&&this.setState({...l(this,Wt),fetchStatus:"idle"}),r.abort()},onFail:(U,Z)=>{$(this,Le,Je).call(this,{type:"failed",failureCount:U,error:Z})},onPause:()=>{$(this,Le,Je).call(this,{type:"pause"})},onContinue:()=>{$(this,Le,Je).call(this,{type:"continue"})},retry:d.options.retry,retryDelay:d.options.retryDelay,networkMode:d.options.networkMode,canRun:()=>!0}));try{const U=await l(this,he).start();if(U===void 0)throw process.env.NODE_ENV!=="production"&&console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`),new Error(`${this.queryHash} data is undefined`);return this.setData(U),(v=(x=l(this,ke).config).onSuccess)==null||v.call(x,U,this),(I=(O=l(this,ke).config).onSettled)==null||I.call(O,U,this.state.error,this),U}catch(U){if(U instanceof ur){if(U.silent)return l(this,he).promise;if(U.revert){if(this.state.data===void 0)throw U;return this.state.data}}throw $(this,Le,Je).call(this,{type:"error",error:U}),(B=(k=l(this,ke).config).onError)==null||B.call(k,U,this),(K=(P=l(this,ke).config).onSettled)==null||K.call(P,this.state.data,U,this),U}finally{this.scheduleGc()}}},Ft=new WeakMap,Wt=new WeakMap,ke=new WeakMap,Pt=new WeakMap,he=new WeakMap,rn=new WeakMap,Dt=new WeakMap,Le=new WeakSet,Je=function(t){const n=r=>{switch(t.type){case"failed":return{...r,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...r,fetchStatus:"paused"};case"continue":return{...r,fetchStatus:"fetching"};case"fetch":return{...r,...fs(r.data,this.options),fetchMeta:t.meta??null};case"success":const s={...r,...hs(t.data,t.dataUpdatedAt),dataUpdateCount:r.dataUpdateCount+1,...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};return _(this,Wt,t.manual?s:void 0),s;case"error":const i=t.error;return{...r,error:i,errorUpdateCount:r.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:r.fetchFailureCount+1,fetchFailureReason:i,fetchStatus:"idle",status:"error"};case"invalidate":return{...r,isInvalidated:!0};case"setState":return{...r,...t.state}}};this.state=n(this.state),ue.batch(()=>{this.observers.forEach(r=>{r.onQueryUpdate()}),l(this,ke).notify({query:this,type:"updated",action:t})})},Bs);function fs(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:us(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}function hs(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:"success"}}function ps(e){const t=typeof e.initialData=="function"?e.initialData():e.initialData,n=t!==void 0,r=n?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:n?r??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:n?"success":"pending",fetchStatus:"idle"}}var Ja=(Us=class extends Nt{constructor(t,n){super();N(this,ee);N(this,ve);N(this,X);N(this,sn);N(this,Te);N(this,Ot);N(this,Qt);N(this,Ve);N(this,ct);N(this,an);N(this,$t);N(this,jt);N(this,It);N(this,Mt);N(this,ut);N(this,zt,new Set);this.options=n,_(this,ve,t),_(this,ct,null),_(this,Ve,cr()),this.bindMethods(),this.setOptions(n)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(l(this,X).addObserver(this),ms(l(this,X),this.options)?$(this,ee,dn).call(this):this.updateResult(),$(this,ee,wr).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return dr(l(this,X),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return dr(l(this,X),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,$(this,ee,Cr).call(this),$(this,ee,xr).call(this),l(this,X).removeObserver(this)}setOptions(t){const n=this.options,r=l(this,X);if(this.options=l(this,ve).defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof Me(this.options.enabled,l(this,X))!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");$(this,ee,Sr).call(this),l(this,X).setOptions(this.options),n._defaulted&&!Cn(this.options,n)&&l(this,ve).getQueryCache().notify({type:"observerOptionsUpdated",query:l(this,X),observer:this});const s=this.hasListeners();s&&ys(l(this,X),r,this.options,n)&&$(this,ee,dn).call(this),this.updateResult(),s&&(l(this,X)!==r||Me(this.options.enabled,l(this,X))!==Me(n.enabled,l(this,X))||st(this.options.staleTime,l(this,X))!==st(n.staleTime,l(this,X)))&&$(this,ee,Er).call(this);const i=$(this,ee,br).call(this);s&&(l(this,X)!==r||Me(this.options.enabled,l(this,X))!==Me(n.enabled,l(this,X))||i!==l(this,ut))&&$(this,ee,Tr).call(this,i)}getOptimisticResult(t){const n=l(this,ve).getQueryCache().build(l(this,ve),t),r=this.createResult(n,t);return to(this,r)&&(_(this,Te,r),_(this,Qt,this.options),_(this,Ot,l(this,X).state)),r}getCurrentResult(){return l(this,Te)}trackResult(t,n){return new Proxy(t,{get:(r,s)=>(this.trackProp(s),n==null||n(s),s==="promise"&&(this.trackProp("data"),!this.options.experimental_prefetchInRender&&l(this,Ve).status==="pending"&&l(this,Ve).reject(new Error("experimental_prefetchInRender feature flag is not enabled"))),Reflect.get(r,s))})}trackProp(t){l(this,zt).add(t)}getCurrentQuery(){return l(this,X)}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const n=l(this,ve).defaultQueryOptions(t),r=l(this,ve).getQueryCache().build(l(this,ve),n);return r.fetch().then(()=>this.createResult(r,n))}fetch(t){return $(this,ee,dn).call(this,{...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),l(this,Te)))}createResult(t,n){var c;const r=l(this,X),s=this.options,i=l(this,Te),o=l(this,Ot),d=l(this,Qt),f=t!==r?t.state:l(this,sn),{state:C}=t;let E={...C},x=!1,v;if(n._optimisticResults){const u=this.hasListeners(),A=!u&&ms(t,n),m=u&&ys(t,r,n,s);(A||m)&&(E={...E,...fs(C.data,t.options)}),n._optimisticResults==="isRestoring"&&(E.fetchStatus="idle")}let{error:O,errorUpdatedAt:I,status:k}=E;v=E.data;let B=!1;if(n.placeholderData!==void 0&&v===void 0&&k==="pending"){let u;i!=null&&i.isPlaceholderData&&n.placeholderData===(d==null?void 0:d.placeholderData)?(u=i.data,B=!0):u=typeof n.placeholderData=="function"?n.placeholderData((c=l(this,jt))==null?void 0:c.state.data,l(this,jt)):n.placeholderData,u!==void 0&&(k="success",v=ar(i==null?void 0:i.data,u,n),x=!0)}if(n.select&&v!==void 0&&!B)if(i&&v===(o==null?void 0:o.data)&&n.select===l(this,an))v=l(this,$t);else try{_(this,an,n.select),v=n.select(v),v=ar(i==null?void 0:i.data,v,n),_(this,$t,v),_(this,ct,null)}catch(u){_(this,ct,u)}l(this,ct)&&(O=l(this,ct),v=l(this,$t),I=Date.now(),k="error");const P=E.fetchStatus==="fetching",K=k==="pending",U=k==="error",Z=K&&P,Y=v!==void 0,a={status:k,fetchStatus:E.fetchStatus,isPending:K,isSuccess:k==="success",isError:U,isInitialLoading:Z,isLoading:Z,data:v,dataUpdatedAt:E.dataUpdatedAt,error:O,errorUpdatedAt:I,failureCount:E.fetchFailureCount,failureReason:E.fetchFailureReason,errorUpdateCount:E.errorUpdateCount,isFetched:E.dataUpdateCount>0||E.errorUpdateCount>0,isFetchedAfterMount:E.dataUpdateCount>f.dataUpdateCount||E.errorUpdateCount>f.errorUpdateCount,isFetching:P,isRefetching:P&&!K,isLoadingError:U&&!Y,isPaused:E.fetchStatus==="paused",isPlaceholderData:x,isRefetchError:U&&Y,isStale:lr(t,n),refetch:this.refetch,promise:l(this,Ve),isEnabled:Me(n.enabled,t)!==!1};if(this.options.experimental_prefetchInRender){const u=y=>{a.status==="error"?y.reject(a.error):a.data!==void 0&&y.resolve(a.data)},A=()=>{const y=_(this,Ve,a.promise=cr());u(y)},m=l(this,Ve);switch(m.status){case"pending":t.queryHash===r.queryHash&&u(m);break;case"fulfilled":(a.status==="error"||a.data!==m.value)&&A();break;case"rejected":(a.status!=="error"||a.error!==m.reason)&&A();break}}return a}updateResult(){const t=l(this,Te),n=this.createResult(l(this,X),this.options);if(_(this,Ot,l(this,X).state),_(this,Qt,this.options),l(this,Ot).data!==void 0&&_(this,jt,l(this,X)),Cn(n,t))return;_(this,Te,n);const r=()=>{if(!t)return!0;const{notifyOnChangeProps:s}=this.options,i=typeof s=="function"?s():s;if(i==="all"||!i&&!l(this,zt).size)return!0;const o=new Set(i??l(this,zt));return this.options.throwOnError&&o.add("error"),Object.keys(l(this,Te)).some(d=>{const h=d;return l(this,Te)[h]!==t[h]&&o.has(h)})};$(this,ee,Ws).call(this,{listeners:r()})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&$(this,ee,wr).call(this)}},ve=new WeakMap,X=new WeakMap,sn=new WeakMap,Te=new WeakMap,Ot=new WeakMap,Qt=new WeakMap,Ve=new WeakMap,ct=new WeakMap,an=new WeakMap,$t=new WeakMap,jt=new WeakMap,It=new WeakMap,Mt=new WeakMap,ut=new WeakMap,zt=new WeakMap,ee=new WeakSet,dn=function(t){$(this,ee,Sr).call(this);let n=l(this,X).fetch(this.options,t);return t!=null&&t.throwOnError||(n=n.catch(be)),n},Er=function(){$(this,ee,Cr).call(this);const t=st(this.options.staleTime,l(this,X));if(wt||l(this,Te).isStale||!nr(t))return;const r=ns(l(this,Te).dataUpdatedAt,t)+1;_(this,It,Tt.setTimeout(()=>{l(this,Te).isStale||this.updateResult()},r))},br=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(l(this,X)):this.options.refetchInterval)??!1},Tr=function(t){$(this,ee,xr).call(this),_(this,ut,t),!(wt||Me(this.options.enabled,l(this,X))===!1||!nr(l(this,ut))||l(this,ut)===0)&&_(this,Mt,Tt.setInterval(()=>{(this.options.refetchIntervalInBackground||or.isFocused())&&$(this,ee,dn).call(this)},l(this,ut)))},wr=function(){$(this,ee,Er).call(this),$(this,ee,Tr).call(this,$(this,ee,br).call(this))},Cr=function(){l(this,It)&&(Tt.clearTimeout(l(this,It)),_(this,It,void 0))},xr=function(){l(this,Mt)&&(Tt.clearInterval(l(this,Mt)),_(this,Mt,void 0))},Sr=function(){const t=l(this,ve).getQueryCache().build(l(this,ve),this.options);if(t===l(this,X))return;const n=l(this,X);_(this,X,t),_(this,sn,t.state),this.hasListeners()&&(n==null||n.removeObserver(this),t.addObserver(this))},Ws=function(t){ue.batch(()=>{t.listeners&&this.listeners.forEach(n=>{n(l(this,Te))}),l(this,ve).getQueryCache().notify({query:l(this,X),type:"observerResultsUpdated"})})},Us);function eo(e,t){return Me(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status==="error"&&t.retryOnMount===!1)}function ms(e,t){return eo(e,t)||e.state.data!==void 0&&dr(e,t,t.refetchOnMount)}function dr(e,t,n){if(Me(t.enabled,e)!==!1&&st(t.staleTime,e)!=="static"){const r=typeof n=="function"?n(e):n;return r==="always"||r!==!1&&lr(e,t)}return!1}function ys(e,t,n,r){return(e!==t||Me(r.enabled,e)===!1)&&(!n.suspense||e.state.status!=="error")&&lr(e,n)}function lr(e,t){return Me(t.enabled,e)!==!1&&e.isStaleByTime(st(t.staleTime,e))}function to(e,t){return!Cn(e.getCurrentResult(),t)}function gs(e){return{onFetch:(t,n)=>{var C,E,x,v,O;const r=t.options,s=(x=(E=(C=t.fetchOptions)==null?void 0:C.meta)==null?void 0:E.fetchMore)==null?void 0:x.direction,i=((v=t.state.data)==null?void 0:v.pages)||[],o=((O=t.state.data)==null?void 0:O.pageParams)||[];let d={pages:[],pageParams:[]},h=0;const f=async()=>{let I=!1;const k=K=>{Object.defineProperty(K,"signal",{enumerable:!0,get:()=>(t.signal.aborted?I=!0:t.signal.addEventListener("abort",()=>{I=!0}),t.signal)})},B=os(t.options,t.fetchOptions),P=async(K,U,Z)=>{if(I)return Promise.reject();if(U==null&&K.pages.length)return Promise.resolve(K);const oe=(()=>{const A={client:t.client,queryKey:t.queryKey,pageParam:U,direction:Z?"backward":"forward",meta:t.options.meta};return k(A),A})(),a=await B(oe),{maxPages:c}=t.options,u=Z?ja:$a;return{pages:u(K.pages,a,c),pageParams:u(K.pageParams,U,c)}};if(s&&i.length){const K=s==="backward",U=K?no:As,Z={pages:i,pageParams:o},Y=U(r,Z);d=await P(Z,Y,K)}else{const K=e??i.length;do{const U=h===0?o[0]??r.initialPageParam:As(r,d);if(h>0&&U==null)break;d=await P(d,U),h++}while(h<K)}return d};t.options.persister?t.fetchFn=()=>{var I,k;return(k=(I=t.options).persister)==null?void 0:k.call(I,f,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},n)}:t.fetchFn=f}}}function As(e,{pages:t,pageParams:n}){const r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,n[r],n):void 0}function no(e,{pages:t,pageParams:n}){var r;return t.length>0?(r=e.getPreviousPageParam)==null?void 0:r.call(e,t[0],t,n[0],n):void 0}var ro=(Rs=class extends ls{constructor(t){super();N(this,We);N(this,on);N(this,He);N(this,we);N(this,kt);_(this,on,t.client),this.mutationId=t.mutationId,_(this,we,t.mutationCache),_(this,He,[]),this.state=t.state||Es(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options=t,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){l(this,He).includes(t)||(l(this,He).push(t),this.clearGcTimeout(),l(this,we).notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){_(this,He,l(this,He).filter(n=>n!==t)),this.scheduleGc(),l(this,we).notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){l(this,He).length||(this.state.status==="pending"?this.scheduleGc():l(this,we).remove(this))}continue(){var t;return((t=l(this,kt))==null?void 0:t.continue())??this.execute(this.state.variables)}async execute(t){var o,d,h,f,C,E,x,v,O,I,k,B,P,K,U,Z,Y,oe,a,c;const n=()=>{$(this,We,pt).call(this,{type:"continue"})},r={client:l(this,on),meta:this.options.meta,mutationKey:this.options.mutationKey};_(this,kt,ds({fn:()=>this.options.mutationFn?this.options.mutationFn(t,r):Promise.reject(new Error("No mutationFn found")),onFail:(u,A)=>{$(this,We,pt).call(this,{type:"failed",failureCount:u,error:A})},onPause:()=>{$(this,We,pt).call(this,{type:"pause"})},onContinue:n,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>l(this,we).canRun(this)}));const s=this.state.status==="pending",i=!l(this,kt).canStart();try{if(s)n();else{$(this,We,pt).call(this,{type:"pending",variables:t,isPaused:i}),await((d=(o=l(this,we).config).onMutate)==null?void 0:d.call(o,t,this,r));const A=await((f=(h=this.options).onMutate)==null?void 0:f.call(h,t,r));A!==this.state.context&&$(this,We,pt).call(this,{type:"pending",context:A,variables:t,isPaused:i})}const u=await l(this,kt).start();return await((E=(C=l(this,we).config).onSuccess)==null?void 0:E.call(C,u,t,this.state.context,this,r)),await((v=(x=this.options).onSuccess)==null?void 0:v.call(x,u,t,this.state.context,r)),await((I=(O=l(this,we).config).onSettled)==null?void 0:I.call(O,u,null,this.state.variables,this.state.context,this,r)),await((B=(k=this.options).onSettled)==null?void 0:B.call(k,u,null,t,this.state.context,r)),$(this,We,pt).call(this,{type:"success",data:u}),u}catch(u){try{throw await((K=(P=l(this,we).config).onError)==null?void 0:K.call(P,u,t,this.state.context,this,r)),await((Z=(U=this.options).onError)==null?void 0:Z.call(U,u,t,this.state.context,r)),await((oe=(Y=l(this,we).config).onSettled)==null?void 0:oe.call(Y,void 0,u,this.state.variables,this.state.context,this,r)),await((c=(a=this.options).onSettled)==null?void 0:c.call(a,void 0,u,t,this.state.context,r)),u}finally{$(this,We,pt).call(this,{type:"error",error:u})}}finally{l(this,we).runNext(this)}}},on=new WeakMap,He=new WeakMap,we=new WeakMap,kt=new WeakMap,We=new WeakSet,pt=function(t){const n=r=>{switch(t.type){case"failed":return{...r,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...r,isPaused:!0};case"continue":return{...r,isPaused:!1};case"pending":return{...r,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:t.isPaused,status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...r,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...r,data:void 0,error:t.error,failureCount:r.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=n(this.state),ue.batch(()=>{l(this,He).forEach(r=>{r.onMutationUpdate(t)}),l(this,we).notify({mutation:this,type:"updated",action:t})})},Rs);function Es(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var so=(Ls=class extends Nt{constructor(t={}){super();N(this,Ge);N(this,Ne);N(this,cn);this.config=t,_(this,Ge,new Set),_(this,Ne,new Map),_(this,cn,0)}build(t,n,r){const s=new ro({client:t,mutationCache:this,mutationId:++On(this,cn)._,options:t.defaultMutationOptions(n),state:r});return this.add(s),s}add(t){l(this,Ge).add(t);const n=vn(t);if(typeof n=="string"){const r=l(this,Ne).get(n);r?r.push(t):l(this,Ne).set(n,[t])}this.notify({type:"added",mutation:t})}remove(t){if(l(this,Ge).delete(t)){const n=vn(t);if(typeof n=="string"){const r=l(this,Ne).get(n);if(r)if(r.length>1){const s=r.indexOf(t);s!==-1&&r.splice(s,1)}else r[0]===t&&l(this,Ne).delete(n)}}this.notify({type:"removed",mutation:t})}canRun(t){const n=vn(t);if(typeof n=="string"){const r=l(this,Ne).get(n),s=r==null?void 0:r.find(i=>i.state.status==="pending");return!s||s===t}else return!0}runNext(t){var r;const n=vn(t);if(typeof n=="string"){const s=(r=l(this,Ne).get(n))==null?void 0:r.find(i=>i!==t&&i.state.isPaused);return(s==null?void 0:s.continue())??Promise.resolve()}else return Promise.resolve()}clear(){ue.batch(()=>{l(this,Ge).forEach(t=>{this.notify({type:"removed",mutation:t})}),l(this,Ge).clear(),l(this,Ne).clear()})}getAll(){return Array.from(l(this,Ge))}find(t){const n={exact:!0,...t};return this.getAll().find(r=>ss(n,r))}findAll(t={}){return this.getAll().filter(n=>ss(t,n))}notify(t){ue.batch(()=>{this.listeners.forEach(n=>{n(t)})})}resumePausedMutations(){const t=this.getAll().filter(n=>n.state.isPaused);return ue.batch(()=>Promise.all(t.map(n=>n.continue().catch(be))))}},Ge=new WeakMap,Ne=new WeakMap,cn=new WeakMap,Ls);function vn(e){var t;return(t=e.options.scope)==null?void 0:t.id}var io=(Ns=class extends Nt{constructor(t,n){super();N(this,Ye);N(this,Xe);N(this,dt);N(this,Fe);N(this,Ze);_(this,Xe,t),this.setOptions(n),this.bindMethods(),$(this,Ye,In).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){var r;const n=this.options;this.options=l(this,Xe).defaultMutationOptions(t),Cn(this.options,n)||l(this,Xe).getMutationCache().notify({type:"observerOptionsUpdated",mutation:l(this,Fe),observer:this}),n!=null&&n.mutationKey&&this.options.mutationKey&&Ct(n.mutationKey)!==Ct(this.options.mutationKey)?this.reset():((r=l(this,Fe))==null?void 0:r.state.status)==="pending"&&l(this,Fe).setOptions(this.options)}onUnsubscribe(){var t;this.hasListeners()||(t=l(this,Fe))==null||t.removeObserver(this)}onMutationUpdate(t){$(this,Ye,In).call(this),$(this,Ye,vr).call(this,t)}getCurrentResult(){return l(this,dt)}reset(){var t;(t=l(this,Fe))==null||t.removeObserver(this),_(this,Fe,void 0),$(this,Ye,In).call(this),$(this,Ye,vr).call(this)}mutate(t,n){var r;return _(this,Ze,n),(r=l(this,Fe))==null||r.removeObserver(this),_(this,Fe,l(this,Xe).getMutationCache().build(l(this,Xe),this.options)),l(this,Fe).addObserver(this),l(this,Fe).execute(t)}},Xe=new WeakMap,dt=new WeakMap,Fe=new WeakMap,Ze=new WeakMap,Ye=new WeakSet,In=function(){var n;const t=((n=l(this,Fe))==null?void 0:n.state)??Es();_(this,dt,{...t,isPending:t.status==="pending",isSuccess:t.status==="success",isError:t.status==="error",isIdle:t.status==="idle",mutate:this.mutate,reset:this.reset})},vr=function(t){ue.batch(()=>{var n,r,s,i,o,d,h,f;if(l(this,Ze)&&this.hasListeners()){const C=l(this,dt).variables,E=l(this,dt).context,x={client:l(this,Xe),meta:this.options.meta,mutationKey:this.options.mutationKey};(t==null?void 0:t.type)==="success"?((r=(n=l(this,Ze)).onSuccess)==null||r.call(n,t.data,C,E,x),(i=(s=l(this,Ze)).onSettled)==null||i.call(s,t.data,null,C,E,x)):(t==null?void 0:t.type)==="error"&&((d=(o=l(this,Ze)).onError)==null||d.call(o,t.error,C,E,x),(f=(h=l(this,Ze)).onSettled)==null||f.call(h,void 0,t.error,C,E,x))}this.listeners.forEach(C=>{C(l(this,dt))})})},Ns),ao=(qs=class extends Nt{constructor(t={}){super();N(this,Qe);this.config=t,_(this,Qe,new Map)}build(t,n,r){const s=n.queryKey,i=n.queryHash??rr(s,n);let o=this.get(i);return o||(o=new Ya({client:t,queryKey:s,queryHash:i,options:t.defaultQueryOptions(n),state:r,defaultOptions:t.getQueryDefaults(s)}),this.add(o)),o}add(t){l(this,Qe).has(t.queryHash)||(l(this,Qe).set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const n=l(this,Qe).get(t.queryHash);n&&(t.destroy(),n===t&&l(this,Qe).delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){ue.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return l(this,Qe).get(t)}getAll(){return[...l(this,Qe).values()]}find(t){const n={exact:!0,...t};return this.getAll().find(r=>rs(n,r))}findAll(t={}){const n=this.getAll();return Object.keys(t).length>0?n.filter(r=>rs(t,r)):n}notify(t){ue.batch(()=>{this.listeners.forEach(n=>{n(t)})})}onFocus(){ue.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){ue.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},Qe=new WeakMap,qs),oo=(Ks=class{constructor(e={}){N(this,se);N(this,lt);N(this,ft);N(this,Vt);N(this,Gt);N(this,ht);N(this,Xt);N(this,Zt);_(this,se,e.queryCache||new ao),_(this,lt,e.mutationCache||new so),_(this,ft,e.defaultOptions||{}),_(this,Vt,new Map),_(this,Gt,new Map),_(this,ht,0)}mount(){On(this,ht)._++,l(this,ht)===1&&(_(this,Xt,or.subscribe(async e=>{e&&(await this.resumePausedMutations(),l(this,se).onFocus())})),_(this,Zt,Sn.subscribe(async e=>{e&&(await this.resumePausedMutations(),l(this,se).onOnline())})))}unmount(){var e,t;On(this,ht)._--,l(this,ht)===0&&((e=l(this,Xt))==null||e.call(this),_(this,Xt,void 0),(t=l(this,Zt))==null||t.call(this),_(this,Zt,void 0))}isFetching(e){return l(this,se).findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return l(this,lt).findAll({...e,status:"pending"}).length}getQueryData(e){var n;const t=this.defaultQueryOptions({queryKey:e});return(n=l(this,se).get(t.queryHash))==null?void 0:n.state.data}ensureQueryData(e){const t=this.defaultQueryOptions(e),n=l(this,se).build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(st(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return l(this,se).findAll(e).map(({queryKey:t,state:n})=>{const r=n.data;return[t,r]})}setQueryData(e,t,n){const r=this.defaultQueryOptions({queryKey:e}),s=l(this,se).get(r.queryHash),i=s==null?void 0:s.state.data,o=Ha(t,i);if(o!==void 0)return l(this,se).build(this,r).setData(o,{...n,manual:!0})}setQueriesData(e,t,n){return ue.batch(()=>l(this,se).findAll(e).map(({queryKey:r})=>[r,this.setQueryData(r,t,n)]))}getQueryState(e){var n;const t=this.defaultQueryOptions({queryKey:e});return(n=l(this,se).get(t.queryHash))==null?void 0:n.state}removeQueries(e){const t=l(this,se);ue.batch(()=>{t.findAll(e).forEach(n=>{t.remove(n)})})}resetQueries(e,t){const n=l(this,se);return ue.batch(()=>(n.findAll(e).forEach(r=>{r.reset()}),this.refetchQueries({type:"active",...e},t)))}cancelQueries(e,t={}){const n={revert:!0,...t},r=ue.batch(()=>l(this,se).findAll(e).map(s=>s.cancel(n)));return Promise.all(r).then(be).catch(be)}invalidateQueries(e,t={}){return ue.batch(()=>(l(this,se).findAll(e).forEach(n=>{n.invalidate()}),(e==null?void 0:e.refetchType)==="none"?Promise.resolve():this.refetchQueries({...e,type:(e==null?void 0:e.refetchType)??(e==null?void 0:e.type)??"active"},t)))}refetchQueries(e,t={}){const n={...t,cancelRefetch:t.cancelRefetch??!0},r=ue.batch(()=>l(this,se).findAll(e).filter(s=>!s.isDisabled()&&!s.isStatic()).map(s=>{let i=s.fetch(void 0,n);return n.throwOnError||(i=i.catch(be)),s.state.fetchStatus==="paused"?Promise.resolve():i}));return Promise.all(r).then(be)}fetchQuery(e){const t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);const n=l(this,se).build(this,t);return n.isStaleByTime(st(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(be).catch(be)}fetchInfiniteQuery(e){return e.behavior=gs(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(be).catch(be)}ensureInfiniteQueryData(e){return e.behavior=gs(e.pages),this.ensureQueryData(e)}resumePausedMutations(){return Sn.isOnline()?l(this,lt).resumePausedMutations():Promise.resolve()}getQueryCache(){return l(this,se)}getMutationCache(){return l(this,lt)}getDefaultOptions(){return l(this,ft)}setDefaultOptions(e){_(this,ft,e)}setQueryDefaults(e,t){l(this,Vt).set(Ct(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...l(this,Vt).values()],n={};return t.forEach(r=>{tn(e,r.queryKey)&&Object.assign(n,r.defaultOptions)}),n}setMutationDefaults(e,t){l(this,Gt).set(Ct(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...l(this,Gt).values()],n={};return t.forEach(r=>{tn(e,r.mutationKey)&&Object.assign(n,r.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;const t={...l(this,ft).queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=rr(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.queryFn===xn&&(t.enabled=!1),t}defaultMutationOptions(e){return e!=null&&e._defaulted?e:{...l(this,ft).mutations,...(e==null?void 0:e.mutationKey)&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){l(this,se).clear(),l(this,lt).clear()}},se=new WeakMap,lt=new WeakMap,ft=new WeakMap,Vt=new WeakMap,Gt=new WeakMap,ht=new WeakMap,Xt=new WeakMap,Zt=new WeakMap,Ks),bs=ce.createContext(void 0),fr=e=>{const t=ce.useContext(bs);if(!t)throw new Error("No QueryClient set, use QueryClientProvider to set one");return t},co=({client:e,children:t})=>(ce.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),H.jsx(bs.Provider,{value:e,children:t})),Ts=ce.createContext(!1),uo=()=>ce.useContext(Ts);Ts.Provider;function lo(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var fo=ce.createContext(lo()),ho=()=>ce.useContext(fo),po=(e,t)=>{(e.suspense||e.throwOnError||e.experimental_prefetchInRender)&&(t.isReset()||(e.retryOnMount=!1))},mo=e=>{ce.useEffect(()=>{e.clearReset()},[e])},yo=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:s})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(s&&e.data===void 0||cs(n,[e.error,r])),go=e=>{if(e.suspense){const n=s=>s==="static"?s:Math.max(s??1e3,1e3),r=e.staleTime;e.staleTime=typeof r=="function"?(...s)=>n(r(...s)):n(r),typeof e.gcTime=="number"&&(e.gcTime=Math.max(e.gcTime,1e3))}},Ao=(e,t)=>e.isLoading&&e.isFetching&&!t,Eo=(e,t)=>(e==null?void 0:e.suspense)&&t.isPending,ws=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function bo(e,t,n){var E,x,v,O,I;if(process.env.NODE_ENV!=="production"&&(typeof e!="object"||Array.isArray(e)))throw new Error('Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object');const r=uo(),s=ho(),i=fr(),o=i.defaultQueryOptions(e);(x=(E=i.getDefaultOptions().queries)==null?void 0:E._experimental_beforeQuery)==null||x.call(E,o),process.env.NODE_ENV!=="production"&&(o.queryFn||console.error(`[${o.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`)),o._optimisticResults=r?"isRestoring":"optimistic",go(o),po(o,s),mo(s);const d=!i.getQueryCache().get(o.queryHash),[h]=ce.useState(()=>new t(i,o)),f=h.getOptimisticResult(o),C=!r&&e.subscribed!==!1;if(ce.useSyncExternalStore(ce.useCallback(k=>{const B=C?h.subscribe(ue.batchCalls(k)):be;return h.updateResult(),B},[h,C]),()=>h.getCurrentResult(),()=>h.getCurrentResult()),ce.useEffect(()=>{h.setOptions(o)},[o,h]),Eo(o,f))throw ws(o,h,s);if(yo({result:f,errorResetBoundary:s,throwOnError:o.throwOnError,query:i.getQueryCache().get(o.queryHash),suspense:o.suspense}))throw f.error;if((O=(v=i.getDefaultOptions().queries)==null?void 0:v._experimental_afterQuery)==null||O.call(v,o,f),o.experimental_prefetchInRender&&!wt&&Ao(f,r)){const k=d?ws(o,h,s):(I=i.getQueryCache().get(o.queryHash))==null?void 0:I.promise;k==null||k.catch(be).finally(()=>{h.updateResult()})}return o.notifyOnChangeProps?f:h.trackResult(f)}function To(e,t){return bo(e,Ja)}function it(e,t){const n=fr(),[r]=ce.useState(()=>new io(n,e));ce.useEffect(()=>{r.setOptions(e)},[r,e]);const s=ce.useSyncExternalStore(ce.useCallback(o=>r.subscribe(ue.batchCalls(o)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),i=ce.useCallback((o,d)=>{r.mutate(o,d).catch(be)},[r]);if(s.error&&cs(r.options.throwOnError,[s.error]))throw s.error;return{...s,mutate:i,mutateAsync:s.mutate}}const nn=()=>{const e=Q(i=>i.state.swapExecutionIndex),t=Q(i=>i.state.swapExecutions[i.state.swapExecutionIndex]??{}),n=Q(i=>i.updateSwapExecutionAtIndex),r=Q(i=>i.resetSwapExecutionAtIndex),s=F.useCallback(i=>n(e,i),[n,e]);return F.useMemo(()=>({...t,update:s,resetSwap:r}),[t,s,r])},wo=2e4,Co=()=>{const{module:e}=q(),t=Q(n=>n.state.isMarketOrder);return F.useMemo(()=>e===z.TWAP?t?V.TWAP_MARKET:V.TWAP_LIMIT:e===z.LIMIT?V.LIMIT:e===z.STOP_LOSS?t?V.STOP_LOSS_MARKET:V.STOP_LOSS_LIMIT:e===z.TAKE_PROFIT?t?V.TAKE_PROFIT_MARKET:V.TAKE_PROFIT_LIMIT:V.TWAP_MARKET,[e,t])},Cs=()=>{const{account:e,config:t,chainId:n,isDev:r}=q();return F.useMemo(()=>["useTwapOrderHistoryManager",e,t==null?void 0:t.adapter,t==null?void 0:t.partner,n,r],[e,t,n,r])},xo=()=>{const{callbacks:e}=q(),t=fr(),n=Cs();return F.useCallback(r=>{var d;const s=t.getQueryData(n);let i=!1;const o=[];s&&s.filter(h=>h.version===2).forEach(h=>{var C;const f=r.find(E=>E.id===h.id);f&&f.progress!==h.progress&&(i=!0,o.push(f),f.status===pe.Completed&&((C=e==null?void 0:e.onOrderFilled)==null||C.call(e,f)))}),i&&((d=e==null?void 0:e.onOrdersProgressUpdate)==null||d.call(e,o))},[t,n,e])},hr=()=>{const{account:e,config:t,chainId:n,isDev:r}=q(),s=Cs(),i=xo();return To({refetchInterval:wo,refetchOnWindowFocus:!0,retry:!1,staleTime:1/0,queryKey:s,queryFn:async({signal:d})=>{if(!e||!n||!t)return[];const h=await la({signal:d,chainId:n,config:t,account:e,isDev:r});return i(h),h.map(f=>t!=null&&t.twapConfig?{...f,fillDelayMillis:qn(f,t.twapConfig)}:f)}})},So=(e,t,n)=>F.useMemo(()=>{if(!(!e||!t||!n||n!=null&&n.isMarketPrice))return Rr(n,e==null?void 0:e.decimals,t==null?void 0:t.decimals)},[n,e,t]),vo=(e,t,n)=>F.useMemo(()=>{if(!(!e||!t||!n))return Lr(n,e.decimals,t.decimals)},[n,e,t]),Fo=(e,t,n)=>F.useMemo(()=>{if(!(!e||!t||!n))return Kn(n.srcAmountFilled,n.dstAmountFilled,e.decimals,t.decimals)},[n,e,t]),Fn=(e,t)=>[...e.filter(r=>r.status===t)].sort((r,s)=>s.createdAt-r.createdAt),Po=()=>{const{data:e,isLoading:t,refetch:n,isRefetching:r}=hr(),s=F.useCallback(()=>n().then(i=>i.data),[n]);return F.useMemo(()=>({orders:{all:e??[],open:Fn(e??[],pe.Open),completed:Fn(e??[],pe.Completed),cancelled:Fn(e??[],pe.Cancelled),expired:Fn(e??[],pe.Expired)},isLoading:t,isRefetching:r,refetchOrders:s}),[e,t,r,s])},pr=()=>{const e=Q(n=>n.state.currentTime),t=Jn().duration;return F.useMemo(()=>Si(e,t),[e,t])},xs=()=>{const{srcToken:e,dstToken:t,account:n,chainId:r,slippage:s,config:i,module:o,fees:d}=q(),{amount:h}=rt(),{amountPerTrade:f,totalTrades:C}=qe(),E=pr(),{amount:x}=tr(),{pricePerChunk:v}=bt(),{milliseconds:O}=Lt();return F.useMemo(()=>{var I;return Kr({chainId:r,srcToken:Ut((e==null?void 0:e.address)||"")?((I=At(r))==null?void 0:I.wToken.address)||"":(e==null?void 0:e.address)||"",dstToken:(t==null?void 0:t.address)||"",srcAmount:h,deadlineMillis:E,fillDelayMillis:!C||C===1?0:O,slippage:s*100,account:n,srcAmountPerTrade:f,dstMinAmountPerTrade:x,triggerAmountPerTrade:v,config:i,module:o})},[e,t,n,r,s,i,o,h,f,C,O,x,v,d])};function Do(e){const t=e.slice(2);if(t.length===128){const i=`0x${t.slice(0,64)}`,o=parseInt(t.charAt(64),16),d=(o>>3)+27,h=`0x${(o&7).toString(16)}${t.slice(65,128)}`;return{r:i,s:h,v:d}}const n=`0x${t.slice(0,64)}`,r=`0x${t.slice(64,128)}`,s=parseInt(t.slice(128,130),16);return{r:n,s:r,v:s}}const Oo=()=>{var i;const{account:e,walletInteractions:t,callbacks:n,chainId:r}=q(),s=(i=En())==null?void 0:i.wToken;return it({mutationFn:async({onHash:o,srcAmountWei:d})=>{var f,C;if(!e)throw new Error("missing account");if(!t)throw new Error("missing walletInteractions");if(!s)throw new Error("tokenAddress is not defined");fe.onWrapRequest();const h=await t.wrapNativeToken(d);return(f=n==null?void 0:n.onWrapRequest)==null||f.call(n),o==null||o(h),fe.onWrapSuccess(h),(C=n==null?void 0:n.onWrapSuccess)==null||C.call(n,{txHash:h,explorerUrl:Rt(h,r),amount:Ee(d,s.decimals)}),h},onError:o=>{throw fe.onWrapError(o),o}})},Ss=()=>{const{account:e,walletInteractions:t,chainId:n,callbacks:r,isDev:s}=q(),i=xs(),{refetch:o}=hr();return it({mutationFn:async()=>{var I,k,B,P;if(!e)throw new Error("missing account");if(!t)throw new Error("missing walletInteractions");if(!n)throw new Error("missing chainId");const{order:d,domain:h,types:f,primaryType:C}=i;fe.onSignOrderRequest(d);let E;try{E=await t.signOrder({domain:h,types:f,primaryType:C,message:d,account:e})}catch(K){throw(I=r==null?void 0:r.onSignOrderError)==null||I.call(r,K),fe.onSignOrderError(K),K}fe.onSignOrderSuccess(E),(k=r==null?void 0:r.onSignOrderSuccess)==null||k.call(r,E);const x=Do(E),v={v:`0x${x.v.toString(16)}`,r:x.r,s:x.s};(B=r==null?void 0:r.onSignOrderRequest)==null||B.call(r);const O=await Qr(d,v,s);return(P=r==null?void 0:r.onOrderCreated)==null||P.call(r,O),await o(),O}})},vs=()=>{const{account:e,walletInteractions:t,config:n}=q();return it({mutationFn:async({tokenAddress:r,srcAmountWei:s})=>{if(!t)throw new Error("missing walletInteractions");if(!e)throw new Error("missing account");if(!n)throw new Error("missing config");const i=await t.getAllowance({tokenAddress:r,spenderAddress:n.repermit}),o=S(i||"0").lt(S(s).toString());return{allowance:i,approvalRequired:o}}})},Io=()=>{const{account:e,walletInteractions:t,config:n,chainId:r,callbacks:s}=q(),{mutateAsync:i}=vs();return it({onError:o=>{fe.onApproveError(o)},mutationFn:async({token:o,onHash:d,srcAmountWei:h})=>{var E,x;if(!e)throw new Error("missing account");if(!t)throw new Error("missing walletInteractions");if(!n)throw new Error("missing config");fe.onApproveRequest();const f=await t.approveToken({tokenAddress:o.address,amount:h,spenderAddress:n.repermit});if(!f)throw new Error("failed to approve token");(E=s==null?void 0:s.onApproveRequest)==null||E.call(s),d(f);let C=!1;for(let v=0;v<3;v++){const{approvalRequired:O}=await i({tokenAddress:o.address,srcAmountWei:h});if(!O){C=!0;break}v<2&&await new Promise(I=>setTimeout(I,3e3))}if(!C)throw new Error(`Insufficient ${o.symbol} allowance to perform the swap. Please approve the token first.`);return fe.onApproveSuccess(f),(x=s==null?void 0:s.onApproveSuccess)==null||x.call(s,{txHash:f,explorerUrl:Rt(f,r),token:o,amount:Ee(h,o.decimals)}),f}})},Mo=()=>{const{account:e,chainId:t,srcToken:n,dstToken:r,module:s,slippage:i}=q(),o=bt(),d=rt().amount,h=qe().amountPerTrade,f=pr(),C=qe().totalTrades,E=Lt().fillDelay,x=tr().amount,v=Q(O=>O.state.isMarketOrder);return it({mutationFn:async()=>{fe.onRequestOrder({account:e,chainId:t,module:s,srcToken:n,dstToken:r,fromTokenAmount:d,srcChunkAmount:h,triggerPricePerTrade:o.pricePerChunk,deadline:f,fillDelay:E.unit*E.value,minDstAmountOutPerTrade:x,slippage:i,isMarketOrder:v||!1,chunksAmount:C})}})};function ko(e){const t=e.message,n=t.match(/,\s*code\s*:\s*(\d+)/i);return{message:t.replace(/^error\s*:/i,"").replace(/,\s*code\s*:\s*\d+/i,"").trim()||"",code:n?Number(n[1]):0}}const Fs=()=>{const{srcToken:e,dstToken:t,chainId:n,callbacks:r,marketPrice:s}=q(),i=Io().mutateAsync,o=Oo().mutateAsync,d=Ss().mutateAsync,{mutateAsync:h}=vs(),{update:f}=nn(),{amount:C}=rt(),E=Mo().mutate;return it({mutationFn:async()=>{var v,O;const x=Ut((e==null?void 0:e.address)||" ");try{if(!e)throw new Error("missing srcToken");if(!t)throw new Error("missing dstToken");if(!n)throw new Error("missing chainId");const I=Zr(e,n);f({allowanceLoading:!0,wrapTxHash:void 0,approveTxHash:void 0,acceptedMarketPrice:s,acceptedSrcAmount:C,srcToken:e,dstToken:t,pendingSteps:[]});const{approvalRequired:k}=await h({tokenAddress:I.address,srcAmountWei:C});let B=0,P=1;x&&P++,k&&P++,f({totalSteps:P,stepIndex:B,allowanceLoading:!1,hasApproval:!k,status:Se.LOADING}),E();let K=[];x&&K.push(tt.WRAP),k&&K.push(tt.APPROVE),K.push(tt.CREATE),f({pendingSteps:K}),x&&(f({step:tt.WRAP}),await o({onHash:Z=>f({wrapTxHash:Z}),srcAmountWei:C}),B++,f({stepIndex:B})),k&&(f({step:tt.APPROVE}),await i({token:I,onHash:Z=>f({approveTxHash:Z}),srcAmountWei:C}),B++,f({stepIndex:B})),f({step:tt.CREATE});const U=await d();return f({status:Se.SUCCESS,orderId:U.id}),U}catch(I){if(Vn(I))(v=r==null?void 0:r.onSubmitOrderRejected)==null||v.call(r),f({step:void 0,status:void 0,stepIndex:void 0,error:I});else{const k=ko(I);(O=r==null?void 0:r.onSubmitOrderFailed)==null||O.call(r,k),f({status:Se.FAILED,parsedError:k,error:I})}throw I}}})},_o=()=>{const e=nn(),{srcToken:t,dstToken:n}=q(),r=Fs(),s=Q(f=>f.resetState),i=F.useCallback(()=>r.mutateAsync(),[r]),{update:o,resetSwap:d,...h}=e;return F.useMemo(()=>({status:h.status,parsedError:h.parsedError,error:h.error,step:h.step,stepIndex:h.stepIndex,approveTxHash:h.approveTxHash,wrapTxHash:h.wrapTxHash,totalSteps:h.totalSteps,pendingSteps:h.pendingSteps,srcToken:t,dstToken:n,onSubmit:i,resetState:s,resetCurrentSwap:d,isLoading:(e==null?void 0:e.status)===Se.LOADING,isSuccess:(e==null?void 0:e.status)===Se.SUCCESS,isFailed:(e==null?void 0:e.status)===Se.FAILED,confirmButtonLoading:h.allowanceLoading}),[i,h,s,d,t,n])},Bo=()=>{const{marketPrice:e,srcToken:t,dstToken:n,marketPriceLoading:r,srcBalance:s,srcUsd1Token:i,noLiquidity:o,typedInputAmount:d}=q(),h=r||S(i||"0").isZero()||s===void 0||S(e||"0").isZero(),f=!!(t&&n&&d&&h),E=!!(ts()||o||f||S(d||"0").isZero()||!t||!n);return F.useMemo(()=>({disabled:E,loading:f}),[E,f])},Uo=()=>{const{srcUsd1Token:e,dstUsd1Token:t}=q(),n=rt().amountUI,r=wn().amountUI,s=nt(n,e),i=nt(r,t);return{srcAmountUsd:s,dstAmountUsd:i}},Ro=()=>{const{fees:e,dstToken:t,dstUsd1Token:n}=q(),{amountUI:r}=wn(),s=F.useMemo(()=>!e||!r?"":S(r).multipliedBy(e).dividedBy(100).toFixed(),[r,e]),i=Yn((t==null?void 0:t.decimals)||0,s);return{amountUI:s,amount:i,percent:e,usd:nt(s,n)}},Lo=e=>{const t=F.useMemo(()=>!e.minDestAmountPerTrade||!e.totalTrades?"":S(e.minDestAmountPerTrade).multipliedBy(e.totalTrades).decimalPlaces(0).toFixed(),[e.minDestAmountPerTrade,e.totalTrades]),n=F.useMemo(()=>!e.minDestAmountPerTradeUI||!e.totalTrades?"":S(e.minDestAmountPerTradeUI).multipliedBy(e.totalTrades).toFixed(),[e.minDestAmountPerTradeUI,e.totalTrades]),r=F.useMemo(()=>!e.minDestAmountPerTradeUsd||!e.totalTrades?"":S(e.minDestAmountPerTradeUsd).multipliedBy(e.totalTrades).decimalPlaces(2).toFixed(),[e.minDestAmountPerTradeUsd,e.totalTrades]);return F.useMemo(()=>({srcToken:e.srcToken,dstToken:e.dstToken,orderType:e.orderType,createdAt:e.createdAt||0,deadline:e.deadline||0,totalTrades:e.totalTrades||0,tradeInterval:e.tradeInterval||0,recipient:e.account||"",srcAmount:e.srcAmount||"",srcAmountUI:e.srcAmountUI||"",srcAmountUsd:e.srcAmountUsd||"",dstAmount:e.dstAmount||"",dstAmountUI:e.dstAmountUI||"",dstAmountUsd:e.dstAmountUsd||"",limitPrice:e.limitPrice||"",limitPriceUI:e.limitPriceUI||"",limitPriceUsd:e.limitPriceUsd||"",sizePerTrade:e.srcAmountPerTrade||"",sizePerTradeUI:e.srcAmountPerTradeUI||"",sizePerTradeUsd:e.srcAmountPerTradeUsd,minDestAmountPerTrade:e.minDestAmountPerTrade||"",minDestAmountPerTradeUI:e.minDestAmountPerTradeUI||"",minDestAmountPerTradeUsd:e.minDestAmountPerTradeUsd,dstMinAmount:t,dstMinAmountUI:n,dstMinAmountUsd:r,triggerPrice:e.triggerPrice||"",triggerPriceUI:e.triggerPriceUI||"",triggerPriceUsd:e.triggerPriceUsd}),[e.srcToken,e.dstToken,e.orderType,e.createdAt,e.deadline,e.totalTrades,e.tradeInterval,e.account,e.srcAmount,e.srcAmountUI,e.srcAmountUsd,e.dstAmount,e.dstAmountUI,e.dstAmountUsd,e.limitPrice,e.limitPriceUI,e.limitPriceUsd,e.srcAmountPerTrade,e.srcAmountPerTradeUI,e.srcAmountPerTradeUsd,e.minDestAmountPerTrade,e.minDestAmountPerTradeUI,e.minDestAmountPerTradeUsd,t,n,r,e.triggerPrice,e.triggerPriceUI,e.triggerPriceUsd])},No=()=>{const{config:e}=q();return F.useMemo(()=>({spender:e.repermit}),[e])},qo=()=>{const{srcToken:e,dstToken:t,account:n,marketPrice:r}=q(),{spender:s}=No(),{amount:i}=rt(),{amount:o,amountUI:d,usd:h}=Tn(),{amountPerTrade:f,amountPerTradeUI:C,amountPerTradeUsd:E,totalTrades:x}=qe(),v=pr(),{amount:O,amountUI:I,usd:k}=tr(),{amountUI:B,amount:P,usd:K}=bt(),{milliseconds:U}=Lt(),{amount:Z,amountUI:Y}=wn(),{srcAmountUsd:oe,dstAmountUsd:a}=Uo(),{amount:c,amountUI:u,percent:A,usd:m}=Ro(),y=xs(),w=Q(G=>G.state.isMarketOrder),p=Q(G=>G.state.currentTime),g=nn(),T=Co(),b=g.acceptedSrcAmount||i,D=Ee(r,(t==null?void 0:t.decimals)||0),R=F.useMemo(()=>T===V.TAKE_PROFIT_MARKET||T===V.TAKE_PROFIT_LIMIT||T===V.STOP_LOSS_LIMIT||T===V.STOP_LOSS_MARKET,[T]),L=Lo({srcToken:e,dstToken:t,account:n,orderType:T,createdAt:p,deadline:v,totalTrades:x,tradeInterval:U,srcAmount:b,srcAmountUI:Ee(b,(e==null?void 0:e.decimals)||0),srcAmountUsd:oe,dstAmount:Z,dstAmountUI:Y,dstAmountUsd:a,limitPrice:w?void 0:o,limitPriceUI:w?void 0:d,limitPriceUsd:w?void 0:h,srcAmountPerTrade:f,srcAmountPerTradeUI:C,srcAmountPerTradeUsd:E,minDestAmountPerTrade:O,minDestAmountPerTradeUI:I,minDestAmountPerTradeUsd:k,triggerPrice:P,triggerPriceUI:B,triggerPriceUsd:K});return F.useMemo(()=>({...L,feesAmountUI:u,feesAmount:c,feesUsd:m||"",feesPercentage:A,rePermitData:y,isTriggerPrice:R,isMarketOrder:w,marketPrice:r,marketPriceUi:D,spender:s}),[L,u,c,m,A,y,R,w,r,D,s])},Ko=()=>{const{supportedChains:e}=q();return F.useMemo(()=>e,[e])},Ho=60,Ps=()=>{const{refetch:e}=hr();return it({mutationFn:async t=>{var n;for(let r=0;r<Ho;r++){const s=(n=await e())==null?void 0:n.data;if(!s)throw new Error("orders not found");const i=s.find(o=>o.id===t);if((i==null?void 0:i.status)===pe.Cancelled)return;await new Promise(o=>setTimeout(o,1e3))}throw new Error("Timed out waiting for order cancellation to be confirmed")}})},Wo=()=>{const e=Q(n=>n.updateState),t=Q(n=>n.state.cancelOrders);return{cancelOrders:t,setCancelOrder:(n,r)=>{e({cancelOrders:{...t,[n]:r}})},clearCancelOrder:n=>{const{[n]:r,...s}=t;e({cancelOrders:s})}}},Qo=e=>{const{account:t,walletInteractions:n,config:r,callbacks:s,chainId:i}=q(),o=Ps().mutateAsync,{cancelOrders:d,setCancelOrder:h,clearCancelOrder:f}=Wo(),{mutateAsync:C}=it({mutationFn:async()=>{var O,I,k;if(!t||!n||!r)throw new Error("missing required parameters");if(!e)throw new Error("order is required");const v=e.id;try{(O=s==null?void 0:s.onCancelOrderRequest)==null||O.call(s,e),h(v,{status:Se.LOADING}),fe.onCancelOrderRequest([e.version===1?e.id.toString():e.hash],e.version);const B=await n.cancelOrder({order:e,contractAddress:e.version===1?e.twapAddress:r.repermit,args:e.version===1?[e.id]:[[e.repermitDigest]],abi:e.version===1?js:$s});if(!B)throw new Error("failed to cancel order");return fe.onCancelOrderSuccess(B),await o(e.id),(I=s==null?void 0:s.onCancelOrderSuccess)==null||I.call(s,{order:e,txHash:B,explorerUrl:Rt(B,i)}),h(v,{status:Se.SUCCESS,txHash:B}),B}catch(B){console.error("cancel order error",B),(k=s==null?void 0:s.onCancelOrderFailed)==null||k.call(s,B),Vn(B)?f(v):(h(v,{status:Se.FAILED,error:B.message}),fe.onCancelOrderError(B))}}}),E=F.useMemo(()=>{const v=d[(e==null?void 0:e.id)||""];return{isLoading:(v==null?void 0:v.status)===Se.LOADING,isSuccess:(v==null?void 0:v.status)===Se.SUCCESS,isError:(v==null?void 0:v.status)===Se.FAILED,error:v==null?void 0:v.error,txHash:v==null?void 0:v.txHash}},[d,e==null?void 0:e.id]),x=F.useCallback(async()=>C(),[C]);return F.useMemo(()=>({cancelOrder:x,...E}),[x,E])},Ds=F.createContext(null),$o=({children:e})=>{const t=xa(),n=Pa(),r=va(),s=_a(),i=Ba(),o=bn(),d=Ua(),h=Ra(),f=ts(),C=Bo(),E=qo(),x=Po(),v=_o(),O=Ko(),I=Ps(),{module:k}=q(),B={tradesAmountPanel:t,durationPanel:n,fillDelayPanel:r,limitPricePanel:s,triggerPricePanel:i,pricePanel:o,dstTokenPanel:d,disclaimerPanel:h,inputError:f,submitOrderButton:C,derivedFormData:E,orderHistoryPanel:x,orderExecutionPanel:v,supportedChains:O,refetchUntilStatusSynced:I,module:k};return H.jsx(Ds.Provider,{value:B,children:e})},jo=()=>{const e=F.useContext(Ds);if(e===null)throw new Error("useSpot must be used within SpotProvider");return e},zo=F.createContext(null),mr={didCatch:!1,error:null};class Vo extends F.Component{constructor(t){super(t),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=mr}static getDerivedStateFromError(t){return{didCatch:!0,error:t}}resetErrorBoundary(){const{error:t}=this.state;if(t!==null){for(var n,r,s=arguments.length,i=new Array(s),o=0;o<s;o++)i[o]=arguments[o];(n=(r=this.props).onReset)===null||n===void 0||n.call(r,{args:i,reason:"imperative-api"}),this.setState(mr)}}componentDidCatch(t,n){var r,s;(r=(s=this.props).onError)===null||r===void 0||r.call(s,t,n)}componentDidUpdate(t,n){const{didCatch:r}=this.state,{resetKeys:s}=this.props;if(r&&n.error!==null&&Go(t.resetKeys,s)){var i,o;(i=(o=this.props).onReset)===null||i===void 0||i.call(o,{next:s,prev:t.resetKeys,reason:"keys"}),this.setState(mr)}}render(){const{children:t,fallbackRender:n,FallbackComponent:r,fallback:s}=this.props,{didCatch:i,error:o}=this.state;let d=t;if(i){const h={error:o,resetErrorBoundary:this.resetErrorBoundary};if(typeof n=="function")d=n(h);else if(r)d=F.createElement(r,h);else if(s!==void 0)d=s;else throw o}return F.createElement(zo.Provider,{value:{didCatch:i,error:o,resetErrorBoundary:this.resetErrorBoundary}},d)}}function Go(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[];return e.length!==t.length||e.some((n,r)=>!Object.is(n,t[r]))}const Xo=()=>H.jsx("div",{className:"twap-error-fallback",children:H.jsx("p",{style:{fontSize:20,fontWeight:600,textAlign:"center",width:"100%",marginTop:40},children:"Something went wrong"})});function Zo({children:e}){return H.jsx(Vo,{FallbackComponent:Xo,onError:t=>fe.onCrash(t),children:H.jsx(H.Fragment,{children:e})})}const Os=F.createContext(null),Yo=new oo({defaultOptions:{queries:{refetchOnWindowFocus:!1}}}),Jo=e=>{var r,s,i;const t=Q(o=>o.updateState),n=Q(o=>o.state.isMarketOrder);return F.useEffect(()=>{const o=setInterval(()=>{t({currentTime:Date.now()})},6e4);return()=>clearInterval(o)},[t]),F.useEffect(()=>{var d,h,f,C,E,x,v,O,I,k,B,P,K,U,Z,Y;const o=(h=(d=e.overrides)==null?void 0:d.state)==null?void 0:h.isMarketOrder;o!==void 0&&t({isMarketOrder:o}),t({typedChunks:(C=(f=e.overrides)==null?void 0:f.state)==null?void 0:C.chunks,typedFillDelay:(x=(E=e.overrides)==null?void 0:E.state)==null?void 0:x.fillDelay,typedDuration:(O=(v=e.overrides)==null?void 0:v.state)==null?void 0:O.duration,typedLimitPrice:(k=(I=e.overrides)==null?void 0:I.state)==null?void 0:k.limitPrice,typedTriggerPrice:(P=(B=e.overrides)==null?void 0:B.state)==null?void 0:P.triggerPrice,triggerPricePercent:(U=(K=e.overrides)==null?void 0:K.state)==null?void 0:U.triggerPricePercent,limitPricePercent:(Y=(Z=e.overrides)==null?void 0:Z.state)==null?void 0:Y.limitPricePercent})},[(r=e.overrides)==null?void 0:r.state,e.module]),F.useEffect(()=>{var o,d,h,f;t({typedLimitPrice:(d=(o=e.overrides)==null?void 0:o.state)==null?void 0:d.limitPrice,typedTriggerPrice:(f=(h=e.overrides)==null?void 0:h.state)==null?void 0:f.triggerPrice,triggerPricePercent:void 0,limitPricePercent:void 0})},[(s=e.srcToken)==null?void 0:s.address,(i=e.dstToken)==null?void 0:i.address]),F.useEffect(()=>{e.module===z.LIMIT&&t({isMarketOrder:!1})},[e.module]),F.useEffect(()=>{n&&t({isInvertedTrade:!1})},[n]),F.useEffect(()=>{t({typedChunks:void 0})},[e.typedInputAmount]),null},ec=({marketReferencePrice:e,srcToken:t,dstToken:n,chainId:r,typedInputAmount:s})=>F.useMemo(()=>{if(Xn(t,n,r)||Zn(t,n,r))return{isLoading:!1,noLiquidity:!1,value:Et(s||"0",t==null?void 0:t.decimals)};if(S(e.value||0).isZero()||S(s||0).isZero())return e;const i=S(e.value||0).dividedBy(s||0).decimalPlaces(0).toFixed();return{...e,value:i}},[e,s,t,n,r]),tc=e=>{const t=nn(),n=F.useMemo(()=>Ur(e.partner),[e.partner]),r=F.useMemo(()=>{const d=n[0];return e.chainId&&n.includes(e.chainId)?e.chainId:d},[e.chainId,n]),s=F.useMemo(()=>Hn(e.partner,r),[e.partner,r]),i=ec(e),o=F.useMemo(()=>qr(e.minChunkSizeUsd),[e.minChunkSizeUsd]);return F.useEffect(()=>{fe.init(s,o,r)},[s,r,o]),H.jsxs(Os.Provider,{value:{typedInputAmount:e.typedInputAmount,minChunkSizeUsd:o,account:e.account,walletInteractions:e.walletInteractions,marketPrice:t.acceptedMarketPrice||i.value,marketPriceLoading:!t.acceptedMarketPrice&&i.isLoading,noLiquidity:!t.acceptedMarketPrice&&i.noLiquidity,config:s,slippage:e.priceProtection,supportedChains:n,chainId:r,partner:e.partner,module:e.module,fees:e.fees||0,overrides:e.overrides,callbacks:e.callbacks,srcUsd1Token:e.srcUsd1Token,dstUsd1Token:e.dstUsd1Token,srcBalance:e.srcBalance,dstBalance:e.dstBalance,srcToken:t.srcToken||e.srcToken,dstToken:t.dstToken||e.dstToken,isDev:e.isDev},children:[H.jsx(Jo,{...e}),H.jsx($o,{children:H.jsx(Zo,{children:e.children})})]})},nc=e=>H.jsx(co,{client:Yo,children:H.jsx(tc,{...e})}),q=()=>{const e=F.useContext(Os);if(e===null)throw new Error("useSpotContext must be used within SpotProvider");return e},rc=(e,t,n)=>{const r=En();return F.useMemo(()=>e==null?void 0:e.map(s=>({srcToken:t,dstToken:n,srcAmount:Ee(s.inAmount,t==null?void 0:t.decimals),dstAmount:Ee(s.outAmount,n==null?void 0:n.decimals),timestamp:s.timestamp,txHash:s.txHash,explorerUrl:Rt(s.txHash,r==null?void 0:r.id),executionRate:Kn(s.inAmount,s.outAmount,t==null?void 0:t.decimals,n==null?void 0:n.decimals)})).filter(s=>s.srcToken!==void 0&&s.dstToken!==void 0),[e,t,n,r])},sc=(e,t,n)=>{const{config:r}=q(),s=So(t,n,e),i=vo(t,n,e),o=Fo(t,n,e),d=F.useMemo(()=>e?e.version===2?e.fillDelay:r.twapConfig?qn(e,r.twapConfig):0:0,[e,r]),h=rc(e==null?void 0:e.fills,t,n)??[];return F.useMemo(()=>{if(e!=null&&e.id)return{original:e,fills:h,srcToken:t,dstToken:n,orderType:e.type,createdAt:e.createdAt,deadline:e.deadline||0,totalTrades:e.totalTradesAmount||0,tradeInterval:d,recipient:e.maker||"",srcAmount:e.srcAmount||"",srcAmountUI:Ee(e.srcAmount,t==null?void 0:t.decimals),limitPrice:Et(s,n==null?void 0:n.decimals),limitPriceUI:s||"",sizePerTrade:e.srcAmountPerTrade||"",sizePerTradeUI:Ee(e.srcAmountPerTrade,t==null?void 0:t.decimals),minDestAmountPerTrade:e.dstMinAmountPerTrade||"",minDestAmountPerTradeUI:Ee(e.dstMinAmountPerTrade,n==null?void 0:n.decimals),dstMinAmount:e.dstMinAmountTotal,dstMinAmountUI:Ee(e.dstMinAmountTotal,n==null?void 0:n.decimals),triggerPrice:Et(i,n==null?void 0:n.decimals),triggerPriceUI:i||"",id:e.id,amountInFilled:e.srcAmountFilled,amountInFilledUI:Ee(e.srcAmountFilled,t==null?void 0:t.decimals),amountOutFilled:e.dstAmountFilled,amountOutFilledUI:Ee(e.dstAmountFilled,n==null?void 0:n.decimals),progress:e.progress,executionPrice:Et(o,n==null?void 0:n.decimals),executionPriceUI:o,version:e.version}},[e,h,t,n,d,s,i,o])};Hi(fa.version),M.DISCLAIMER_URL=oi,M.Disclaimer=Jt,M.InputErrors=me,M.Module=z,M.ORBS_LOGO=ii,M.ORBS_SLTP_FAQ_URL=si,M.ORBS_TWAP_FAQ_URL=ri,M.ORBS_WEBSITE_URL=ai,M.OrderFilter=Fr,M.OrderStatus=pe,M.OrderType=V,M.Partners=Be,M.SPOT_VERSION=fn,M.SpotProvider=nc,M.Steps=tt,M.SwapStatus=Se,M.TimeUnit=Pe,M.buildRePermitOrderData=Kr,M.ensureWrappedToken=Zr,M.eqIgnoreCase=yt,M.getConfig=Hn,M.getExplorerUrl=Rt,M.getMinChunkSizeUsd=qr,M.getNetwork=At,M.getOrderExecutionRate=Kn,M.getOrderFillDelayMillis=qn,M.getOrderLimitPriceRate=Rr,M.getOrderType=Aa,M.getPartnerChains=Ur,M.getPartners=Nr,M.getTriggerPriceRate=Lr,M.isNativeAddress=Ut,M.isTxRejected=Vn,M.millisToDays=Gn,M.millisToMinutes=An,M.networks=ye,M.parseError=ga,M.shouldUnwrapOnly=Zn,M.shouldWrapOnly=Xn,M.submitOrder=Qr,M.toAmountUi=Ee,M.toAmountWei=Et,M.useAmountUi=en,M.useCancelOrder=Qo,M.useDerivedHistoryOrder=sc,M.useExplorerLink=Ea,M.useNetwork=En,M.useSignOrder=Ss,M.useSpot=jo,M.useSubmitOrder=Fs,M.useSwapExecution=nn,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})}));
|
|
64
|
+
`,extractResults:E=>{var x;return(((x=E.data)==null?void 0:x.orderFilleds)||[]).map(v=>({...v,timestamp:new Date(v.timestamp).getTime()}))}})};class oa extends Error{constructor(){super("No graph endpoint found"),this.name="NoGraphEndpointError"}}const ca=async({chainId:e,signal:t,page:n,limit:r,filters:s})=>{try{const i=await sa({chainId:e,signal:t,page:n,limit:r,filters:s}),[o,d]=await Promise.all([aa({chainId:e,orders:i,signal:t}),ia({chainId:e,orders:i,signal:t})]),h=i.map(C=>{const E=o==null?void 0:o.filter(x=>x.TWAP_id===Number(C.Contract_id)&&yt(x.exchange,C.exchange)&&yt(x.twapAddress,C.twapAddress));return na(C,e,E,ua(C,E||[],d))}).sort((C,E)=>E.createdAt-C.createdAt),f=new Set;return h.filter(C=>f.has(C.id)?!1:(f.add(C.id),!0))}catch{return[]}},ua=(e,t,n)=>{var d;const r=(d=n==null?void 0:n.find(h=>h.twapId===e.Contract_id.toString()&&yt(h.twapAddress,e.twapAddress)))==null?void 0:d.status,i=$r(t).reduce((h,f)=>h.plus(f.inAmount),new S(0)).toFixed(),o=zr(e.ask_srcAmount,i);return da(o,e.ask_deadline*1e3,r)},zr=(e,t)=>{if(!t||!e)return 0;const n=S(t).dividedBy(e).toNumber();return n>=.99?100:n<=0?0:Number((n*100).toFixed(2))},da=(e,t,n)=>e===100?pe.Completed:n==="CANCELLED"?pe.Cancelled:n==="COMPLETED"?pe.Completed:t>Date.now()?pe.Open:pe.Expired,la=async({signal:e,page:t,chainId:n,limit:r,config:s,account:i,isDev:o=!1})=>(await Promise.all([s?ca({chainId:n,signal:e,page:t,limit:r,filters:{accounts:[i],configs:s.twapConfig?[s.twapConfig]:[]}}):Promise.resolve([]),ea({chainId:n,signal:e,account:i,exchange:s==null?void 0:s.adapter,partner:s==null?void 0:s.partner,isDev:o})]).then(([f,C])=>[...f,...C])).sort((f,C)=>C.createdAt-f.createdAt),fa={version:"1.1.29"},Vr=e=>{let t;const n=new Set,r=(f,C)=>{const E=typeof f=="function"?f(t):f;if(!Object.is(E,t)){const x=t;t=C??(typeof E!="object"||E===null)?E:Object.assign({},t,E),n.forEach(v=>v(t,x))}},s=()=>t,d={setState:r,getState:s,getInitialState:()=>h,subscribe:f=>(n.add(f),()=>n.delete(f))},h=t=e(r,s,d);return d},ha=(e=>e?Vr(e):Vr),pa=e=>e;function ma(e,t=pa){const n=F.useSyncExternalStore(e.subscribe,F.useCallback(()=>t(e.getState()),[e,t]),F.useCallback(()=>t(e.getInitialState()),[e,t]));return F.useDebugValue(n),n}const Gr=e=>{const t=ha(e),n=r=>ma(t,r);return Object.assign(n,t),n},ya=(e=>e?Gr(e):Gr),gn={},Xr={currentTime:Date.now(),cancelOrders:{},swapExecutions:[gn],swapExecutionIndex:0},Q=ya((e,t)=>({state:Xr,updateState:n=>e(r=>({state:{...r.state,...n}})),updateSwapExecutionAtIndex:(n,r)=>e(s=>{const i=[...s.state.swapExecutions];return i[n]={...i[n]??gn,...r},{state:{...s.state,swapExecutions:i}}}),resetSwapExecutionAtIndex:()=>e(n=>{const r=[...n.state.swapExecutions];return r[n.state.swapExecutionIndex]=gn,{state:{...n.state,swapExecutions:r}}}),resetState:()=>{const n=t().state;e({state:{...Xr,currentTime:Date.now(),isMarketOrder:n.isMarketOrder,swapExecutions:[...n.swapExecutions,gn],swapExecutionIndex:n.swapExecutionIndex+1}})}}));var Se=(e=>(e[e.LOADING=1]="LOADING",e[e.SUCCESS=2]="SUCCESS",e[e.FAILED=3]="FAILED",e))(Se||{}),Jt=(e=>(e.TRIGGER_MARKET_PRICE="triggerMarketPriceDisclaimer",e.MARKET_PRICE="marketOrderDisclaimer",e.LIMIT_PRICE="limitOrderDisclaimer",e))(Jt||{}),tt=(e=>(e.WRAP="wrap",e.APPROVE="approve",e.CREATE="create",e))(tt||{});const Et=(e,t)=>!t||!e||S(e).isNaN()?"":S(e).multipliedBy(S(10).pow(t)).toFixed(0),Ee=(e,t)=>{try{return!t||!e||S(e).isNaN()?"":S(e).dividedBy(S(10).pow(t)).toFixed()}catch(n){return console.error(n),""}},ga=e=>{const t="An error occurred.";if(!e||!e.message)return t;try{return e.message.toLowerCase().includes("rejected")?"Transaction Rejected":t}catch{return t}},Vn=e=>{var t,n,r,s;if(e!=null&&e.message)return((n=(t=e.message)==null?void 0:t.toLowerCase())==null?void 0:n.includes("rejected"))||((s=(r=e.message)==null?void 0:r.toLowerCase())==null?void 0:s.includes("denied"))},Zr=(e,t)=>{const n=At(t);return n&&Ut(e.address)?n.wToken:e};function Gn(e){return e?e/864e5:0}function An(e){return e?e/6e4:0}const Aa=(e,t)=>e?V.TWAP_MARKET:t===1?V.LIMIT:V.TWAP_LIMIT,Xn=(e,t,n)=>{const r=At(n);return Ut((e==null?void 0:e.address)||"")&&yt((t==null?void 0:t.address)||"",(r==null?void 0:r.wToken.address)||"")},Zn=(e,t,n)=>{const r=At(n);return yt((e==null?void 0:e.address)||"",(r==null?void 0:r.wToken.address)||"")&&Ut((t==null?void 0:t.address)||"")},Rt=(e,t)=>{if(!t)return"";const n=At(t);return`${n==null?void 0:n.explorer}/tx/${e}`},Yn=(e,t)=>F.useMemo(()=>Et(t,e),[e,t]),en=(e,t)=>F.useMemo(()=>Ee(t,e),[e,t]),En=()=>{const{chainId:e}=q();return F.useMemo(()=>At(e),[e])},Ea=e=>{const t=En();return F.useMemo(()=>{if(!(!e||!t))return Rt(e,t.id)},[e,t])},nt=(e,t)=>F.useMemo(()=>!e||!t||S(e||"0").isZero()||S(t||"0").isZero()?"":S(e||"0").times(t).toFixed(),[e,t]),ba=()=>{const{srcToken:e,dstToken:t,chainId:n}=q();return F.useMemo(()=>Xn(e,t,n),[e,t,n])},Ta=()=>{const{srcToken:e,dstToken:t,chainId:n}=q();return F.useMemo(()=>Zn(e,t,n),[e,t,n])},wa=()=>{const e=ba(),t=Ta();return e||t},rt=()=>{const{srcToken:e,typedInputAmount:t}=q();return{amount:Yn(e==null?void 0:e.decimals,t),amountUI:t,error:S(t||0).isZero()?"enterAmount":void 0}},Ca=(e,t)=>{const{module:n,srcUsd1Token:r,marketPrice:s,minChunkSizeUsd:i,typedInputAmount:o}=q();return F.useMemo(()=>{if(S(o||"0").isZero()||!s||S(r||"0").isZero())return;if(!e)return{type:me.MIN_CHUNKS,value:1,args:{minChunks:"1"}};const{isError:d}=Ri(e,t,n);if(d)return{type:me.MAX_CHUNKS,value:t,args:{maxChunks:`${t}`}};const{isError:h,value:f}=Ui(o||"",r||"",i||0);if(h)return{type:me.MIN_TRADE_SIZE,value:f,args:{minTradeSize:`${f}`}}},[e,t,n,o,r,i,s])},qe=()=>{const{srcToken:e,srcUsd1Token:t,module:n,minChunkSizeUsd:r}=q(),s=Q(O=>O.state.typedChunks),i=Q(O=>O.updateState),{amount:o,amountUI:d}=rt(),h=F.useMemo(()=>xi(d||"",t||"",r||0),[d,t,r]),f=F.useMemo(()=>Ci(h,n,s),[h,s,n]),C=F.useCallback(O=>i({typedChunks:O}),[i]),E=F.useMemo(()=>Fi(o||"",f),[o,f]),x=en(e==null?void 0:e.decimals,E),v=F.useMemo(()=>t?S(x||"0").times(t||0).toString():"0",[x,t]);return{totalTrades:f,maxTrades:h,amountPerTradeUI:x,amountPerTrade:E,amountPerTradeUsd:v,onChange:C,error:Ca(f,h)}},xa=()=>{const{srcToken:e,dstToken:t}=q(),{onChange:n,totalTrades:r,amountPerTradeUsd:s,amountPerTradeUI:i,error:o,maxTrades:d,amountPerTrade:h}=qe();return{error:o,maxTrades:d,totalTrades:r,amountPerTradeUI:i,amountPerTrade:h,onChange:n,amountPerTradeUsd:s,fromToken:e,toToken:t}},Yr=e=>{const t=Gn(e);if(t>=1)return`${t.toFixed(t%1?1:0)} ${t===1?"day":"days"}`;const n=An(e)/60;if(n>=1)return`${n.toFixed(n%1?1:0)} ${n===1?"hour":"hours"}`;const r=An(e);return`${r.toFixed(r%1?1:0)} ${r===1?"minute":"minutes"}`},Sa=e=>{const{totalTrades:t}=qe(),{marketPrice:n,typedInputAmount:r}=q(),s=F.useMemo(()=>{const{isError:o,value:d}=Bi(e);if(!(!o||S(r||"0").isZero()||!n))return{type:me.MIN_FILL_DELAY,value:d,args:{fillDelay:Yr(d)}}},[e,r,n]),i=F.useMemo(()=>{const{isError:o,value:d}=Pi(e,t);if(!(!o||S(r||"0").isZero()||!n))return{type:me.MAX_FILL_DELAY,value:d,args:{fillDelay:Yr(d)}}},[e,r,n,t]);return s||i},Lt=()=>{const{callbacks:e}=q(),t=Q(i=>i.state.typedFillDelay),n=Q(i=>i.updateState),r=F.useMemo(()=>t||Bn,[t]),s=Sa(r);return{fillDelay:r,onChange:F.useCallback(i=>{var o;n({typedFillDelay:i}),(o=e==null?void 0:e.onFillDelayChange)==null||o.call(e,i)},[n,e]),error:s,milliseconds:r.unit*r.value}},va=()=>{const{onChange:e,fillDelay:t,error:n}=Lt(),r=F.useCallback(i=>e({unit:t.unit,value:Number(i)}),[e,t]),s=F.useCallback(i=>e({unit:i,value:t.value}),[e,t]);return{onInputChange:r,onUnitSelect:s,onChange:e,milliseconds:t.unit*t.value,fillDelay:t,error:n}},Fa=e=>{const{module:t,marketPrice:n}=q();return F.useMemo(()=>{const r=ki(t,e),s=_i(e);if(n){if(r.isError)return{type:me.MAX_ORDER_DURATION,value:r.value,args:{duration:`${Math.floor(Gn(r.value)).toFixed(0)} days`}};if(s.isError)return{type:me.MIN_ORDER_DURATION,value:s.value,args:{duration:`${Math.floor(An(s.value)).toFixed(0)} minutes`}}}},[e,t,n])},Jn=()=>{const{module:e,callbacks:t}=q(),n=Q(h=>h.state.typedDuration),r=Q(h=>h.updateState),s=qe().totalTrades,i=Lt().fillDelay,o=F.useMemo(()=>wi(e,s,i,n),[s,i,n,e]),d=Fa(o);return{duration:o,setDuration:F.useCallback(h=>{var f;r({typedDuration:h}),(f=t==null?void 0:t.onDurationChange)==null||f.call(t,h)},[r,t]),error:d}},Pa=()=>{const{duration:e,setDuration:t,error:n}=Jn(),r=F.useCallback(i=>{t({unit:e.unit,value:Number(i)})},[t,e]),s=F.useCallback(i=>{t({unit:i,value:e.value})},[t,e]);return{duration:e,onChange:t,milliseconds:e.unit*e.value,onInputChange:r,onUnitSelect:s,error:n}},Da=()=>{const{module:e}=q();return F.useMemo(()=>e===z.STOP_LOSS?ci:ui,[e])},er=()=>{const{module:e}=q(),t=Q(n=>n.state.isMarketOrder);return F.useMemo(()=>e!==z.STOP_LOSS&&e!==z.TAKE_PROFIT||t?void 0:e===z.STOP_LOSS?di:li,[e,t])},bn=()=>{const{srcToken:e,dstToken:t,marketPriceLoading:n}=q(),r=Q(f=>f.updateState),s=Q(f=>f.state.isInvertedTrade),i=Q(f=>f.state.typedTriggerPrice),o=Q(f=>f.state.typedLimitPrice),d=Q(f=>f.state.isMarketOrder);return{onInvert:F.useCallback(()=>{i!==void 0&&r({typedTriggerPrice:S(1).div(i).toFixed()}),o!==void 0&&r({typedLimitPrice:S(1).div(o).toFixed()}),r({isInvertedTrade:!s})},[r,s,i,o,n]),isInverted:s,fromToken:s?t:e,toToken:s?e:t,isMarketPrice:d}},Jr=({typedValue:e,tokenDecimals:t=18,initialPrice:n="0",percentage:r,setValue:s,setPercentage:i})=>{const{srcUsd1Token:o,dstUsd1Token:d}=q(),{isInverted:h}=bn(),f=F.useMemo(()=>S((()=>{if(e!==void 0){const k=h?S(e).isZero()?S(0):S(1).div(e):S(e);return Et(k.toFixed(),t)}if(r!==void 0&&S(n||"0").gt(0)&&!S(n||"0").isNaN()){const k=S(n||"0"),B=S(r||0).div(100);return k.plus(k.multipliedBy(B)).decimalPlaces(0).toFixed()}return S(n).gt(0)?n:""})()).decimalPlaces(0).toFixed(),[e,r,t,n,h]),C=F.useCallback(I=>{s(I),i(null)},[s,i]),E=F.useCallback(I=>{s(void 0),i(I)},[s,i]),x=F.useMemo(()=>{if(!n||S(n).isZero())return"";if(r!=null)return r;if(f){const I=S(n),B=S(f).minus(I).div(I).multipliedBy(100).decimalPlaces(2).toString();return S(B||"0").isZero()?"":B}return""},[f,n,r]),v=F.useMemo(()=>{let I="";if(e!==void 0)I=e;else{const k=Ee(f,t);if(S(k||"0").isZero())return"";I=h?S(1).div(k).toFixed():k}return I},[e,t,f,h]),O=nt(h?o:d,v||"0");return{amount:S(f).isNaN()?"":f,amountUI:S(v).isNaN()?"":v,selectedPercentage:x,onChange:C,onPercentageChange:E,isInverted:h,usd:S(O).isNaN()?"":O,isTypedValue:e!==void 0}},Oa=(e="")=>{const{module:t,marketPrice:n,typedInputAmount:r}=q();return F.useMemo(()=>{if(S(r||"0").isZero()||!n||t!==z.STOP_LOSS&&t!==z.TAKE_PROFIT)return;const s=Di(n||"",e||"",t);if(s!=null&&s.isError)return{type:me.STOP_LOSS_TRIGGER_PRICE_GREATER_THAN_MARKET_PRICE,value:s.value};const i=Oi(n||"",e||"",t);if(i!=null&&i.isError)return{type:me.TAKE_PROFIT_TRIGGER_PRICE_LESS_THAN_MARKET_PRICE,value:i.value};if(!e||S(e||0).isZero())return{type:me.EMPTY_TRIGGER_PRICE,value:e}},[n,e,t,r])},Ia=e=>{const{srcToken:t,dstToken:n,module:r,dstUsd1Token:s}=q(),i=qe().amountPerTrade,o=Q(f=>f.state.isMarketOrder),d=F.useMemo(()=>Ti(r,i,e,(t==null?void 0:t.decimals)||0),[e,i,o,t==null?void 0:t.decimals,r]),h=en((n==null?void 0:n.decimals)||0,d);return{amount:d,amountUI:h,usd:nt(h,s)}},bt=()=>{const{dstToken:e,marketPrice:t,module:n,callbacks:r}=q(),s=Q(O=>O.updateState),i=Da(),o=Q(O=>O.state.triggerPricePercent),d=o===void 0?i:o,h=n===z.STOP_LOSS||n===z.TAKE_PROFIT,f=Jr({typedValue:Q(O=>O.state.typedTriggerPrice),percentage:d,tokenDecimals:(e==null?void 0:e.decimals)||18,initialPrice:h?t:void 0,setValue:F.useCallback(O=>{var I;s({typedTriggerPrice:O}),(I=r==null?void 0:r.onTriggerPriceChange)==null||I.call(r,O||"")},[s,r]),setPercentage:F.useCallback(O=>{var I;s({triggerPricePercent:O}),(I=r==null?void 0:r.onTriggerPricePercentChange)==null||I.call(r,O||"")},[s,r])}),C=Oa(f.amount),{amount:E,amountUI:x,usd:v}=Ia(f.amount);return F.useMemo(()=>({...f,error:C,pricePerChunk:E,pricePerChunkUI:x,pricePerChunkUsd:v}),[f,C,E,x,v])},Ma=e=>{const{module:t,marketPrice:n,typedInputAmount:r}=q(),{amount:s}=bt(),i=Q(o=>o.state.isMarketOrder);return F.useMemo(()=>{if(S(r||"0").isZero()||!s||!n)return;const o=Ii(s,e,i,t),d=Mi(s,e,i,t);if(o!=null&&o.isError)return{type:me.TRIGGER_LIMIT_PRICE_GREATER_THAN_TRIGGER_PRICE,value:o.value};if(d!=null&&d.isError)return{type:me.TRIGGER_LIMIT_PRICE_GREATER_THAN_TRIGGER_PRICE,value:d.value};if(e&&S(e||0).isZero())return{type:me.MISSING_LIMIT_PRICE,value:e||""}},[e,s,t,i,r,n])},Tn=()=>{const{dstToken:e,marketPrice:t,callbacks:n}=q(),r=Q(f=>f.updateState),s=er(),i=Q(f=>f.state.limitPricePercent),o=i===void 0?s:i,d=Jr({typedValue:Q(f=>f.state.typedLimitPrice),percentage:o,tokenDecimals:(e==null?void 0:e.decimals)||18,initialPrice:t,setValue:F.useCallback(f=>{var C;r({typedLimitPrice:f}),(C=n==null?void 0:n.onLimitPriceChange)==null||C.call(n,f||"")},[r,n]),setPercentage:F.useCallback(f=>{var C;r({limitPricePercent:f}),(C=n==null?void 0:n.onLimitPricePercentChange)==null||C.call(n,f||"")},[r,n])}),h=Ma(d.amount);return F.useMemo(()=>({...d,error:h}),[d,h])},ka=()=>{const{module:e}=q(),t=Q(d=>d.updateState),n=Q(d=>d.state.isMarketOrder),r=er(),s=Q(d=>d.state.triggerPricePercent)||0,i=e===z.LIMIT,o=F.useCallback(()=>{!n&&e===z.STOP_LOSS&&t({limitPricePercent:r}),t({isMarketOrder:!n})},[t,s,e,n,r]);return{isLimitPrice:!n,toggleLimitPrice:o,hide:i}},_a=()=>{const{module:e,marketPriceLoading:t,srcToken:n,dstToken:r}=q(),{amount:s,amountUI:i,onChange:o,onPercentageChange:d,usd:h,selectedPercentage:f,error:C,isTypedValue:E}=Tn(),x=Q(K=>K.updateState),v=er(),{isLimitPrice:O,toggleLimitPrice:I}=ka(),{fromToken:k,toToken:B}=bn(),P=F.useCallback(()=>{x({typedLimitPrice:void 0}),x({limitPricePercent:v})},[x,e,v]);return{price:s,priceUI:i,error:C,onInputChange:o,onPercentageChange:d,onReset:P,usd:h,srcToken:n,dstToken:r,invertedSrcToken:k,invertedDstToken:B,percentage:f,isLoading:t,isLimitPrice:O,toggleLimitPrice:I,isTypedValue:E}},Ba=()=>{const{marketPrice:e,marketPriceLoading:t,srcToken:n,dstToken:r}=q(),{amount:s,amountUI:i,onChange:o,onPercentageChange:d,usd:h,selectedPercentage:f,error:C,pricePerChunk:E,pricePerChunkUI:x,pricePerChunkUsd:v,isTypedValue:O}=bt(),I=Q(K=>K.updateState),{fromToken:k,toToken:B}=bn(),P=F.useCallback(()=>{I({triggerPricePercent:void 0,typedTriggerPrice:void 0})},[I]);return{price:s,priceUI:i,amountPerChunk:E,amountPerChunkUI:x,amountPerChunkUsd:v,error:C,onInputChange:o,onPercentageChange:d,percentage:f,onReset:P,usd:h,srcToken:n,dstToken:r,invertedSrcToken:k,invertedDstToken:B,isLoading:t||!e,isTypedValue:O}},es=()=>{const{module:e,marketPrice:t}=q(),n=Tn().amount,r=bt().amount,s=Q(i=>i.state.isMarketOrder);return e===z.LIMIT||!s?n||"":e===z.STOP_LOSS||e===z.TAKE_PROFIT?r||"":t||""},wn=()=>{const{srcToken:e,dstToken:t,dstUsd1Token:n}=q(),r=es(),s=rt().amount,i=F.useMemo(()=>Ei(s||"",r,(e==null?void 0:e.decimals)||0),[s,r,e==null?void 0:e.decimals]),o=en(t==null?void 0:t.decimals,i);return{amount:i,amountUI:o,usd:nt(o,n)}},tr=()=>{const{srcToken:e,dstToken:t,dstUsd1Token:n}=q(),r=es(),s=qe().amountPerTrade,i=Q(h=>h.state.isMarketOrder),o=F.useMemo(()=>bi(s,r,!!i,(e==null?void 0:e.decimals)||0),[s,r,i,e==null?void 0:e.decimals]),d=en(t==null?void 0:t.decimals,o);return{amount:o,amountUI:d,usd:nt(d,n)}},Ua=()=>{const{typedInputAmount:e,marketPriceLoading:t,dstToken:n}=q(),{amountUI:r,usd:s}=wn(),o=wa()?e:r,d=Yn(n==null?void 0:n.decimals,o);return{value:o,valueWei:d,isLoading:t,usd:s}},Ra=()=>{const e=Q(s=>s.state.isMarketOrder),{module:t}=q(),n=F.useMemo(()=>{if(e&&t===z.STOP_LOSS)return Jt.TRIGGER_MARKET_PRICE},[e,t]),r=F.useMemo(()=>{if(!(t!==z.LIMIT&&t!==z.TWAP))return e?Jt.MARKET_PRICE:Jt.LIMIT_PRICE},[e,t]);return n||r},La=()=>{const{minChunkSizeUsd:e,typedInputAmount:t,srcUsd1Token:n}=q(),r=nt(t,n);return F.useMemo(()=>S(e).gt(S(r||"0"))?{type:me.MIN_TRADE_SIZE_ERROR,value:e}:void 0,[e,r])};function ts(){const{marketPrice:e,marketPriceLoading:t,typedInputAmount:n,srcUsd1Token:r,srcBalance:s,chainId:i}=q(),{error:o}=bt(),{error:d}=Tn(),{error:h}=qe(),{error:f}=Lt(),{error:C}=Jn(),E=La(),x=rt().amount,v=F.useMemo(()=>{if(s&&S(x).gt(s))return{type:me.INSUFFICIENT_BALANCE,value:s||""}},[s,x,i]);return F.useMemo(()=>Ni({marketPrice:e,typedInputAmount:n,srcUsd1Token:r,marketPriceLoading:t,triggerPriceError:o,limitPriceError:d,tradesError:h,fillDelayError:f,durationError:C,balanceError:v,minTradeSizeError:E}),[e,t,n,o,d,h,f,C,v,r,E])}var Nt=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},Na={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},qa=(Is=class{constructor(){N(this,Ke,Na);N(this,xt,!1)}setTimeoutProvider(e){process.env.NODE_ENV!=="production"&&l(this,xt)&&e!==l(this,Ke)&&console.error("[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.",{previous:l(this,Ke),provider:e}),_(this,Ke,e),process.env.NODE_ENV!=="production"&&_(this,xt,!1)}setTimeout(e,t){return process.env.NODE_ENV!=="production"&&_(this,xt,!0),l(this,Ke).setTimeout(e,t)}clearTimeout(e){l(this,Ke).clearTimeout(e)}setInterval(e,t){return process.env.NODE_ENV!=="production"&&_(this,xt,!0),l(this,Ke).setInterval(e,t)}clearInterval(e){l(this,Ke).clearInterval(e)}},Ke=new WeakMap,xt=new WeakMap,Is),Tt=new qa;function Ka(e){setTimeout(e,0)}var wt=typeof window>"u"||"Deno"in globalThis;function be(){}function Ha(e,t){return typeof e=="function"?e(t):e}function nr(e){return typeof e=="number"&&e>=0&&e!==1/0}function ns(e,t){return Math.max(e+(t||0)-Date.now(),0)}function st(e,t){return typeof e=="function"?e(t):e}function Me(e,t){return typeof e=="function"?e(t):e}function rs(e,t){const{type:n="all",exact:r,fetchStatus:s,predicate:i,queryKey:o,stale:d}=e;if(o){if(r){if(t.queryHash!==rr(o,t.options))return!1}else if(!tn(t.queryKey,o))return!1}if(n!=="all"){const h=t.isActive();if(n==="active"&&!h||n==="inactive"&&h)return!1}return!(typeof d=="boolean"&&t.isStale()!==d||s&&s!==t.state.fetchStatus||i&&!i(t))}function ss(e,t){const{exact:n,status:r,predicate:s,mutationKey:i}=e;if(i){if(!t.options.mutationKey)return!1;if(n){if(Ct(t.options.mutationKey)!==Ct(i))return!1}else if(!tn(t.options.mutationKey,i))return!1}return!(r&&t.state.status!==r||s&&!s(t))}function rr(e,t){return((t==null?void 0:t.queryKeyHashFn)||Ct)(e)}function Ct(e){return JSON.stringify(e,(t,n)=>ir(n)?Object.keys(n).sort().reduce((r,s)=>(r[s]=n[s],r),{}):n)}function tn(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?Object.keys(t).every(n=>tn(e[n],t[n])):!1}var Wa=Object.prototype.hasOwnProperty;function sr(e,t){if(e===t)return e;const n=is(e)&&is(t);if(!n&&!(ir(e)&&ir(t)))return t;const s=(n?e:Object.keys(e)).length,i=n?t:Object.keys(t),o=i.length,d=n?new Array(o):{};let h=0;for(let f=0;f<o;f++){const C=n?f:i[f],E=e[C],x=t[C];if(E===x){d[C]=E,(n?f<s:Wa.call(e,C))&&h++;continue}if(E===null||x===null||typeof E!="object"||typeof x!="object"){d[C]=x;continue}const v=sr(E,x);d[C]=v,v===E&&h++}return s===o&&h===s?e:d}function Cn(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(e[n]!==t[n])return!1;return!0}function is(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function ir(e){if(!as(e))return!1;const t=e.constructor;if(t===void 0)return!0;const n=t.prototype;return!(!as(n)||!n.hasOwnProperty("isPrototypeOf")||Object.getPrototypeOf(e)!==Object.prototype)}function as(e){return Object.prototype.toString.call(e)==="[object Object]"}function Qa(e){return new Promise(t=>{Tt.setTimeout(t,e)})}function ar(e,t,n){if(typeof n.structuralSharing=="function")return n.structuralSharing(e,t);if(n.structuralSharing!==!1){if(process.env.NODE_ENV!=="production")try{return sr(e,t)}catch(r){throw console.error(`Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${n.queryHash}]: ${r}`),r}return sr(e,t)}return t}function $a(e,t,n=0){const r=[...e,t];return n&&r.length>n?r.slice(1):r}function ja(e,t,n=0){const r=[t,...e];return n&&r.length>n?r.slice(0,-1):r}var xn=Symbol();function os(e,t){return process.env.NODE_ENV!=="production"&&e.queryFn===xn&&console.error(`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${e.queryHash}'`),!e.queryFn&&(t!=null&&t.initialPromise)?()=>t.initialPromise:!e.queryFn||e.queryFn===xn?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function cs(e,t){return typeof e=="function"?e(...t):!!e}var za=(Ms=class extends Nt{constructor(){super();N(this,St);N(this,at);N(this,qt);_(this,qt,t=>{if(!wt&&window.addEventListener){const n=()=>t();return window.addEventListener("visibilitychange",n,!1),()=>{window.removeEventListener("visibilitychange",n)}}})}onSubscribe(){l(this,at)||this.setEventListener(l(this,qt))}onUnsubscribe(){var t;this.hasListeners()||((t=l(this,at))==null||t.call(this),_(this,at,void 0))}setEventListener(t){var n;_(this,qt,t),(n=l(this,at))==null||n.call(this),_(this,at,t(r=>{typeof r=="boolean"?this.setFocused(r):this.onFocus()}))}setFocused(t){l(this,St)!==t&&(_(this,St,t),this.onFocus())}onFocus(){const t=this.isFocused();this.listeners.forEach(n=>{n(t)})}isFocused(){var t;return typeof l(this,St)=="boolean"?l(this,St):((t=globalThis.document)==null?void 0:t.visibilityState)!=="hidden"}},St=new WeakMap,at=new WeakMap,qt=new WeakMap,Ms),or=new za;function cr(){let e,t;const n=new Promise((s,i)=>{e=s,t=i});n.status="pending",n.catch(()=>{});function r(s){Object.assign(n,s),delete n.resolve,delete n.reject}return n.resolve=s=>{r({status:"fulfilled",value:s}),e(s)},n.reject=s=>{r({status:"rejected",reason:s}),t(s)},n}var Va=Ka;function Ga(){let e=[],t=0,n=d=>{d()},r=d=>{d()},s=Va;const i=d=>{t?e.push(d):s(()=>{n(d)})},o=()=>{const d=e;e=[],d.length&&s(()=>{r(()=>{d.forEach(h=>{n(h)})})})};return{batch:d=>{let h;t++;try{h=d()}finally{t--,t||o()}return h},batchCalls:d=>(...h)=>{i(()=>{d(...h)})},schedule:i,setNotifyFunction:d=>{n=d},setBatchNotifyFunction:d=>{r=d},setScheduler:d=>{s=d}}}var ue=Ga(),Xa=(ks=class extends Nt{constructor(){super();N(this,Kt,!0);N(this,ot);N(this,Ht);_(this,Ht,t=>{if(!wt&&window.addEventListener){const n=()=>t(!0),r=()=>t(!1);return window.addEventListener("online",n,!1),window.addEventListener("offline",r,!1),()=>{window.removeEventListener("online",n),window.removeEventListener("offline",r)}}})}onSubscribe(){l(this,ot)||this.setEventListener(l(this,Ht))}onUnsubscribe(){var t;this.hasListeners()||((t=l(this,ot))==null||t.call(this),_(this,ot,void 0))}setEventListener(t){var n;_(this,Ht,t),(n=l(this,ot))==null||n.call(this),_(this,ot,t(this.setOnline.bind(this)))}setOnline(t){l(this,Kt)!==t&&(_(this,Kt,t),this.listeners.forEach(r=>{r(t)}))}isOnline(){return l(this,Kt)}},Kt=new WeakMap,ot=new WeakMap,Ht=new WeakMap,ks),Sn=new Xa;function Za(e){return Math.min(1e3*2**e,3e4)}function us(e){return(e??"online")==="online"?Sn.isOnline():!0}var ur=class extends Error{constructor(e){super("CancelledError"),this.revert=e==null?void 0:e.revert,this.silent=e==null?void 0:e.silent}};function ds(e){let t=!1,n=0,r;const s=cr(),i=()=>s.status!=="pending",o=I=>{var k;if(!i()){const B=new ur(I);x(B),(k=e.onCancel)==null||k.call(e,B)}},d=()=>{t=!0},h=()=>{t=!1},f=()=>or.isFocused()&&(e.networkMode==="always"||Sn.isOnline())&&e.canRun(),C=()=>us(e.networkMode)&&e.canRun(),E=I=>{i()||(r==null||r(),s.resolve(I))},x=I=>{i()||(r==null||r(),s.reject(I))},v=()=>new Promise(I=>{var k;r=B=>{(i()||f())&&I(B)},(k=e.onPause)==null||k.call(e)}).then(()=>{var I;r=void 0,i()||(I=e.onContinue)==null||I.call(e)}),O=()=>{if(i())return;let I;const k=n===0?e.initialPromise:void 0;try{I=k??e.fn()}catch(B){I=Promise.reject(B)}Promise.resolve(I).then(E).catch(B=>{var Y;if(i())return;const P=e.retry??(wt?0:3),K=e.retryDelay??Za,U=typeof K=="function"?K(n,B):K,Z=P===!0||typeof P=="number"&&n<P||typeof P=="function"&&P(n,B);if(t||!Z){x(B);return}n++,(Y=e.onFail)==null||Y.call(e,n,B),Qa(U).then(()=>f()?void 0:v()).then(()=>{t?x(B):O()})})};return{promise:s,status:()=>s.status,cancel:o,continue:()=>(r==null||r(),s),cancelRetry:d,continueRetry:h,canStart:C,start:()=>(C()?O():v().then(O),s)}}var ls=(_s=class{constructor(){N(this,vt)}destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),nr(this.gcTime)&&_(this,vt,Tt.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(wt?1/0:300*1e3))}clearGcTimeout(){l(this,vt)&&(Tt.clearTimeout(l(this,vt)),_(this,vt,void 0))}},vt=new WeakMap,_s),Ya=(Bs=class extends ls{constructor(t){super();N(this,Le);N(this,Ft);N(this,Wt);N(this,ke);N(this,Pt);N(this,he);N(this,rn);N(this,Dt);_(this,Dt,!1),_(this,rn,t.defaultOptions),this.setOptions(t.options),this.observers=[],_(this,Pt,t.client),_(this,ke,l(this,Pt).getQueryCache()),this.queryKey=t.queryKey,this.queryHash=t.queryHash,_(this,Ft,ps(this.options)),this.state=t.state??l(this,Ft),this.scheduleGc()}get meta(){return this.options.meta}get promise(){var t;return(t=l(this,he))==null?void 0:t.promise}setOptions(t){if(this.options={...l(this,rn),...t},this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){const n=ps(this.options);n.data!==void 0&&(this.setState(hs(n.data,n.dataUpdatedAt)),_(this,Ft,n))}}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&l(this,ke).remove(this)}setData(t,n){const r=ar(this.state.data,t,this.options);return $(this,Le,Je).call(this,{data:r,type:"success",dataUpdatedAt:n==null?void 0:n.updatedAt,manual:n==null?void 0:n.manual}),r}setState(t,n){$(this,Le,Je).call(this,{type:"setState",state:t,setStateOptions:n})}cancel(t){var r,s;const n=(r=l(this,he))==null?void 0:r.promise;return(s=l(this,he))==null||s.cancel(t),n?n.then(be).catch(be):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(l(this,Ft))}isActive(){return this.observers.some(t=>Me(t.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===xn||this.state.dataUpdateCount+this.state.errorUpdateCount===0}isStatic(){return this.getObserversCount()>0?this.observers.some(t=>st(t.options.staleTime,this)==="static"):!1}isStale(){return this.getObserversCount()>0?this.observers.some(t=>t.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(t=0){return this.state.data===void 0?!0:t==="static"?!1:this.state.isInvalidated?!0:!ns(this.state.dataUpdatedAt,t)}onFocus(){var n;const t=this.observers.find(r=>r.shouldFetchOnWindowFocus());t==null||t.refetch({cancelRefetch:!1}),(n=l(this,he))==null||n.continue()}onOnline(){var n;const t=this.observers.find(r=>r.shouldFetchOnReconnect());t==null||t.refetch({cancelRefetch:!1}),(n=l(this,he))==null||n.continue()}addObserver(t){this.observers.includes(t)||(this.observers.push(t),this.clearGcTimeout(),l(this,ke).notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){this.observers.includes(t)&&(this.observers=this.observers.filter(n=>n!==t),this.observers.length||(l(this,he)&&(l(this,Dt)?l(this,he).cancel({revert:!0}):l(this,he).cancelRetry()),this.scheduleGc()),l(this,ke).notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||$(this,Le,Je).call(this,{type:"invalidate"})}async fetch(t,n){var h,f,C,E,x,v,O,I,k,B,P,K;if(this.state.fetchStatus!=="idle"&&((h=l(this,he))==null?void 0:h.status())!=="rejected"){if(this.state.data!==void 0&&(n!=null&&n.cancelRefetch))this.cancel({silent:!0});else if(l(this,he))return l(this,he).continueRetry(),l(this,he).promise}if(t&&this.setOptions(t),!this.options.queryFn){const U=this.observers.find(Z=>Z.options.queryFn);U&&this.setOptions(U.options)}process.env.NODE_ENV!=="production"&&(Array.isArray(this.options.queryKey)||console.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"));const r=new AbortController,s=U=>{Object.defineProperty(U,"signal",{enumerable:!0,get:()=>(_(this,Dt,!0),r.signal)})},i=()=>{const U=os(this.options,n),Y=(()=>{const oe={client:l(this,Pt),queryKey:this.queryKey,meta:this.meta};return s(oe),oe})();return _(this,Dt,!1),this.options.persister?this.options.persister(U,Y,this):U(Y)},d=(()=>{const U={fetchOptions:n,options:this.options,queryKey:this.queryKey,client:l(this,Pt),state:this.state,fetchFn:i};return s(U),U})();(f=this.options.behavior)==null||f.onFetch(d,this),_(this,Wt,this.state),(this.state.fetchStatus==="idle"||this.state.fetchMeta!==((C=d.fetchOptions)==null?void 0:C.meta))&&$(this,Le,Je).call(this,{type:"fetch",meta:(E=d.fetchOptions)==null?void 0:E.meta}),_(this,he,ds({initialPromise:n==null?void 0:n.initialPromise,fn:d.fetchFn,onCancel:U=>{U instanceof ur&&U.revert&&this.setState({...l(this,Wt),fetchStatus:"idle"}),r.abort()},onFail:(U,Z)=>{$(this,Le,Je).call(this,{type:"failed",failureCount:U,error:Z})},onPause:()=>{$(this,Le,Je).call(this,{type:"pause"})},onContinue:()=>{$(this,Le,Je).call(this,{type:"continue"})},retry:d.options.retry,retryDelay:d.options.retryDelay,networkMode:d.options.networkMode,canRun:()=>!0}));try{const U=await l(this,he).start();if(U===void 0)throw process.env.NODE_ENV!=="production"&&console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`),new Error(`${this.queryHash} data is undefined`);return this.setData(U),(v=(x=l(this,ke).config).onSuccess)==null||v.call(x,U,this),(I=(O=l(this,ke).config).onSettled)==null||I.call(O,U,this.state.error,this),U}catch(U){if(U instanceof ur){if(U.silent)return l(this,he).promise;if(U.revert){if(this.state.data===void 0)throw U;return this.state.data}}throw $(this,Le,Je).call(this,{type:"error",error:U}),(B=(k=l(this,ke).config).onError)==null||B.call(k,U,this),(K=(P=l(this,ke).config).onSettled)==null||K.call(P,this.state.data,U,this),U}finally{this.scheduleGc()}}},Ft=new WeakMap,Wt=new WeakMap,ke=new WeakMap,Pt=new WeakMap,he=new WeakMap,rn=new WeakMap,Dt=new WeakMap,Le=new WeakSet,Je=function(t){const n=r=>{switch(t.type){case"failed":return{...r,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...r,fetchStatus:"paused"};case"continue":return{...r,fetchStatus:"fetching"};case"fetch":return{...r,...fs(r.data,this.options),fetchMeta:t.meta??null};case"success":const s={...r,...hs(t.data,t.dataUpdatedAt),dataUpdateCount:r.dataUpdateCount+1,...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};return _(this,Wt,t.manual?s:void 0),s;case"error":const i=t.error;return{...r,error:i,errorUpdateCount:r.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:r.fetchFailureCount+1,fetchFailureReason:i,fetchStatus:"idle",status:"error"};case"invalidate":return{...r,isInvalidated:!0};case"setState":return{...r,...t.state}}};this.state=n(this.state),ue.batch(()=>{this.observers.forEach(r=>{r.onQueryUpdate()}),l(this,ke).notify({query:this,type:"updated",action:t})})},Bs);function fs(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:us(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}function hs(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:"success"}}function ps(e){const t=typeof e.initialData=="function"?e.initialData():e.initialData,n=t!==void 0,r=n?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:n?r??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:n?"success":"pending",fetchStatus:"idle"}}var Ja=(Us=class extends Nt{constructor(t,n){super();N(this,ee);N(this,ve);N(this,X);N(this,sn);N(this,Te);N(this,Ot);N(this,Qt);N(this,Ve);N(this,ct);N(this,an);N(this,$t);N(this,jt);N(this,It);N(this,Mt);N(this,ut);N(this,zt,new Set);this.options=n,_(this,ve,t),_(this,ct,null),_(this,Ve,cr()),this.bindMethods(),this.setOptions(n)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(l(this,X).addObserver(this),ms(l(this,X),this.options)?$(this,ee,dn).call(this):this.updateResult(),$(this,ee,wr).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return dr(l(this,X),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return dr(l(this,X),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,$(this,ee,Cr).call(this),$(this,ee,xr).call(this),l(this,X).removeObserver(this)}setOptions(t){const n=this.options,r=l(this,X);if(this.options=l(this,ve).defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof Me(this.options.enabled,l(this,X))!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");$(this,ee,Sr).call(this),l(this,X).setOptions(this.options),n._defaulted&&!Cn(this.options,n)&&l(this,ve).getQueryCache().notify({type:"observerOptionsUpdated",query:l(this,X),observer:this});const s=this.hasListeners();s&&ys(l(this,X),r,this.options,n)&&$(this,ee,dn).call(this),this.updateResult(),s&&(l(this,X)!==r||Me(this.options.enabled,l(this,X))!==Me(n.enabled,l(this,X))||st(this.options.staleTime,l(this,X))!==st(n.staleTime,l(this,X)))&&$(this,ee,Er).call(this);const i=$(this,ee,br).call(this);s&&(l(this,X)!==r||Me(this.options.enabled,l(this,X))!==Me(n.enabled,l(this,X))||i!==l(this,ut))&&$(this,ee,Tr).call(this,i)}getOptimisticResult(t){const n=l(this,ve).getQueryCache().build(l(this,ve),t),r=this.createResult(n,t);return to(this,r)&&(_(this,Te,r),_(this,Qt,this.options),_(this,Ot,l(this,X).state)),r}getCurrentResult(){return l(this,Te)}trackResult(t,n){return new Proxy(t,{get:(r,s)=>(this.trackProp(s),n==null||n(s),s==="promise"&&(this.trackProp("data"),!this.options.experimental_prefetchInRender&&l(this,Ve).status==="pending"&&l(this,Ve).reject(new Error("experimental_prefetchInRender feature flag is not enabled"))),Reflect.get(r,s))})}trackProp(t){l(this,zt).add(t)}getCurrentQuery(){return l(this,X)}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const n=l(this,ve).defaultQueryOptions(t),r=l(this,ve).getQueryCache().build(l(this,ve),n);return r.fetch().then(()=>this.createResult(r,n))}fetch(t){return $(this,ee,dn).call(this,{...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),l(this,Te)))}createResult(t,n){var c;const r=l(this,X),s=this.options,i=l(this,Te),o=l(this,Ot),d=l(this,Qt),f=t!==r?t.state:l(this,sn),{state:C}=t;let E={...C},x=!1,v;if(n._optimisticResults){const u=this.hasListeners(),A=!u&&ms(t,n),m=u&&ys(t,r,n,s);(A||m)&&(E={...E,...fs(C.data,t.options)}),n._optimisticResults==="isRestoring"&&(E.fetchStatus="idle")}let{error:O,errorUpdatedAt:I,status:k}=E;v=E.data;let B=!1;if(n.placeholderData!==void 0&&v===void 0&&k==="pending"){let u;i!=null&&i.isPlaceholderData&&n.placeholderData===(d==null?void 0:d.placeholderData)?(u=i.data,B=!0):u=typeof n.placeholderData=="function"?n.placeholderData((c=l(this,jt))==null?void 0:c.state.data,l(this,jt)):n.placeholderData,u!==void 0&&(k="success",v=ar(i==null?void 0:i.data,u,n),x=!0)}if(n.select&&v!==void 0&&!B)if(i&&v===(o==null?void 0:o.data)&&n.select===l(this,an))v=l(this,$t);else try{_(this,an,n.select),v=n.select(v),v=ar(i==null?void 0:i.data,v,n),_(this,$t,v),_(this,ct,null)}catch(u){_(this,ct,u)}l(this,ct)&&(O=l(this,ct),v=l(this,$t),I=Date.now(),k="error");const P=E.fetchStatus==="fetching",K=k==="pending",U=k==="error",Z=K&&P,Y=v!==void 0,a={status:k,fetchStatus:E.fetchStatus,isPending:K,isSuccess:k==="success",isError:U,isInitialLoading:Z,isLoading:Z,data:v,dataUpdatedAt:E.dataUpdatedAt,error:O,errorUpdatedAt:I,failureCount:E.fetchFailureCount,failureReason:E.fetchFailureReason,errorUpdateCount:E.errorUpdateCount,isFetched:E.dataUpdateCount>0||E.errorUpdateCount>0,isFetchedAfterMount:E.dataUpdateCount>f.dataUpdateCount||E.errorUpdateCount>f.errorUpdateCount,isFetching:P,isRefetching:P&&!K,isLoadingError:U&&!Y,isPaused:E.fetchStatus==="paused",isPlaceholderData:x,isRefetchError:U&&Y,isStale:lr(t,n),refetch:this.refetch,promise:l(this,Ve),isEnabled:Me(n.enabled,t)!==!1};if(this.options.experimental_prefetchInRender){const u=y=>{a.status==="error"?y.reject(a.error):a.data!==void 0&&y.resolve(a.data)},A=()=>{const y=_(this,Ve,a.promise=cr());u(y)},m=l(this,Ve);switch(m.status){case"pending":t.queryHash===r.queryHash&&u(m);break;case"fulfilled":(a.status==="error"||a.data!==m.value)&&A();break;case"rejected":(a.status!=="error"||a.error!==m.reason)&&A();break}}return a}updateResult(){const t=l(this,Te),n=this.createResult(l(this,X),this.options);if(_(this,Ot,l(this,X).state),_(this,Qt,this.options),l(this,Ot).data!==void 0&&_(this,jt,l(this,X)),Cn(n,t))return;_(this,Te,n);const r=()=>{if(!t)return!0;const{notifyOnChangeProps:s}=this.options,i=typeof s=="function"?s():s;if(i==="all"||!i&&!l(this,zt).size)return!0;const o=new Set(i??l(this,zt));return this.options.throwOnError&&o.add("error"),Object.keys(l(this,Te)).some(d=>{const h=d;return l(this,Te)[h]!==t[h]&&o.has(h)})};$(this,ee,Ws).call(this,{listeners:r()})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&$(this,ee,wr).call(this)}},ve=new WeakMap,X=new WeakMap,sn=new WeakMap,Te=new WeakMap,Ot=new WeakMap,Qt=new WeakMap,Ve=new WeakMap,ct=new WeakMap,an=new WeakMap,$t=new WeakMap,jt=new WeakMap,It=new WeakMap,Mt=new WeakMap,ut=new WeakMap,zt=new WeakMap,ee=new WeakSet,dn=function(t){$(this,ee,Sr).call(this);let n=l(this,X).fetch(this.options,t);return t!=null&&t.throwOnError||(n=n.catch(be)),n},Er=function(){$(this,ee,Cr).call(this);const t=st(this.options.staleTime,l(this,X));if(wt||l(this,Te).isStale||!nr(t))return;const r=ns(l(this,Te).dataUpdatedAt,t)+1;_(this,It,Tt.setTimeout(()=>{l(this,Te).isStale||this.updateResult()},r))},br=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(l(this,X)):this.options.refetchInterval)??!1},Tr=function(t){$(this,ee,xr).call(this),_(this,ut,t),!(wt||Me(this.options.enabled,l(this,X))===!1||!nr(l(this,ut))||l(this,ut)===0)&&_(this,Mt,Tt.setInterval(()=>{(this.options.refetchIntervalInBackground||or.isFocused())&&$(this,ee,dn).call(this)},l(this,ut)))},wr=function(){$(this,ee,Er).call(this),$(this,ee,Tr).call(this,$(this,ee,br).call(this))},Cr=function(){l(this,It)&&(Tt.clearTimeout(l(this,It)),_(this,It,void 0))},xr=function(){l(this,Mt)&&(Tt.clearInterval(l(this,Mt)),_(this,Mt,void 0))},Sr=function(){const t=l(this,ve).getQueryCache().build(l(this,ve),this.options);if(t===l(this,X))return;const n=l(this,X);_(this,X,t),_(this,sn,t.state),this.hasListeners()&&(n==null||n.removeObserver(this),t.addObserver(this))},Ws=function(t){ue.batch(()=>{t.listeners&&this.listeners.forEach(n=>{n(l(this,Te))}),l(this,ve).getQueryCache().notify({query:l(this,X),type:"observerResultsUpdated"})})},Us);function eo(e,t){return Me(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status==="error"&&t.retryOnMount===!1)}function ms(e,t){return eo(e,t)||e.state.data!==void 0&&dr(e,t,t.refetchOnMount)}function dr(e,t,n){if(Me(t.enabled,e)!==!1&&st(t.staleTime,e)!=="static"){const r=typeof n=="function"?n(e):n;return r==="always"||r!==!1&&lr(e,t)}return!1}function ys(e,t,n,r){return(e!==t||Me(r.enabled,e)===!1)&&(!n.suspense||e.state.status!=="error")&&lr(e,n)}function lr(e,t){return Me(t.enabled,e)!==!1&&e.isStaleByTime(st(t.staleTime,e))}function to(e,t){return!Cn(e.getCurrentResult(),t)}function gs(e){return{onFetch:(t,n)=>{var C,E,x,v,O;const r=t.options,s=(x=(E=(C=t.fetchOptions)==null?void 0:C.meta)==null?void 0:E.fetchMore)==null?void 0:x.direction,i=((v=t.state.data)==null?void 0:v.pages)||[],o=((O=t.state.data)==null?void 0:O.pageParams)||[];let d={pages:[],pageParams:[]},h=0;const f=async()=>{let I=!1;const k=K=>{Object.defineProperty(K,"signal",{enumerable:!0,get:()=>(t.signal.aborted?I=!0:t.signal.addEventListener("abort",()=>{I=!0}),t.signal)})},B=os(t.options,t.fetchOptions),P=async(K,U,Z)=>{if(I)return Promise.reject();if(U==null&&K.pages.length)return Promise.resolve(K);const oe=(()=>{const A={client:t.client,queryKey:t.queryKey,pageParam:U,direction:Z?"backward":"forward",meta:t.options.meta};return k(A),A})(),a=await B(oe),{maxPages:c}=t.options,u=Z?ja:$a;return{pages:u(K.pages,a,c),pageParams:u(K.pageParams,U,c)}};if(s&&i.length){const K=s==="backward",U=K?no:As,Z={pages:i,pageParams:o},Y=U(r,Z);d=await P(Z,Y,K)}else{const K=e??i.length;do{const U=h===0?o[0]??r.initialPageParam:As(r,d);if(h>0&&U==null)break;d=await P(d,U),h++}while(h<K)}return d};t.options.persister?t.fetchFn=()=>{var I,k;return(k=(I=t.options).persister)==null?void 0:k.call(I,f,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},n)}:t.fetchFn=f}}}function As(e,{pages:t,pageParams:n}){const r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,n[r],n):void 0}function no(e,{pages:t,pageParams:n}){var r;return t.length>0?(r=e.getPreviousPageParam)==null?void 0:r.call(e,t[0],t,n[0],n):void 0}var ro=(Rs=class extends ls{constructor(t){super();N(this,We);N(this,on);N(this,He);N(this,we);N(this,kt);_(this,on,t.client),this.mutationId=t.mutationId,_(this,we,t.mutationCache),_(this,He,[]),this.state=t.state||Es(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options=t,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){l(this,He).includes(t)||(l(this,He).push(t),this.clearGcTimeout(),l(this,we).notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){_(this,He,l(this,He).filter(n=>n!==t)),this.scheduleGc(),l(this,we).notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){l(this,He).length||(this.state.status==="pending"?this.scheduleGc():l(this,we).remove(this))}continue(){var t;return((t=l(this,kt))==null?void 0:t.continue())??this.execute(this.state.variables)}async execute(t){var o,d,h,f,C,E,x,v,O,I,k,B,P,K,U,Z,Y,oe,a,c;const n=()=>{$(this,We,pt).call(this,{type:"continue"})},r={client:l(this,on),meta:this.options.meta,mutationKey:this.options.mutationKey};_(this,kt,ds({fn:()=>this.options.mutationFn?this.options.mutationFn(t,r):Promise.reject(new Error("No mutationFn found")),onFail:(u,A)=>{$(this,We,pt).call(this,{type:"failed",failureCount:u,error:A})},onPause:()=>{$(this,We,pt).call(this,{type:"pause"})},onContinue:n,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>l(this,we).canRun(this)}));const s=this.state.status==="pending",i=!l(this,kt).canStart();try{if(s)n();else{$(this,We,pt).call(this,{type:"pending",variables:t,isPaused:i}),await((d=(o=l(this,we).config).onMutate)==null?void 0:d.call(o,t,this,r));const A=await((f=(h=this.options).onMutate)==null?void 0:f.call(h,t,r));A!==this.state.context&&$(this,We,pt).call(this,{type:"pending",context:A,variables:t,isPaused:i})}const u=await l(this,kt).start();return await((E=(C=l(this,we).config).onSuccess)==null?void 0:E.call(C,u,t,this.state.context,this,r)),await((v=(x=this.options).onSuccess)==null?void 0:v.call(x,u,t,this.state.context,r)),await((I=(O=l(this,we).config).onSettled)==null?void 0:I.call(O,u,null,this.state.variables,this.state.context,this,r)),await((B=(k=this.options).onSettled)==null?void 0:B.call(k,u,null,t,this.state.context,r)),$(this,We,pt).call(this,{type:"success",data:u}),u}catch(u){try{throw await((K=(P=l(this,we).config).onError)==null?void 0:K.call(P,u,t,this.state.context,this,r)),await((Z=(U=this.options).onError)==null?void 0:Z.call(U,u,t,this.state.context,r)),await((oe=(Y=l(this,we).config).onSettled)==null?void 0:oe.call(Y,void 0,u,this.state.variables,this.state.context,this,r)),await((c=(a=this.options).onSettled)==null?void 0:c.call(a,void 0,u,t,this.state.context,r)),u}finally{$(this,We,pt).call(this,{type:"error",error:u})}}finally{l(this,we).runNext(this)}}},on=new WeakMap,He=new WeakMap,we=new WeakMap,kt=new WeakMap,We=new WeakSet,pt=function(t){const n=r=>{switch(t.type){case"failed":return{...r,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...r,isPaused:!0};case"continue":return{...r,isPaused:!1};case"pending":return{...r,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:t.isPaused,status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...r,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...r,data:void 0,error:t.error,failureCount:r.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=n(this.state),ue.batch(()=>{l(this,He).forEach(r=>{r.onMutationUpdate(t)}),l(this,we).notify({mutation:this,type:"updated",action:t})})},Rs);function Es(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var so=(Ls=class extends Nt{constructor(t={}){super();N(this,Ge);N(this,Ne);N(this,cn);this.config=t,_(this,Ge,new Set),_(this,Ne,new Map),_(this,cn,0)}build(t,n,r){const s=new ro({client:t,mutationCache:this,mutationId:++On(this,cn)._,options:t.defaultMutationOptions(n),state:r});return this.add(s),s}add(t){l(this,Ge).add(t);const n=vn(t);if(typeof n=="string"){const r=l(this,Ne).get(n);r?r.push(t):l(this,Ne).set(n,[t])}this.notify({type:"added",mutation:t})}remove(t){if(l(this,Ge).delete(t)){const n=vn(t);if(typeof n=="string"){const r=l(this,Ne).get(n);if(r)if(r.length>1){const s=r.indexOf(t);s!==-1&&r.splice(s,1)}else r[0]===t&&l(this,Ne).delete(n)}}this.notify({type:"removed",mutation:t})}canRun(t){const n=vn(t);if(typeof n=="string"){const r=l(this,Ne).get(n),s=r==null?void 0:r.find(i=>i.state.status==="pending");return!s||s===t}else return!0}runNext(t){var r;const n=vn(t);if(typeof n=="string"){const s=(r=l(this,Ne).get(n))==null?void 0:r.find(i=>i!==t&&i.state.isPaused);return(s==null?void 0:s.continue())??Promise.resolve()}else return Promise.resolve()}clear(){ue.batch(()=>{l(this,Ge).forEach(t=>{this.notify({type:"removed",mutation:t})}),l(this,Ge).clear(),l(this,Ne).clear()})}getAll(){return Array.from(l(this,Ge))}find(t){const n={exact:!0,...t};return this.getAll().find(r=>ss(n,r))}findAll(t={}){return this.getAll().filter(n=>ss(t,n))}notify(t){ue.batch(()=>{this.listeners.forEach(n=>{n(t)})})}resumePausedMutations(){const t=this.getAll().filter(n=>n.state.isPaused);return ue.batch(()=>Promise.all(t.map(n=>n.continue().catch(be))))}},Ge=new WeakMap,Ne=new WeakMap,cn=new WeakMap,Ls);function vn(e){var t;return(t=e.options.scope)==null?void 0:t.id}var io=(Ns=class extends Nt{constructor(t,n){super();N(this,Ye);N(this,Xe);N(this,dt);N(this,Fe);N(this,Ze);_(this,Xe,t),this.setOptions(n),this.bindMethods(),$(this,Ye,In).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){var r;const n=this.options;this.options=l(this,Xe).defaultMutationOptions(t),Cn(this.options,n)||l(this,Xe).getMutationCache().notify({type:"observerOptionsUpdated",mutation:l(this,Fe),observer:this}),n!=null&&n.mutationKey&&this.options.mutationKey&&Ct(n.mutationKey)!==Ct(this.options.mutationKey)?this.reset():((r=l(this,Fe))==null?void 0:r.state.status)==="pending"&&l(this,Fe).setOptions(this.options)}onUnsubscribe(){var t;this.hasListeners()||(t=l(this,Fe))==null||t.removeObserver(this)}onMutationUpdate(t){$(this,Ye,In).call(this),$(this,Ye,vr).call(this,t)}getCurrentResult(){return l(this,dt)}reset(){var t;(t=l(this,Fe))==null||t.removeObserver(this),_(this,Fe,void 0),$(this,Ye,In).call(this),$(this,Ye,vr).call(this)}mutate(t,n){var r;return _(this,Ze,n),(r=l(this,Fe))==null||r.removeObserver(this),_(this,Fe,l(this,Xe).getMutationCache().build(l(this,Xe),this.options)),l(this,Fe).addObserver(this),l(this,Fe).execute(t)}},Xe=new WeakMap,dt=new WeakMap,Fe=new WeakMap,Ze=new WeakMap,Ye=new WeakSet,In=function(){var n;const t=((n=l(this,Fe))==null?void 0:n.state)??Es();_(this,dt,{...t,isPending:t.status==="pending",isSuccess:t.status==="success",isError:t.status==="error",isIdle:t.status==="idle",mutate:this.mutate,reset:this.reset})},vr=function(t){ue.batch(()=>{var n,r,s,i,o,d,h,f;if(l(this,Ze)&&this.hasListeners()){const C=l(this,dt).variables,E=l(this,dt).context,x={client:l(this,Xe),meta:this.options.meta,mutationKey:this.options.mutationKey};(t==null?void 0:t.type)==="success"?((r=(n=l(this,Ze)).onSuccess)==null||r.call(n,t.data,C,E,x),(i=(s=l(this,Ze)).onSettled)==null||i.call(s,t.data,null,C,E,x)):(t==null?void 0:t.type)==="error"&&((d=(o=l(this,Ze)).onError)==null||d.call(o,t.error,C,E,x),(f=(h=l(this,Ze)).onSettled)==null||f.call(h,void 0,t.error,C,E,x))}this.listeners.forEach(C=>{C(l(this,dt))})})},Ns),ao=(qs=class extends Nt{constructor(t={}){super();N(this,Qe);this.config=t,_(this,Qe,new Map)}build(t,n,r){const s=n.queryKey,i=n.queryHash??rr(s,n);let o=this.get(i);return o||(o=new Ya({client:t,queryKey:s,queryHash:i,options:t.defaultQueryOptions(n),state:r,defaultOptions:t.getQueryDefaults(s)}),this.add(o)),o}add(t){l(this,Qe).has(t.queryHash)||(l(this,Qe).set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const n=l(this,Qe).get(t.queryHash);n&&(t.destroy(),n===t&&l(this,Qe).delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){ue.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return l(this,Qe).get(t)}getAll(){return[...l(this,Qe).values()]}find(t){const n={exact:!0,...t};return this.getAll().find(r=>rs(n,r))}findAll(t={}){const n=this.getAll();return Object.keys(t).length>0?n.filter(r=>rs(t,r)):n}notify(t){ue.batch(()=>{this.listeners.forEach(n=>{n(t)})})}onFocus(){ue.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){ue.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},Qe=new WeakMap,qs),oo=(Ks=class{constructor(e={}){N(this,se);N(this,lt);N(this,ft);N(this,Vt);N(this,Gt);N(this,ht);N(this,Xt);N(this,Zt);_(this,se,e.queryCache||new ao),_(this,lt,e.mutationCache||new so),_(this,ft,e.defaultOptions||{}),_(this,Vt,new Map),_(this,Gt,new Map),_(this,ht,0)}mount(){On(this,ht)._++,l(this,ht)===1&&(_(this,Xt,or.subscribe(async e=>{e&&(await this.resumePausedMutations(),l(this,se).onFocus())})),_(this,Zt,Sn.subscribe(async e=>{e&&(await this.resumePausedMutations(),l(this,se).onOnline())})))}unmount(){var e,t;On(this,ht)._--,l(this,ht)===0&&((e=l(this,Xt))==null||e.call(this),_(this,Xt,void 0),(t=l(this,Zt))==null||t.call(this),_(this,Zt,void 0))}isFetching(e){return l(this,se).findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return l(this,lt).findAll({...e,status:"pending"}).length}getQueryData(e){var n;const t=this.defaultQueryOptions({queryKey:e});return(n=l(this,se).get(t.queryHash))==null?void 0:n.state.data}ensureQueryData(e){const t=this.defaultQueryOptions(e),n=l(this,se).build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(st(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return l(this,se).findAll(e).map(({queryKey:t,state:n})=>{const r=n.data;return[t,r]})}setQueryData(e,t,n){const r=this.defaultQueryOptions({queryKey:e}),s=l(this,se).get(r.queryHash),i=s==null?void 0:s.state.data,o=Ha(t,i);if(o!==void 0)return l(this,se).build(this,r).setData(o,{...n,manual:!0})}setQueriesData(e,t,n){return ue.batch(()=>l(this,se).findAll(e).map(({queryKey:r})=>[r,this.setQueryData(r,t,n)]))}getQueryState(e){var n;const t=this.defaultQueryOptions({queryKey:e});return(n=l(this,se).get(t.queryHash))==null?void 0:n.state}removeQueries(e){const t=l(this,se);ue.batch(()=>{t.findAll(e).forEach(n=>{t.remove(n)})})}resetQueries(e,t){const n=l(this,se);return ue.batch(()=>(n.findAll(e).forEach(r=>{r.reset()}),this.refetchQueries({type:"active",...e},t)))}cancelQueries(e,t={}){const n={revert:!0,...t},r=ue.batch(()=>l(this,se).findAll(e).map(s=>s.cancel(n)));return Promise.all(r).then(be).catch(be)}invalidateQueries(e,t={}){return ue.batch(()=>(l(this,se).findAll(e).forEach(n=>{n.invalidate()}),(e==null?void 0:e.refetchType)==="none"?Promise.resolve():this.refetchQueries({...e,type:(e==null?void 0:e.refetchType)??(e==null?void 0:e.type)??"active"},t)))}refetchQueries(e,t={}){const n={...t,cancelRefetch:t.cancelRefetch??!0},r=ue.batch(()=>l(this,se).findAll(e).filter(s=>!s.isDisabled()&&!s.isStatic()).map(s=>{let i=s.fetch(void 0,n);return n.throwOnError||(i=i.catch(be)),s.state.fetchStatus==="paused"?Promise.resolve():i}));return Promise.all(r).then(be)}fetchQuery(e){const t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);const n=l(this,se).build(this,t);return n.isStaleByTime(st(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(be).catch(be)}fetchInfiniteQuery(e){return e.behavior=gs(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(be).catch(be)}ensureInfiniteQueryData(e){return e.behavior=gs(e.pages),this.ensureQueryData(e)}resumePausedMutations(){return Sn.isOnline()?l(this,lt).resumePausedMutations():Promise.resolve()}getQueryCache(){return l(this,se)}getMutationCache(){return l(this,lt)}getDefaultOptions(){return l(this,ft)}setDefaultOptions(e){_(this,ft,e)}setQueryDefaults(e,t){l(this,Vt).set(Ct(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...l(this,Vt).values()],n={};return t.forEach(r=>{tn(e,r.queryKey)&&Object.assign(n,r.defaultOptions)}),n}setMutationDefaults(e,t){l(this,Gt).set(Ct(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...l(this,Gt).values()],n={};return t.forEach(r=>{tn(e,r.mutationKey)&&Object.assign(n,r.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;const t={...l(this,ft).queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=rr(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.queryFn===xn&&(t.enabled=!1),t}defaultMutationOptions(e){return e!=null&&e._defaulted?e:{...l(this,ft).mutations,...(e==null?void 0:e.mutationKey)&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){l(this,se).clear(),l(this,lt).clear()}},se=new WeakMap,lt=new WeakMap,ft=new WeakMap,Vt=new WeakMap,Gt=new WeakMap,ht=new WeakMap,Xt=new WeakMap,Zt=new WeakMap,Ks),bs=ce.createContext(void 0),fr=e=>{const t=ce.useContext(bs);if(!t)throw new Error("No QueryClient set, use QueryClientProvider to set one");return t},co=({client:e,children:t})=>(ce.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),H.jsx(bs.Provider,{value:e,children:t})),Ts=ce.createContext(!1),uo=()=>ce.useContext(Ts);Ts.Provider;function lo(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var fo=ce.createContext(lo()),ho=()=>ce.useContext(fo),po=(e,t)=>{(e.suspense||e.throwOnError||e.experimental_prefetchInRender)&&(t.isReset()||(e.retryOnMount=!1))},mo=e=>{ce.useEffect(()=>{e.clearReset()},[e])},yo=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:s})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(s&&e.data===void 0||cs(n,[e.error,r])),go=e=>{if(e.suspense){const n=s=>s==="static"?s:Math.max(s??1e3,1e3),r=e.staleTime;e.staleTime=typeof r=="function"?(...s)=>n(r(...s)):n(r),typeof e.gcTime=="number"&&(e.gcTime=Math.max(e.gcTime,1e3))}},Ao=(e,t)=>e.isLoading&&e.isFetching&&!t,Eo=(e,t)=>(e==null?void 0:e.suspense)&&t.isPending,ws=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function bo(e,t,n){var E,x,v,O,I;if(process.env.NODE_ENV!=="production"&&(typeof e!="object"||Array.isArray(e)))throw new Error('Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object');const r=uo(),s=ho(),i=fr(),o=i.defaultQueryOptions(e);(x=(E=i.getDefaultOptions().queries)==null?void 0:E._experimental_beforeQuery)==null||x.call(E,o),process.env.NODE_ENV!=="production"&&(o.queryFn||console.error(`[${o.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`)),o._optimisticResults=r?"isRestoring":"optimistic",go(o),po(o,s),mo(s);const d=!i.getQueryCache().get(o.queryHash),[h]=ce.useState(()=>new t(i,o)),f=h.getOptimisticResult(o),C=!r&&e.subscribed!==!1;if(ce.useSyncExternalStore(ce.useCallback(k=>{const B=C?h.subscribe(ue.batchCalls(k)):be;return h.updateResult(),B},[h,C]),()=>h.getCurrentResult(),()=>h.getCurrentResult()),ce.useEffect(()=>{h.setOptions(o)},[o,h]),Eo(o,f))throw ws(o,h,s);if(yo({result:f,errorResetBoundary:s,throwOnError:o.throwOnError,query:i.getQueryCache().get(o.queryHash),suspense:o.suspense}))throw f.error;if((O=(v=i.getDefaultOptions().queries)==null?void 0:v._experimental_afterQuery)==null||O.call(v,o,f),o.experimental_prefetchInRender&&!wt&&Ao(f,r)){const k=d?ws(o,h,s):(I=i.getQueryCache().get(o.queryHash))==null?void 0:I.promise;k==null||k.catch(be).finally(()=>{h.updateResult()})}return o.notifyOnChangeProps?f:h.trackResult(f)}function To(e,t){return bo(e,Ja)}function it(e,t){const n=fr(),[r]=ce.useState(()=>new io(n,e));ce.useEffect(()=>{r.setOptions(e)},[r,e]);const s=ce.useSyncExternalStore(ce.useCallback(o=>r.subscribe(ue.batchCalls(o)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),i=ce.useCallback((o,d)=>{r.mutate(o,d).catch(be)},[r]);if(s.error&&cs(r.options.throwOnError,[s.error]))throw s.error;return{...s,mutate:i,mutateAsync:s.mutate}}const nn=()=>{const e=Q(i=>i.state.swapExecutionIndex),t=Q(i=>i.state.swapExecutions[i.state.swapExecutionIndex]??{}),n=Q(i=>i.updateSwapExecutionAtIndex),r=Q(i=>i.resetSwapExecutionAtIndex),s=F.useCallback(i=>n(e,i),[n,e]);return F.useMemo(()=>({...t,update:s,resetSwap:r}),[t,s,r])},wo=2e4,Co=()=>{const{module:e}=q(),t=Q(n=>n.state.isMarketOrder);return F.useMemo(()=>e===z.TWAP?t?V.TWAP_MARKET:V.TWAP_LIMIT:e===z.LIMIT?V.LIMIT:e===z.STOP_LOSS?t?V.STOP_LOSS_MARKET:V.STOP_LOSS_LIMIT:e===z.TAKE_PROFIT?t?V.TAKE_PROFIT_MARKET:V.TAKE_PROFIT_LIMIT:V.TWAP_MARKET,[e,t])},Cs=()=>{const{account:e,config:t,chainId:n,isDev:r}=q();return F.useMemo(()=>["useTwapOrderHistoryManager",e,t==null?void 0:t.adapter,t==null?void 0:t.partner,n,r],[e,t,n,r])},xo=()=>{const{callbacks:e}=q(),t=fr(),n=Cs();return F.useCallback(r=>{var d;const s=t.getQueryData(n);let i=!1;const o=[];s&&s.filter(h=>h.version===2).forEach(h=>{var C;const f=r.find(E=>E.id===h.id);f&&f.progress!==h.progress&&(i=!0,o.push(f),f.status===pe.Completed&&((C=e==null?void 0:e.onOrderFilled)==null||C.call(e,f)))}),i&&((d=e==null?void 0:e.onOrdersProgressUpdate)==null||d.call(e,o))},[t,n,e])},hr=()=>{const{account:e,config:t,chainId:n,isDev:r}=q(),s=Cs(),i=xo();return To({refetchInterval:wo,refetchOnWindowFocus:!0,retry:!1,staleTime:1/0,queryKey:s,queryFn:async({signal:d})=>{if(!e||!n||!t)return[];const h=await la({signal:d,chainId:n,config:t,account:e,isDev:r});return i(h),h.map(f=>t!=null&&t.twapConfig?{...f,fillDelayMillis:qn(f,t.twapConfig)}:f)}})},So=(e,t,n)=>F.useMemo(()=>{if(!(!e||!t||!n||n!=null&&n.isMarketPrice))return Rr(n,e==null?void 0:e.decimals,t==null?void 0:t.decimals)},[n,e,t]),vo=(e,t,n)=>F.useMemo(()=>{if(!(!e||!t||!n))return Lr(n,e.decimals,t.decimals)},[n,e,t]),Fo=(e,t,n)=>F.useMemo(()=>{if(!(!e||!t||!n))return Kn(n.srcAmountFilled,n.dstAmountFilled,e.decimals,t.decimals)},[n,e,t]),Fn=(e,t)=>[...e.filter(r=>r.status===t)].sort((r,s)=>s.createdAt-r.createdAt),Po=()=>{const{data:e,isLoading:t,refetch:n,isRefetching:r}=hr(),s=F.useCallback(()=>n().then(i=>i.data),[n]);return F.useMemo(()=>({orders:{all:e??[],open:Fn(e??[],pe.Open),completed:Fn(e??[],pe.Completed),cancelled:Fn(e??[],pe.Cancelled),expired:Fn(e??[],pe.Expired)},isLoading:t,isRefetching:r,refetchOrders:s}),[e,t,r,s])},pr=()=>{const e=Q(n=>n.state.currentTime),t=Jn().duration;return F.useMemo(()=>Si(e,t),[e,t])},xs=()=>{const{srcToken:e,dstToken:t,account:n,chainId:r,slippage:s,config:i,module:o,fees:d}=q(),{amount:h}=rt(),{amountPerTrade:f,totalTrades:C}=qe(),E=pr(),{amount:x}=tr(),{pricePerChunk:v}=bt(),{milliseconds:O}=Lt();return F.useMemo(()=>{var I;return Kr({chainId:r,srcToken:Ut((e==null?void 0:e.address)||"")?((I=At(r))==null?void 0:I.wToken.address)||"":(e==null?void 0:e.address)||"",dstToken:(t==null?void 0:t.address)||"",srcAmount:h,deadlineMillis:E,fillDelayMillis:!C||C===1?0:O,slippage:s*100,account:n,srcAmountPerTrade:f,dstMinAmountPerTrade:x,triggerAmountPerTrade:v,config:i,module:o})},[e,t,n,r,s,i,o,h,f,C,O,x,v,d])};function Do(e){const t=e.slice(2);if(t.length===128){const i=`0x${t.slice(0,64)}`,o=parseInt(t.charAt(64),16),d=(o>>3)+27,h=`0x${(o&7).toString(16)}${t.slice(65,128)}`;return{r:i,s:h,v:d}}const n=`0x${t.slice(0,64)}`,r=`0x${t.slice(64,128)}`,s=parseInt(t.slice(128,130),16);return{r:n,s:r,v:s}}const Oo=()=>{var i;const{account:e,walletInteractions:t,callbacks:n,chainId:r}=q(),s=(i=En())==null?void 0:i.wToken;return it({mutationFn:async({onHash:o,srcAmountWei:d})=>{var f,C;if(!e)throw new Error("missing account");if(!t)throw new Error("missing walletInteractions");if(!s)throw new Error("tokenAddress is not defined");fe.onWrapRequest();const h=await t.wrapNativeToken(d);return(f=n==null?void 0:n.onWrapRequest)==null||f.call(n),o==null||o(h),fe.onWrapSuccess(h),(C=n==null?void 0:n.onWrapSuccess)==null||C.call(n,{txHash:h,explorerUrl:Rt(h,r),amount:Ee(d,s.decimals)}),h},onError:o=>{throw fe.onWrapError(o),o}})},Ss=()=>{const{account:e,walletInteractions:t,chainId:n,callbacks:r,isDev:s}=q(),i=xs(),{refetch:o}=hr();return it({mutationFn:async()=>{var I,k,B,P;if(!e)throw new Error("missing account");if(!t)throw new Error("missing walletInteractions");if(!n)throw new Error("missing chainId");const{order:d,domain:h,types:f,primaryType:C}=i;fe.onSignOrderRequest(d);let E;try{E=await t.signOrder({domain:h,types:f,primaryType:C,message:d,account:e})}catch(K){throw(I=r==null?void 0:r.onSignOrderError)==null||I.call(r,K),fe.onSignOrderError(K),K}fe.onSignOrderSuccess(E),(k=r==null?void 0:r.onSignOrderSuccess)==null||k.call(r,E);const x=Do(E),v={v:`0x${x.v.toString(16)}`,r:x.r,s:x.s};(B=r==null?void 0:r.onSignOrderRequest)==null||B.call(r);const O=await Qr(d,v,s);return(P=r==null?void 0:r.onOrderCreated)==null||P.call(r,O),await o(),O}})},vs=()=>{const{account:e,walletInteractions:t,config:n}=q();return it({mutationFn:async({tokenAddress:r,srcAmountWei:s})=>{if(!t)throw new Error("missing walletInteractions");if(!e)throw new Error("missing account");if(!n)throw new Error("missing config");const i=await t.getAllowance({tokenAddress:r,spenderAddress:n.repermit}),o=S(i||"0").lt(S(s).toString());return{allowance:i,approvalRequired:o}}})},Io=()=>{const{account:e,walletInteractions:t,config:n,chainId:r,callbacks:s}=q(),{mutateAsync:i}=vs();return it({onError:o=>{fe.onApproveError(o)},mutationFn:async({token:o,onHash:d,srcAmountWei:h})=>{var E,x;if(!e)throw new Error("missing account");if(!t)throw new Error("missing walletInteractions");if(!n)throw new Error("missing config");fe.onApproveRequest();const f=await t.approveToken({tokenAddress:o.address,amount:h,spenderAddress:n.repermit});if(!f)throw new Error("failed to approve token");(E=s==null?void 0:s.onApproveRequest)==null||E.call(s),d(f);let C=!1;for(let v=0;v<3;v++){const{approvalRequired:O}=await i({tokenAddress:o.address,srcAmountWei:h});if(!O){C=!0;break}v<2&&await new Promise(I=>setTimeout(I,3e3))}if(!C)throw new Error(`Insufficient ${o.symbol} allowance to perform the swap. Please approve the token first.`);return fe.onApproveSuccess(f),(x=s==null?void 0:s.onApproveSuccess)==null||x.call(s,{txHash:f,explorerUrl:Rt(f,r),token:o,amount:Ee(h,o.decimals)}),f}})},Mo=()=>{const{account:e,chainId:t,srcToken:n,dstToken:r,module:s,slippage:i}=q(),o=bt(),d=rt().amount,h=qe().amountPerTrade,f=pr(),C=qe().totalTrades,E=Lt().fillDelay,x=tr().amount,v=Q(O=>O.state.isMarketOrder);return it({mutationFn:async()=>{fe.onRequestOrder({account:e,chainId:t,module:s,srcToken:n,dstToken:r,fromTokenAmount:d,srcChunkAmount:h,triggerPricePerTrade:o.pricePerChunk,deadline:f,fillDelay:E.unit*E.value,minDstAmountOutPerTrade:x,slippage:i,isMarketOrder:v||!1,chunksAmount:C})}})};function ko(e){const t=e.message,n=t.match(/,\s*code\s*:\s*(\d+)/i);return{message:t.replace(/^error\s*:/i,"").replace(/,\s*code\s*:\s*\d+/i,"").trim()||"",code:n?Number(n[1]):0}}const Fs=()=>{const{srcToken:e,dstToken:t,chainId:n,callbacks:r,marketPrice:s}=q(),i=Io().mutateAsync,o=Oo().mutateAsync,d=Ss().mutateAsync,{mutateAsync:h}=vs(),{update:f}=nn(),{amount:C}=rt(),E=Mo().mutate;return it({mutationFn:async()=>{var v,O;const x=Ut((e==null?void 0:e.address)||" ");try{if(!e)throw new Error("missing srcToken");if(!t)throw new Error("missing dstToken");if(!n)throw new Error("missing chainId");const I=Zr(e,n);f({allowanceLoading:!0,wrapTxHash:void 0,approveTxHash:void 0,acceptedMarketPrice:s,acceptedSrcAmount:C,srcToken:e,dstToken:t,pendingSteps:[]});const{approvalRequired:k}=await h({tokenAddress:I.address,srcAmountWei:C});let B=0,P=1;x&&P++,k&&P++,f({totalSteps:P,stepIndex:B,allowanceLoading:!1,hasApproval:!k,status:Se.LOADING}),E();let K=[];x&&K.push(tt.WRAP),k&&K.push(tt.APPROVE),K.push(tt.CREATE),f({pendingSteps:K}),x&&(f({step:tt.WRAP}),await o({onHash:Z=>f({wrapTxHash:Z}),srcAmountWei:C}),B++,f({stepIndex:B})),k&&(f({step:tt.APPROVE}),await i({token:I,onHash:Z=>f({approveTxHash:Z}),srcAmountWei:C}),B++,f({stepIndex:B})),f({step:tt.CREATE});const U=await d();return f({status:Se.SUCCESS,orderId:U.id}),U}catch(I){if(Vn(I))(v=r==null?void 0:r.onSubmitOrderRejected)==null||v.call(r),f({step:void 0,status:void 0,stepIndex:void 0,error:I});else{const k=ko(I);(O=r==null?void 0:r.onSubmitOrderFailed)==null||O.call(r,k),f({status:Se.FAILED,parsedError:k,error:I})}throw I}}})},_o=()=>{const e=nn(),{srcToken:t,dstToken:n}=q(),r=Fs(),s=Q(f=>f.resetState),i=F.useCallback(()=>r.mutateAsync(),[r]),{update:o,resetSwap:d,...h}=e;return F.useMemo(()=>({status:h.status,parsedError:h.parsedError,error:h.error,step:h.step,stepIndex:h.stepIndex,approveTxHash:h.approveTxHash,wrapTxHash:h.wrapTxHash,totalSteps:h.totalSteps,pendingSteps:h.pendingSteps,srcToken:t,dstToken:n,onSubmit:i,resetState:s,resetCurrentSwap:d,isLoading:(e==null?void 0:e.status)===Se.LOADING,isSuccess:(e==null?void 0:e.status)===Se.SUCCESS,isFailed:(e==null?void 0:e.status)===Se.FAILED,confirmButtonLoading:h.allowanceLoading}),[i,h,s,d,t,n])},Bo=()=>{const{marketPrice:e,srcToken:t,dstToken:n,marketPriceLoading:r,srcBalance:s,srcUsd1Token:i,noLiquidity:o,typedInputAmount:d}=q(),h=r||S(i||"0").isZero()||s===void 0||S(e||"0").isZero(),f=!!(t&&n&&d&&h),E=!!(ts()||o||f||S(d||"0").isZero()||!t||!n);return F.useMemo(()=>({disabled:E,loading:f}),[E,f])},Uo=()=>{const{srcUsd1Token:e,dstUsd1Token:t}=q(),n=rt().amountUI,r=wn().amountUI,s=nt(n,e),i=nt(r,t);return{srcAmountUsd:s,dstAmountUsd:i}},Ro=()=>{const{fees:e,dstToken:t,dstUsd1Token:n}=q(),{amountUI:r}=wn(),s=F.useMemo(()=>!e||!r?"":S(r).multipliedBy(e).dividedBy(100).toFixed(),[r,e]),i=Yn((t==null?void 0:t.decimals)||0,s);return{amountUI:s,amount:i,percent:e,usd:nt(s,n)}},Lo=e=>{const t=F.useMemo(()=>!e.minDestAmountPerTrade||!e.totalTrades?"":S(e.minDestAmountPerTrade).multipliedBy(e.totalTrades).decimalPlaces(0).toFixed(),[e.minDestAmountPerTrade,e.totalTrades]),n=F.useMemo(()=>!e.minDestAmountPerTradeUI||!e.totalTrades?"":S(e.minDestAmountPerTradeUI).multipliedBy(e.totalTrades).toFixed(),[e.minDestAmountPerTradeUI,e.totalTrades]),r=F.useMemo(()=>!e.minDestAmountPerTradeUsd||!e.totalTrades?"":S(e.minDestAmountPerTradeUsd).multipliedBy(e.totalTrades).decimalPlaces(2).toFixed(),[e.minDestAmountPerTradeUsd,e.totalTrades]);return F.useMemo(()=>({srcToken:e.srcToken,dstToken:e.dstToken,orderType:e.orderType,createdAt:e.createdAt||0,deadline:e.deadline||0,totalTrades:e.totalTrades||0,tradeInterval:e.tradeInterval||0,recipient:e.account||"",srcAmount:e.srcAmount||"",srcAmountUI:e.srcAmountUI||"",srcAmountUsd:e.srcAmountUsd||"",dstAmount:e.dstAmount||"",dstAmountUI:e.dstAmountUI||"",dstAmountUsd:e.dstAmountUsd||"",limitPrice:e.limitPrice||"",limitPriceUI:e.limitPriceUI||"",limitPriceUsd:e.limitPriceUsd||"",sizePerTrade:e.srcAmountPerTrade||"",sizePerTradeUI:e.srcAmountPerTradeUI||"",sizePerTradeUsd:e.srcAmountPerTradeUsd,minDestAmountPerTrade:e.minDestAmountPerTrade||"",minDestAmountPerTradeUI:e.minDestAmountPerTradeUI||"",minDestAmountPerTradeUsd:e.minDestAmountPerTradeUsd,dstMinAmount:t,dstMinAmountUI:n,dstMinAmountUsd:r,triggerPrice:e.triggerPrice||"",triggerPriceUI:e.triggerPriceUI||"",triggerPriceUsd:e.triggerPriceUsd}),[e.srcToken,e.dstToken,e.orderType,e.createdAt,e.deadline,e.totalTrades,e.tradeInterval,e.account,e.srcAmount,e.srcAmountUI,e.srcAmountUsd,e.dstAmount,e.dstAmountUI,e.dstAmountUsd,e.limitPrice,e.limitPriceUI,e.limitPriceUsd,e.srcAmountPerTrade,e.srcAmountPerTradeUI,e.srcAmountPerTradeUsd,e.minDestAmountPerTrade,e.minDestAmountPerTradeUI,e.minDestAmountPerTradeUsd,t,n,r,e.triggerPrice,e.triggerPriceUI,e.triggerPriceUsd])},No=()=>{const{config:e}=q();return F.useMemo(()=>({spender:e.repermit}),[e])},qo=()=>{const{srcToken:e,dstToken:t,account:n,marketPrice:r}=q(),{spender:s}=No(),{amount:i}=rt(),{amount:o,amountUI:d,usd:h}=Tn(),{amountPerTrade:f,amountPerTradeUI:C,amountPerTradeUsd:E,totalTrades:x}=qe(),v=pr(),{amount:O,amountUI:I,usd:k}=tr(),{amountUI:B,amount:P,usd:K}=bt(),{milliseconds:U}=Lt(),{amount:Z,amountUI:Y}=wn(),{srcAmountUsd:oe,dstAmountUsd:a}=Uo(),{amount:c,amountUI:u,percent:A,usd:m}=Ro(),y=xs(),w=Q(G=>G.state.isMarketOrder),p=Q(G=>G.state.currentTime),g=nn(),T=Co(),b=g.acceptedSrcAmount||i,D=Ee(r,(t==null?void 0:t.decimals)||0),R=F.useMemo(()=>T===V.TAKE_PROFIT_MARKET||T===V.TAKE_PROFIT_LIMIT||T===V.STOP_LOSS_LIMIT||T===V.STOP_LOSS_MARKET,[T]),L=Lo({srcToken:e,dstToken:t,account:n,orderType:T,createdAt:p,deadline:v,totalTrades:x,tradeInterval:U,srcAmount:b,srcAmountUI:Ee(b,(e==null?void 0:e.decimals)||0),srcAmountUsd:oe,dstAmount:Z,dstAmountUI:Y,dstAmountUsd:a,limitPrice:w?void 0:o,limitPriceUI:w?void 0:d,limitPriceUsd:w?void 0:h,srcAmountPerTrade:f,srcAmountPerTradeUI:C,srcAmountPerTradeUsd:E,minDestAmountPerTrade:O,minDestAmountPerTradeUI:I,minDestAmountPerTradeUsd:k,triggerPrice:P,triggerPriceUI:B,triggerPriceUsd:K});return F.useMemo(()=>({...L,feesAmountUI:u,feesAmount:c,feesUsd:m||"",feesPercentage:A,rePermitData:y,isTriggerPrice:R,isMarketOrder:w,marketPrice:r,marketPriceUi:D,spender:s}),[L,u,c,m,A,y,R,w,r,D,s])},Ko=()=>{const{supportedChains:e}=q();return F.useMemo(()=>e,[e])},Ho=60,Ps=()=>{const{refetch:e}=hr();return it({mutationFn:async t=>{var n;for(let r=0;r<Ho;r++){const s=(n=await e())==null?void 0:n.data;if(!s)throw new Error("orders not found");const i=s.find(o=>o.id===t);if((i==null?void 0:i.status)===pe.Cancelled)return;await new Promise(o=>setTimeout(o,1e3))}throw new Error("Timed out waiting for order cancellation to be confirmed")}})},Wo=()=>{const e=Q(n=>n.updateState),t=Q(n=>n.state.cancelOrders);return{cancelOrders:t,setCancelOrder:(n,r)=>{e({cancelOrders:{...t,[n]:r}})},clearCancelOrder:n=>{const{[n]:r,...s}=t;e({cancelOrders:s})}}},Qo=e=>{const{account:t,walletInteractions:n,config:r,callbacks:s,chainId:i}=q(),o=Ps().mutateAsync,{cancelOrders:d,setCancelOrder:h,clearCancelOrder:f}=Wo(),{mutateAsync:C}=it({mutationFn:async()=>{var O,I,k;if(!t||!n||!r)throw new Error("missing required parameters");if(!e)throw new Error("order is required");const v=e.id;try{(O=s==null?void 0:s.onCancelOrderRequest)==null||O.call(s,e),h(v,{status:Se.LOADING}),fe.onCancelOrderRequest([e.version===1?e.id.toString():e.hash],e.version);const B=await n.cancelOrder({order:e,contractAddress:e.version===1?e.twapAddress:r.repermit,args:e.version===1?[e.id]:[[e.repermitDigest]],abi:e.version===1?js:$s});if(!B)throw new Error("failed to cancel order");return fe.onCancelOrderSuccess(B),await o(e.id),(I=s==null?void 0:s.onCancelOrderSuccess)==null||I.call(s,{order:e,txHash:B,explorerUrl:Rt(B,i)}),h(v,{status:Se.SUCCESS,txHash:B}),B}catch(B){console.error("cancel order error",B),(k=s==null?void 0:s.onCancelOrderFailed)==null||k.call(s,B),Vn(B)?f(v):(h(v,{status:Se.FAILED,error:B.message}),fe.onCancelOrderError(B))}}}),E=F.useMemo(()=>{const v=d[(e==null?void 0:e.id)||""];return{isLoading:(v==null?void 0:v.status)===Se.LOADING,isSuccess:(v==null?void 0:v.status)===Se.SUCCESS,isError:(v==null?void 0:v.status)===Se.FAILED,error:v==null?void 0:v.error,txHash:v==null?void 0:v.txHash}},[d,e==null?void 0:e.id]),x=F.useCallback(async()=>C(),[C]);return F.useMemo(()=>({cancelOrder:x,...E}),[x,E])},Ds=F.createContext(null),$o=({children:e})=>{const t=xa(),n=Pa(),r=va(),s=_a(),i=Ba(),o=bn(),d=Ua(),h=Ra(),f=ts(),C=Bo(),E=qo(),x=Po(),v=_o(),O=Ko(),I=Ps(),{module:k}=q(),B={tradesAmountPanel:t,durationPanel:n,fillDelayPanel:r,limitPricePanel:s,triggerPricePanel:i,pricePanel:o,dstTokenPanel:d,disclaimerPanel:h,inputError:f,submitOrderButton:C,derivedFormData:E,orderHistoryPanel:x,orderExecutionPanel:v,supportedChains:O,refetchUntilStatusSynced:I,module:k};return H.jsx(Ds.Provider,{value:B,children:e})},jo=()=>{const e=F.useContext(Ds);if(e===null)throw new Error("useSpot must be used within SpotProvider");return e},zo=F.createContext(null),mr={didCatch:!1,error:null};class Vo extends F.Component{constructor(t){super(t),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=mr}static getDerivedStateFromError(t){return{didCatch:!0,error:t}}resetErrorBoundary(){const{error:t}=this.state;if(t!==null){for(var n,r,s=arguments.length,i=new Array(s),o=0;o<s;o++)i[o]=arguments[o];(n=(r=this.props).onReset)===null||n===void 0||n.call(r,{args:i,reason:"imperative-api"}),this.setState(mr)}}componentDidCatch(t,n){var r,s;(r=(s=this.props).onError)===null||r===void 0||r.call(s,t,n)}componentDidUpdate(t,n){const{didCatch:r}=this.state,{resetKeys:s}=this.props;if(r&&n.error!==null&&Go(t.resetKeys,s)){var i,o;(i=(o=this.props).onReset)===null||i===void 0||i.call(o,{next:s,prev:t.resetKeys,reason:"keys"}),this.setState(mr)}}render(){const{children:t,fallbackRender:n,FallbackComponent:r,fallback:s}=this.props,{didCatch:i,error:o}=this.state;let d=t;if(i){const h={error:o,resetErrorBoundary:this.resetErrorBoundary};if(typeof n=="function")d=n(h);else if(r)d=F.createElement(r,h);else if(s!==void 0)d=s;else throw o}return F.createElement(zo.Provider,{value:{didCatch:i,error:o,resetErrorBoundary:this.resetErrorBoundary}},d)}}function Go(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[];return e.length!==t.length||e.some((n,r)=>!Object.is(n,t[r]))}const Xo=()=>H.jsx("div",{className:"twap-error-fallback",children:H.jsx("p",{style:{fontSize:20,fontWeight:600,textAlign:"center",width:"100%",marginTop:40},children:"Something went wrong"})});function Zo({children:e}){return H.jsx(Vo,{FallbackComponent:Xo,onError:t=>fe.onCrash(t),children:H.jsx(H.Fragment,{children:e})})}const Os=F.createContext(null),Yo=new oo({defaultOptions:{queries:{refetchOnWindowFocus:!1}}}),Jo=e=>{var r,s,i;const t=Q(o=>o.updateState),n=Q(o=>o.state.isMarketOrder);return F.useEffect(()=>{const o=setInterval(()=>{t({currentTime:Date.now()})},6e4);return()=>clearInterval(o)},[t]),F.useEffect(()=>{var d,h,f,C,E,x,v,O,I,k,B,P,K,U,Z,Y;const o=(h=(d=e.overrides)==null?void 0:d.state)==null?void 0:h.isMarketOrder;o!==void 0&&t({isMarketOrder:o}),t({typedChunks:(C=(f=e.overrides)==null?void 0:f.state)==null?void 0:C.chunks,typedFillDelay:(x=(E=e.overrides)==null?void 0:E.state)==null?void 0:x.fillDelay,typedDuration:(O=(v=e.overrides)==null?void 0:v.state)==null?void 0:O.duration,typedLimitPrice:(k=(I=e.overrides)==null?void 0:I.state)==null?void 0:k.limitPrice,typedTriggerPrice:(P=(B=e.overrides)==null?void 0:B.state)==null?void 0:P.triggerPrice,triggerPricePercent:(U=(K=e.overrides)==null?void 0:K.state)==null?void 0:U.triggerPricePercent,limitPricePercent:(Y=(Z=e.overrides)==null?void 0:Z.state)==null?void 0:Y.limitPricePercent})},[(r=e.overrides)==null?void 0:r.state,e.module]),F.useEffect(()=>{var o,d,h,f;t({typedLimitPrice:(d=(o=e.overrides)==null?void 0:o.state)==null?void 0:d.limitPrice,typedTriggerPrice:(f=(h=e.overrides)==null?void 0:h.state)==null?void 0:f.triggerPrice,triggerPricePercent:void 0,limitPricePercent:void 0})},[(s=e.srcToken)==null?void 0:s.address,(i=e.dstToken)==null?void 0:i.address]),F.useEffect(()=>{e.module===z.LIMIT&&t({isMarketOrder:!1})},[e.module]),F.useEffect(()=>{n&&t({isInvertedTrade:!1})},[n]),F.useEffect(()=>{t({typedChunks:void 0})},[e.typedInputAmount]),null},ec=({marketReferencePrice:e,srcToken:t,dstToken:n,chainId:r,typedInputAmount:s})=>F.useMemo(()=>{if(Xn(t,n,r)||Zn(t,n,r))return{isLoading:!1,noLiquidity:!1,value:Et(s||"0",t==null?void 0:t.decimals)};if(S(e.value||0).isZero()||S(s||0).isZero())return e;const i=S(e.value||0).dividedBy(s||0).decimalPlaces(0).toFixed();return{...e,value:i}},[e,s,t,n,r]),tc=e=>{const t=nn(),n=F.useMemo(()=>Ur(e.partner),[e.partner]),r=F.useMemo(()=>{const d=n[0];return e.chainId&&n.includes(e.chainId)?e.chainId:d},[e.chainId,n]),s=F.useMemo(()=>Hn(e.partner,r),[e.partner,r]),i=ec(e),o=F.useMemo(()=>qr(e.minChunkSizeUsd),[e.minChunkSizeUsd]);return F.useEffect(()=>{fe.init(s,o,r)},[s,r,o]),H.jsxs(Os.Provider,{value:{typedInputAmount:e.typedInputAmount,minChunkSizeUsd:o,account:e.account,walletInteractions:e.walletInteractions,marketPrice:t.acceptedMarketPrice||i.value,marketPriceLoading:!t.acceptedMarketPrice&&i.isLoading,noLiquidity:!t.acceptedMarketPrice&&i.noLiquidity,config:s,slippage:e.priceProtection,supportedChains:n,chainId:r,partner:e.partner,module:e.module,fees:e.fees||0,overrides:e.overrides,callbacks:e.callbacks,srcUsd1Token:e.srcUsd1Token,dstUsd1Token:e.dstUsd1Token,srcBalance:e.srcBalance,dstBalance:e.dstBalance,srcToken:t.srcToken||e.srcToken,dstToken:t.dstToken||e.dstToken,isDev:e.isDev},children:[H.jsx(Jo,{...e}),H.jsx($o,{children:H.jsx(Zo,{children:e.children})})]})},nc=e=>H.jsx(co,{client:Yo,children:H.jsx(tc,{...e})}),q=()=>{const e=F.useContext(Os);if(e===null)throw new Error("useSpotContext must be used within SpotProvider");return e},rc=(e,t,n)=>{const r=En();return F.useMemo(()=>e==null?void 0:e.map(s=>({rawFill:s,srcToken:t,dstToken:n,srcAmount:Ee(s.inAmount,t==null?void 0:t.decimals),dstAmount:Ee(s.outAmount,n==null?void 0:n.decimals),timestamp:s.timestamp,txHash:s.txHash,explorerUrl:Rt(s.txHash,r==null?void 0:r.id),executionRate:Kn(s.inAmount,s.outAmount,t==null?void 0:t.decimals,n==null?void 0:n.decimals)})).filter(s=>s.srcToken!==void 0&&s.dstToken!==void 0),[e,t,n,r])},sc=(e,t,n)=>{const{config:r}=q(),s=So(t,n,e),i=vo(t,n,e),o=Fo(t,n,e),d=F.useMemo(()=>e?e.version===2?e.fillDelay:r.twapConfig?qn(e,r.twapConfig):0:0,[e,r]),h=rc(e==null?void 0:e.fills,t,n)??[];return F.useMemo(()=>{if(e!=null&&e.id)return{original:e,fills:h,srcToken:t,dstToken:n,orderType:e.type,createdAt:e.createdAt,deadline:e.deadline||0,totalTrades:e.totalTradesAmount||0,tradeInterval:d,recipient:e.maker||"",srcAmount:e.srcAmount||"",srcAmountUI:Ee(e.srcAmount,t==null?void 0:t.decimals),limitPrice:Et(s,n==null?void 0:n.decimals),limitPriceUI:s||"",sizePerTrade:e.srcAmountPerTrade||"",sizePerTradeUI:Ee(e.srcAmountPerTrade,t==null?void 0:t.decimals),minDestAmountPerTrade:e.dstMinAmountPerTrade||"",minDestAmountPerTradeUI:Ee(e.dstMinAmountPerTrade,n==null?void 0:n.decimals),dstMinAmount:e.dstMinAmountTotal,dstMinAmountUI:Ee(e.dstMinAmountTotal,n==null?void 0:n.decimals),triggerPrice:Et(i,n==null?void 0:n.decimals),triggerPriceUI:i||"",id:e.id,amountInFilled:e.srcAmountFilled,amountInFilledUI:Ee(e.srcAmountFilled,t==null?void 0:t.decimals),amountOutFilled:e.dstAmountFilled,amountOutFilledUI:Ee(e.dstAmountFilled,n==null?void 0:n.decimals),progress:e.progress,executionPrice:Et(o,n==null?void 0:n.decimals),executionPriceUI:o,version:e.version}},[e,h,t,n,d,s,i,o])};Hi(fa.version),M.DISCLAIMER_URL=oi,M.Disclaimer=Jt,M.InputErrors=me,M.Module=z,M.ORBS_LOGO=ii,M.ORBS_SLTP_FAQ_URL=si,M.ORBS_TWAP_FAQ_URL=ri,M.ORBS_WEBSITE_URL=ai,M.OrderFilter=Fr,M.OrderStatus=pe,M.OrderType=V,M.Partners=Be,M.SPOT_VERSION=fn,M.SpotProvider=nc,M.Steps=tt,M.SwapStatus=Se,M.TimeUnit=Pe,M.buildRePermitOrderData=Kr,M.ensureWrappedToken=Zr,M.eqIgnoreCase=yt,M.getConfig=Hn,M.getExplorerUrl=Rt,M.getMinChunkSizeUsd=qr,M.getNetwork=At,M.getOrderExecutionRate=Kn,M.getOrderFillDelayMillis=qn,M.getOrderLimitPriceRate=Rr,M.getOrderType=Aa,M.getPartnerChains=Ur,M.getPartners=Nr,M.getTriggerPriceRate=Lr,M.isNativeAddress=Ut,M.isTxRejected=Vn,M.millisToDays=Gn,M.millisToMinutes=An,M.networks=ye,M.parseError=ga,M.shouldUnwrapOnly=Zn,M.shouldWrapOnly=Xn,M.submitOrder=Qr,M.toAmountUi=Ee,M.toAmountWei=Et,M.useAmountUi=en,M.useCancelOrder=Qo,M.useDerivedHistoryOrder=sc,M.useExplorerLink=Ea,M.useNetwork=En,M.useSignOrder=Ss,M.useSpot=jo,M.useSubmitOrder=Fs,M.useSwapExecution=nn,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})}));
|