Skip to content

Commit

Permalink
feat: check testnet account for funding (#33)
Browse files Browse the repository at this point in the history
* feat: check testnet account for funding

* implement requestedd changes

* implement requestedd changes
  • Loading branch information
od-hunter authored Oct 7, 2024
1 parent a25cc81 commit 8c188cb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/lib/stellar/horizonQueries.js
Original file line number Diff line number Diff line change
@@ -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)

/**
Expand Down Expand Up @@ -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 {
await fundWithFriendbot(publicKey)

let account = await server.accounts().accountId(publicKey).call()
return account
} catch (err) {
throw error(500, {
message: `Unable to fund account ${publicKey}: ${err.message}`,
})
}
} else {
// @ts-ignore
throw error(err.response?.status ?? 400, {
Expand Down

0 comments on commit 8c188cb

Please sign in to comment.