feat: translation (#389)

This commit is contained in:
Cody Tseng 2025-06-23 23:52:21 +08:00 committed by GitHub
parent e2e115ebeb
commit df9066eae0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 1466 additions and 47 deletions

View file

@ -0,0 +1,55 @@
import { JUMBLE_API_BASE_URL } from '@/constants'
class TransactionService {
static instance: TransactionService
constructor() {
if (!TransactionService.instance) {
TransactionService.instance = this
}
return TransactionService.instance
}
async createTransaction(
pubkey: string,
amount: number
): Promise<{
transactionId: string
invoiceId: string
}> {
const url = new URL('/v1/transactions', JUMBLE_API_BASE_URL).toString()
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
pubkey,
amount,
purpose: 'translation'
})
})
const data = await response.json()
if (!response.ok) {
throw new Error(data.error ?? 'Failed to create transaction')
}
return data
}
async checkTransaction(transactionId: string): Promise<{
state: 'pending' | 'failed' | 'settled'
}> {
const url = new URL(`/v1/transactions/${transactionId}/check`, JUMBLE_API_BASE_URL).toString()
const response = await fetch(url, {
method: 'POST'
})
const data = await response.json()
if (!response.ok) {
throw new Error(data.error ?? 'Failed to complete transaction')
}
return data
}
}
const instance = new TransactionService()
export default instance