@mcchadwick/fiosdk
Version:
The Foundation for Interwallet Operability (FIO) is a consortium of leading blockchain wallets, exchanges and payments providers that seeks to accelerate blockchain adoption by reducing the risk, complexity, and inconvenience of sending and receiving cryp
46 lines (40 loc) • 1.15 kB
text/typescript
import { Constants } from '../../utils/constants'
export class MockRegisterFioName {
ENDPOINT: string = '/register_fio_name'
ACTION: string = 'regaddress'
ACOUNT: string = Constants.defaultAccount
fioName: string
publicKey: string
server: string
constructor(fioName: string, publicKey: string, server: string) {
this.fioName = fioName
this.publicKey = publicKey
this.server = server
}
async execute(): Promise<any> {
let body = {
fio_name: this.fioName,
owner_fio_public_key: this.publicKey
}
let options = {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(body)
}
return fetch(this.server + this.ENDPOINT, options).then(response => {
let statusCode = response.status
let data = response.json()
return Promise.all([statusCode, data])
})
.then(([status, data]) => {
if (status < 200 || status > 300) {
throw new Error(JSON.stringify({ errorCode: status, msg: data }))
} else {
return data
}
})
}
}