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,IAAK,CAAA,oBAAA,CAAqB,aAAa,CAAA,EAAG,QAAQ,CAAA;AACzD,MAAA;AAAA;AAGF,IAAI,IAAA;AACF,MAAM,MAAA,EAAE,KAAM,EAAA,GAAI,MAAM,WAAA;AAAA,QACtB,aAAA;AAAA,QACA,GAAI,CAAA;AAAA,OACN;AACA,MAAA,IAAI,KAAO,EAAA;AACT,QAAA,OAAA,IAAW,IACT,IAAA,OAAA;AAAA,UACE,IAAI,MAAM,KAAK,CAAA;AAAA,UACf;AAAA,SACF;AAAA;AACJ,aACO,CAAG,EAAA;AACV,MAAW,OAAA,IAAA,IAAA,IAAQ,OAAQ,CAAA,CAAA,EAAY,yBAAyB,CAAA;AAChE,MAAA;AAAA;AAGF,IAAA,SAAA,IAAa,IACX,IAAA,SAAA;AAAA,MACE,CAAA,IAAA,EAAO,aAAc,CAAA,aAAa,CAAC,CAAA,qCAAA;AAAA,KACrC;AAAA,GACJ,CAAA;AAEA,EAAO,OAAA;AAAA,IACL;AAAA,GACF;AACF,CAAA;AAEA,IAAO,iBAAQ,GAAA","file":"chunk-BP5VBWVD.mjs","sourcesContent":["import { getFaucetHost, requestSuiFromFaucetV1 } from '@mysten/sui/faucet'\n\nexport const fundAddress = async (\n  address: string,\n  network: 'localnet' | 'devnet' | 'testnet'\n) => {\n  return await requestSuiFromFaucetV1({\n    host: getFaucetHost(network),\n    recipient: address,\n  })\n}\n\nexport const getTestnetFaucetLink = (address: string) => {\n  return `https://faucet.sui.io/?address=${address}`\n}\n","import { useCurrentAccount, useSuiClientContext } from '@mysten/dapp-kit'\nimport { formatAddress } from '@mysten/sui/utils'\nimport { fundAddress, getTestnetFaucetLink } from '~~/helpers/faucet'\n\nexport interface IUseFaucetParams {\n  onError?: (error: Error | null, errorMessage?: string) => void\n  onSuccess?: (message: string) => void\n}\n\nexport interface IUseFaucetResponse {\n  /**\n   * Funds the address on the test network.\n   *\n   * @param {string|undefined} address The address to fund. If not provided, the current address is used.\n   */\n  fund: (address?: string) => void\n}\n\n/**\n * The `useFaucet()` hook lets you fund an address an a test network.\n * \n * The supported networks are **localnet**, **devnet** and **testnet**.\n * The granted amount is:\n * - localnet: 100 SUI\n * - devnet: 10 SUI\n * - testnet: 1 SUI\n * For the **testnet**, the faucet link is opened in a new tab.\n * Please note there is a certain quota for requesting funds from **devnet** and **testnet**.\n * If you have reached the limit, wait for 24 hours, and in the meanwhile use the `#devnet-faucet` and `#testnet-faucet` channels \n * of the official Sui Discord https://discord.gg/sui.\n\n * @returns {IUseFaucetResponse} An object with the fund function.\n */\nconst useFaucet = ({\n  onError,\n  onSuccess,\n}: IUseFaucetParams): IUseFaucetResponse => {\n  const ctx = useSuiClientContext()\n  const currentAccount = useCurrentAccount()\n\n  const fund = async (address?: string) => {\n    if (!['localnet', 'devnet', 'testnet'].includes(ctx.network)) {\n      onError != null &&\n        onError(null, `The ${ctx.network} network does not have a faucet`)\n      return\n    }\n\n    const fundedAddress = address == null ? currentAccount?.address : undefined\n    if (fundedAddress == null) {\n      onError != null && onError(null, 'Please connect your wallet first')\n      return\n    }\n\n    // For the testnet, open the faucet link in a new tab.\n    if (ctx.network === 'testnet') {\n      window.open(getTestnetFaucetLink(fundedAddress), '_blank')\n      return\n    }\n\n    try {\n      const { error } = await fundAddress(\n        fundedAddress,\n        ctx.network as 'localnet' | 'devnet'\n      )\n      if (error) {\n        onError != null &&\n          onError(\n            new Error(error),\n            'Cannot fund the address on this network at the moment'\n          )\n      }\n    } catch (e) {\n      onError != null && onError(e as Error, 'Cannot fund the address')\n      return\n    }\n\n    onSuccess != null &&\n      onSuccess(\n        `The ${formatAddress(fundedAddress)} address has been funded successfully`\n      )\n  }\n\n  return {\n    fund,\n  }\n}\n\nexport default useFaucet\n"]}