From fc090ae4cd8c5a9995d835f149c5cf49d2fa9b37 Mon Sep 17 00:00:00 2001 From: Wil Wade Date: Wed, 3 Apr 2024 17:08:52 +0000 Subject: [PATCH] Paseo faucet support --- .github/workflows/deploy-site.yml | 1 - .github/workflows/verify-pr.yml | 1 - client/src/lib/utils/faucetRequest.ts | 20 +++++++++++++++++--- client/src/lib/utils/networkData.ts | 12 ++++++++++-- src/networkData.ts | 23 ++++++++++++++++++++++- 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy-site.yml b/.github/workflows/deploy-site.yml index 4da80cd2..1e5c2dd4 100644 --- a/.github/workflows/deploy-site.yml +++ b/.github/workflows/deploy-site.yml @@ -31,7 +31,6 @@ jobs: - run: yarn run build env: PUBLIC_CAPTCHA_KEY: 6LesXHomAAAAAGVVTCgc467t8hvBbmK7IlYZCc8O - PUBLIC_FAUCET_URL: https://faucet-api-rococo.liberti.social/drip/web GITHUB_PAGES: "/${{ github.event.repository.name }}" STATIC: true - uses: actions/upload-artifact@v4 diff --git a/.github/workflows/verify-pr.yml b/.github/workflows/verify-pr.yml index 2876c11e..f61e2e81 100644 --- a/.github/workflows/verify-pr.yml +++ b/.github/workflows/verify-pr.yml @@ -34,7 +34,6 @@ jobs: - run: yarn run build env: PUBLIC_CAPTCHA_KEY: 6LesXHomAAAAAGVVTCgc467t8hvBbmK7IlYZCc8O - PUBLIC_FAUCET_URL: https://faucet-api-rococo.liberti.social/drip/web GITHUB_PAGES: "/${{ github.event.repository.name }}" STATIC: true - uses: actions/upload-artifact@master diff --git a/client/src/lib/utils/faucetRequest.ts b/client/src/lib/utils/faucetRequest.ts index a322cfaa..a0bd8b66 100644 --- a/client/src/lib/utils/faucetRequest.ts +++ b/client/src/lib/utils/faucetRequest.ts @@ -21,11 +21,25 @@ export async function faucetRequest( network: NetworkData, parachain_id?: string ): Promise { - const body = { address, parachain_id, recaptcha }; + const body: Record = { address, recaptcha }; - const url = network.endpoint; + const chain = network.chains.find((x) => x.id === parseInt(parachain_id || "-1", 10)); + + if (!chain) { + throw new Error( + `Parachain id:${parachain_id || "-1"} for ${network.networkName} is not defined` + ); + } + + // Force the parachain_id to be empty if we have a spcific chain endpoint + + if (!chain.endpoint && parachain_id) { + body.parachain_id = parachain_id; + } + + const url = chain.endpoint || network.endpoint; if (!url) { - throw new Error(`Endpoint for ${network.networkName} is not defined`); + throw new Error(`Endpoint for ${network.networkName} with ${chain.name} is not defined`); } const fetchResult = await fetch(url, { method: "POST", diff --git a/client/src/lib/utils/networkData.ts b/client/src/lib/utils/networkData.ts index 187f0865..c96e332e 100644 --- a/client/src/lib/utils/networkData.ts +++ b/client/src/lib/utils/networkData.ts @@ -3,6 +3,7 @@ import { PUBLIC_FAUCET_URL } from "$env/static/public"; export interface ChainData { name: string; id: number; + endpoint?: string; } function faucetUrl(defaultUrl: string): string { @@ -24,8 +25,15 @@ export interface NetworkData { export const Frequency: NetworkData = { networkName: "Frequency", currency: "XRQCY", - chains: [{ name: "Frequency Rococo Testnet", id: -1 }], - endpoint: faucetUrl(PUBLIC_FAUCET_URL), + chains: [ + { name: "Frequency Paseo Testnet", id: -1 }, + { + name: "Frequency Rococo Testnet", + id: 4044, + endpoint: "https://faucet-api-rococo.liberti.social/drip/web" + } + ], + endpoint: faucetUrl("https://faucet-api-paseo.liberti.social/drip/web"), explorer: null }; diff --git a/src/networkData.ts b/src/networkData.ts index f915963d..410a011f 100644 --- a/src/networkData.ts +++ b/src/networkData.ts @@ -49,6 +49,18 @@ const frequencyRococo: NetworkData = { matrixWhitelistPatterns: [], }; +const frequencyPaseo: NetworkData = { + balanceCap: 1000, + chains: [{ name: "Frequency Paseo Testnet", id: -1 }], + currency: "XRQCY", + decimals: 8, + dripAmount: "5000", + explorer: null, + networkName: "Frequency Paseo Testnet", + rpcEndpoint: "wss://0.rpc.testnet.amplica.io", + matrixWhitelistPatterns: [], +}; + const westend: NetworkData = { balanceCap: 100, chains: [ @@ -123,7 +135,16 @@ const e2e: NetworkData = { matrixWhitelistPatterns: parityWhitelist, }; -export const networks: Record = { rococo, versi, westend, e2e, trappist, paseo, frequencyRococo }; +export const networks: Record = { + rococo, + versi, + westend, + e2e, + trappist, + paseo, + frequencyRococo, + frequencyPaseo, +}; export function getNetworkData(networkName: string): NetworkData { if (!Object.keys(networks).includes(networkName)) {