Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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