import axios, { AxiosInstance } from 'axios' import { TransactionReceipt } from '@ethersproject/providers' import { Policies, TxBatchInterface } from './types/app.interface' export * from './types/app.interface' export class App { private axiosInstance: AxiosInstance constructor(private apiKey: string, private baseURL: string) { this.axiosInstance = axios.create({ baseURL: this.baseURL + '/application', headers: { apikey: this.apiKey, }, }) } balance = async (): Promise<{ balance: string relayAddress: string }> => { const { balance, relayAddress } = ( await this.axiosInstance.get('/balance') ).data return { balance, relayAddress } } createUser = async (): Promise<{ userAddress: string }> => { // todo: check if sufficient balance // call api const { userAddress } = ( await this.axiosInstance.post('/users/create') ).data // return user address return { userAddress } } evaluateBatch = async ( batch: TxBatchInterface, ): Promise<{ success: boolean }> => { // todo: check if sufficient balance // call api const { success } = ( await this.axiosInstance.post('/transactions/evaluate', batch) ).data // return validity return { success } } sendBatch = async (batch: TxBatchInterface): Promise => { // todo: check if sufficient balance // call api const txReceipt = ( await this.axiosInstance.post('/transactions/send', batch) ).data as TransactionReceipt // return validity return txReceipt } getPolicy = async (): Promise<{ policy: Policies }> => { // call api const { policy } = (await this.axiosInstance.get('/policy')).data // return validity return { policy } } updatePolicy = async ( policy: Policies, signerAddress?: string, ): Promise => { // call api await this.axiosInstance.post('/policy', { body: { policy, signerAddress }, }) } }