Skip to content

Commit

Permalink
Migrate KavaClient to TS (#70)
Browse files Browse the repository at this point in the history
* Migrate KavaClient to TS

* remove comments

* use wallet type from sig

* bump version

* type remainder of client method signatures

* complete typings

* oop

* don't import sig
  • Loading branch information
thomasmost authored Nov 10, 2021
1 parent 3fe425b commit a59b0a3
Show file tree
Hide file tree
Showing 10 changed files with 12,483 additions and 1,541 deletions.
8,380 changes: 8,362 additions & 18 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kava-labs/javascript-sdk",
"version": "5.2.1-beta",
"version": "5.3.0-beta",
"description": "Supports interaction with the Kava blockchain via a REST api",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
42 changes: 30 additions & 12 deletions src/client/hard/index.js → src/client/hard/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const tx = require('../../tx').tx;
const msg = require('../../msg').msg;
import { tx } from "../../tx";
import { msg } from "../../msg";
import { KavaClient } from "..";
import { Coin } from "../../types/Coin";

const DEFAULT_GAS = 300000;

Expand All @@ -12,12 +14,12 @@ const api = {
getTotalBorrowed: '/hard/total-borrowed',
};

class Hard {
export class Hard {
// @ts-ignore
public kavaClient: KavaClient;
public static instance: Hard;

/**
* @param {Object} kavaClient
*/
constructor(kavaClient) {
constructor(kavaClient: KavaClient) {
if (!Hard.instance) {
this.kavaClient = kavaClient;
Hard.instance = this;
Expand Down Expand Up @@ -109,7 +111,10 @@ class Hard {
* @param {String} sequence optional account sequence
* @return {Promise}
*/
async deposit(amount, gas = DEFAULT_GAS, sequence = null) {
async deposit(amount: Coin[], gas = DEFAULT_GAS, sequence = null) {
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized')
}
const msgDeposit = msg.hard.newMsgDeposit(
this.kavaClient.wallet.address,
amount,
Expand All @@ -125,7 +130,10 @@ class Hard {
* @param {String} sequence optional account sequence
* @return {Promise}
*/
async withdraw(amount, gas = DEFAULT_GAS, sequence = null) {
async withdraw(amount: Coin[], gas = DEFAULT_GAS, sequence = null) {
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized')
}
const msgWithdraw = msg.hard.newMsgWithdraw(
this.kavaClient.wallet.address,
amount,
Expand All @@ -141,7 +149,10 @@ class Hard {
* @param {String} sequence optional account sequence
* @return {Promise}
*/
async borrow(amount, gas = DEFAULT_GAS, sequence = null) {
async borrow(amount: Coin[], gas = DEFAULT_GAS, sequence = null) {
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized')
}
const msgBorrow = msg.hard.newMsgBorrow(
this.kavaClient.wallet.address,
amount,
Expand All @@ -157,8 +168,12 @@ class Hard {
* @param {String} sequence optional account sequence
* @return {Promise}
*/
async repay(amount, gas = DEFAULT_GAS, sequence = null) {
async repay(amount: Coin[], gas = DEFAULT_GAS, sequence = null) {
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized')
}
const msgRepay = msg.hard.newMsgRepay(
this.kavaClient.wallet.address,
this.kavaClient.wallet.address,
amount,
);
Expand All @@ -173,7 +188,10 @@ class Hard {
* @param {String} sequence optional account sequence
* @return {Promise}
*/
async liquidate(borrower, gas = DEFAULT_GAS, sequence = null) {
async liquidate(borrower: string, gas = DEFAULT_GAS, sequence = null) {
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized')
}
const msgLiquidate = msg.hard.newMsgLiquidate(
this.kavaClient.wallet.address,
borrower,
Expand Down
Loading

0 comments on commit a59b0a3

Please sign in to comment.