60 lines
1.4 KiB
JavaScript
60 lines
1.4 KiB
JavaScript
import { assertContentTypeJson, assertResponseOk } from '@/lib/url'
|
|
|
|
export const galoyBlinkUrl = 'https://api.blink.sv/graphql'
|
|
export const galoyBlinkDashboardUrl = 'https://dashboard.blink.sv/'
|
|
|
|
export const SCOPE_READ = 'READ'
|
|
export const SCOPE_WRITE = 'WRITE'
|
|
export const SCOPE_RECEIVE = 'RECEIVE'
|
|
|
|
export async function getWallet (authToken, currency) {
|
|
const out = await request(authToken, `
|
|
query me {
|
|
me {
|
|
defaultAccount {
|
|
wallets {
|
|
id
|
|
walletCurrency
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`, {})
|
|
const wallets = out.data.me.defaultAccount.wallets
|
|
for (const wallet of wallets) {
|
|
if (wallet.walletCurrency === currency) {
|
|
return wallet
|
|
}
|
|
}
|
|
throw new Error(`wallet ${currency} not found`)
|
|
}
|
|
|
|
export async function request (authToken, query, variables = {}) {
|
|
const options = {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-API-KEY': authToken
|
|
},
|
|
body: JSON.stringify({ query, variables })
|
|
}
|
|
const res = await fetch(galoyBlinkUrl, options)
|
|
|
|
assertResponseOk(res)
|
|
assertContentTypeJson(res)
|
|
|
|
return res.json()
|
|
}
|
|
|
|
export async function getScopes (authToken) {
|
|
const out = await request(authToken, `
|
|
query scopes {
|
|
authorization {
|
|
scopes
|
|
}
|
|
}
|
|
`, {})
|
|
const scopes = out?.data?.authorization?.scopes
|
|
return scopes || []
|
|
}
|