mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
77 lines
2.1 KiB
TypeScript
77 lines
2.1 KiB
TypeScript
import type { Client } from '..'
|
|
import { XRPLFaucetError } from '../errors'
|
|
|
|
export interface FaucetWallet {
|
|
account: {
|
|
xAddress: string
|
|
classicAddress?: string
|
|
secret: string
|
|
}
|
|
amount: number
|
|
balance: number
|
|
}
|
|
|
|
export enum FaucetNetwork {
|
|
Testnet = 'faucet.altnet.rippletest.net',
|
|
Devnet = 'faucet.devnet.rippletest.net',
|
|
AMMDevnet = 'ammfaucet.devnet.rippletest.net',
|
|
NFTDevnet = 'faucet-nft.ripple.com',
|
|
HooksV2Testnet = 'hooks-testnet-v2.xrpl-labs.com',
|
|
}
|
|
|
|
export const FaucetNetworkPaths: Record<string, string> = {
|
|
[FaucetNetwork.Testnet]: '/accounts',
|
|
[FaucetNetwork.Devnet]: '/accounts',
|
|
[FaucetNetwork.AMMDevnet]: '/accounts',
|
|
[FaucetNetwork.NFTDevnet]: '/accounts',
|
|
[FaucetNetwork.HooksV2Testnet]: '/accounts',
|
|
}
|
|
|
|
/**
|
|
* Get the faucet host based on the Client connection.
|
|
*
|
|
* @param client - Client.
|
|
* @returns A {@link FaucetNetwork}.
|
|
* @throws When the client url is not on altnet or devnet.
|
|
*/
|
|
export function getFaucetHost(client: Client): FaucetNetwork | undefined {
|
|
const connectionUrl = client.url
|
|
|
|
if (connectionUrl.includes('hooks-testnet-v2')) {
|
|
return FaucetNetwork.HooksV2Testnet
|
|
}
|
|
|
|
// 'altnet' for Ripple Testnet server and 'testnet' for XRPL Labs Testnet server
|
|
if (connectionUrl.includes('altnet') || connectionUrl.includes('testnet')) {
|
|
return FaucetNetwork.Testnet
|
|
}
|
|
|
|
if (connectionUrl.includes('amm')) {
|
|
return FaucetNetwork.AMMDevnet
|
|
}
|
|
|
|
if (connectionUrl.includes('devnet')) {
|
|
return FaucetNetwork.Devnet
|
|
}
|
|
|
|
if (connectionUrl.includes('xls20-sandbox')) {
|
|
return FaucetNetwork.NFTDevnet
|
|
}
|
|
|
|
throw new XRPLFaucetError('Faucet URL is not defined or inferrable.')
|
|
}
|
|
|
|
/**
|
|
* Get the faucet pathname based on the faucet hostname.
|
|
*
|
|
* @param hostname - hostname.
|
|
* @returns A String with the correct path for the input hostname.
|
|
* If hostname undefined or cannot find (key, value) pair in {@link FaucetNetworkPaths}, defaults to '/accounts'
|
|
*/
|
|
export function getDefaultFaucetPath(hostname: string | undefined): string {
|
|
if (hostname === undefined) {
|
|
return '/accounts'
|
|
}
|
|
return FaucetNetworkPaths[hostname] || '/accounts'
|
|
}
|