1import{s as e}from"./rolldown-runtime-BcKkbAw3.js";import{Di as t,Zr as n,ca as r,dr as i,gi as a}from"./toasts-B1sjLLES.js";import{t as o}from"./react-CFeKwT_a.js";import{cn as s}from"./ccip-DvnbDvmz.js";import{a as c,o as l}from"./sepolia-DO5K04S7.js";import{a as u,d,n as f,s as p}from"./client-DGGzY1Zj.js";import{r as m}from"./wagmi-DMhpenA2.js";var h=e(o());async function g(e,t,n,r){n?.throwIfAborted();let i=await e(`/api/user/claim`,{method:`POST`,signal:n,headers:r?{"x-metalex-expected-did":r}:void 0});if(n?.throwIfAborted(),!i.ok)throw Error(`Could not confirm the wallet link. Please retry.`);let a=await i.json();if(n?.throwIfAborted(),r&&a.privyDid!==r)throw Error(`Your signed-in profile changed during linking. Please retry.`);if(a.conflicts?.some(e=>e.toLowerCase()===t.toLowerCase()))throw Error(`This wallet belongs to another MetaLeX profile. Sign out to use that profile, or resolve the conflict in Wallet Settings.`);if(!a.wallets?.some(e=>e.toLowerCase()===t.toLowerCase()))throw Error(`Wallet verification has not reached your profile yet. Please retry linking this wallet.`);return a}var _=class extends Error{constructor(){super(`An access token is required for this request`),this.name=`AccessTokenUnavailableError`}};async function v({getAccessToken:e,fetchImplementation:t=fetch,requireAccessToken:n=!1},r,i){let a=await e();if(!a&&n)throw new _;let o=new Headers(i?.headers);return a&&o.set(`authorization`,`Bearer ${a}`),t(r,{...i,headers:o})}var y=({requireAccessToken:e=!1}={})=>{let{getAccessToken:t}=u();return(0,h.useCallback)((n,r)=>v({getAccessToken:t,requireAccessToken:e},n,r),[t,e])};function b(){let e=p(),{linkWallet:r}=f(),a=y({requireAccessToken:!0}),o=t(),s=n(),[c,l]=(0,h.useState)(!1),u=(0,h.useRef)(null);return(0,h.useLayoutEffect)(()=>(l(!1),()=>{u.current?.abort(),u.current=null}),[e?.id]),{isLinking:c,linkWallet:async()=>{if(u.current||!e)return;let t=new AbortController;u.current=t,l(!0);try{let n=await r(t.signal);t.signal.throwIfAborted(),await g(a,n,t.signal,e.id),await o.invalidateQueries({queryKey:[`myProfile`]}),t.signal.throwIfAborted(),i(`Wallet linked`,`This wallet is now linked to your MetaLeX profile.`,{type:`success`})}catch(e){if(t.signal.aborted)return;i(`Wallet was not linked`,e instanceof Error?e.message:`Please try again.`,{type:`error`})}finally{u.current===t&&(u.current=null,l(!1),o.invalidateQueries({queryKey:[`myProfile`]}),s.refresh())}}}}var x=`/api/profile/me`,S=class extends Error{status;constructor(e){super(`My profile request failed (${e})`),this.name=`MyProfileRequestError`,this.status=e}},C=class extends Error{constructor(e){super(`Invalid my profile response: ${e}`),this.name=`InvalidMyProfileResponseError`}};function w(e){return e<1}function T(e){if(typeof e!=`string`)return!1;let t=new Date(e);return!Number.isNaN(t.getTime())&&t.toISOString()===e}function E(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`&&s(e))}function D(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw new C(`expected an object`);let n=e;if(typeof n.id!=`string`)throw new C(`missing identity id`);if(typeof n.privyDid!=`string`)throw new C(`missing Privy DID`);if(t&&n.privyDid!==t)throw new C(`Privy DID does not match request`);if(!T(n.createdAt)||!T(n.updatedAt))throw new C(`invalid profile timestamp`);if(n.migrationPromptDismissedAt!==null&&!T(n.migrationPromptDismissedAt))throw new C(`invalid migration timestamp`);if(n.account!==null&&(typeof n.account!=`string`||!s(n.account)))throw new C(`invalid primary address`);if(!E(n.conflicts)||!E(n.linkedAddresses))throw new C(`invalid linked addresses`)}function O(e,t){return D(e,t),{...e,migrationPromptDismissedAt:e.migrationPromptDismissedAt?new Date(e.migrationPromptDismissedAt):null,createdAt:new Date(e.createdAt),updatedAt:new Date(e.updatedAt)}}async function k(e,t,n){let r=await e(x,{cache:`no-store`,signal:n});if(!r.ok)throw new S(r.status);return O(await r.json(),t)}var A=e=>[`myProfile`,e];function j(){let e=p(),t=y({requireAccessToken:!0});return a({staleTime:l(5),gcTime:c(1),queryKey:e?[...A(e.id),d(e.linkedAccounts).sort().join(`,`)]:[],queryFn:e?({signal:n})=>k(t,e.id,n):r,enabled:!!e,retry:w})}function M(e,t){let{address:n}=m(),r=n?.toLowerCase();return r&&e?.includes(r)?r:t??e?.[0]??null}export{y as a,b as i,M as n,g as o,k as r,j as t};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.