From c3176ff485ec9992ec1b962a7d293b457b76cb03 Mon Sep 17 00:00:00 2001 From: Hunter001 <146340502+od-hunter@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:24:47 +0000 Subject: [PATCH 1/3] feat: check testnet account for funding --- src/lib/stellar/horizonQueries.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib/stellar/horizonQueries.js b/src/lib/stellar/horizonQueries.js index ddb1019..b217a82 100644 --- a/src/lib/stellar/horizonQueries.js +++ b/src/lib/stellar/horizonQueries.js @@ -1,7 +1,7 @@ import { error } from '@sveltejs/kit' -import { TransactionBuilder, Networks, StrKey, Asset, Horizon } from '@stellar/stellar-sdk'; +import { TransactionBuilder, Networks, StrKey, Asset, Horizon } from '@stellar/stellar-sdk' -const horizonUrl = 'https://horizon-testnet.stellar.org'; +const horizonUrl = 'https://horizon-testnet.stellar.org' const server = new Horizon.Server(horizonUrl) /** @@ -38,7 +38,16 @@ export async function fetchAccount(publicKey) { } catch (err) { // @ts-ignore if (err.response?.status === 404) { - throw error(404, 'account not funded on network') + try { + fundWithFriendbot(publicKey) + + let account = await server.accounts().accountId(publicKey).call() + return account + } catch (error) { + throw error(500, { + message: `Unable to fund account ${publicKey}: ${error.message}`, + }) + } } else { // @ts-ignore throw error(err.response?.status ?? 400, { From bbdfbb22d74e3f2c86c4dea81d1c7456dc6cda19 Mon Sep 17 00:00:00 2001 From: Hunter001 <146340502+od-hunter@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:45:35 +0000 Subject: [PATCH 2/3] implement requestedd changes --- src/lib/stellar/horizonQueries.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/stellar/horizonQueries.js b/src/lib/stellar/horizonQueries.js index b217a82..d1773a5 100644 --- a/src/lib/stellar/horizonQueries.js +++ b/src/lib/stellar/horizonQueries.js @@ -39,11 +39,11 @@ export async function fetchAccount(publicKey) { // @ts-ignore if (err.response?.status === 404) { try { - fundWithFriendbot(publicKey) + await fundWithFriendbot(publicKey) let account = await server.accounts().accountId(publicKey).call() return account - } catch (error) { + } catch (err) { throw error(500, { message: `Unable to fund account ${publicKey}: ${error.message}`, }) From e3d1a1672226e641a4192196de0876d8c96d81e7 Mon Sep 17 00:00:00 2001 From: Hunter001 <146340502+od-hunter@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:55:14 +0000 Subject: [PATCH 3/3] implement requestedd changes --- src/lib/stellar/horizonQueries.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/stellar/horizonQueries.js b/src/lib/stellar/horizonQueries.js index d1773a5..9f58ac8 100644 --- a/src/lib/stellar/horizonQueries.js +++ b/src/lib/stellar/horizonQueries.js @@ -45,7 +45,7 @@ export async function fetchAccount(publicKey) { return account } catch (err) { throw error(500, { - message: `Unable to fund account ${publicKey}: ${error.message}`, + message: `Unable to fund account ${publicKey}: ${err.message}`, }) } } else {