Skip to content

Commit

Permalink
Merge branch 'issue-1/fix-return-type' into 'master'
Browse files Browse the repository at this point in the history
Fix return type of `getBalance`

Closes #1

See merge request thorchain/asgardex-common/asgardex-binance!2
  • Loading branch information
thorchain-admin authored and stuartwk committed Oct 4, 2020
1 parent 528bbb1 commit 7a27c74
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/asgardex-binance/__tests__/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require('dotenv').config()
import BinanceClient from '../src/client'
import { Network } from '../src/types/binance'
import { Network, Balance } from '../src/types/binance'

describe('BinanceClient Test', () => {
const balance = [
Expand All @@ -9,7 +9,7 @@ describe('BinanceClient Test', () => {
frozen: '0.00000000',
locked: '0.00000000',
symbol: 'BNB',
},
} as Balance,
]
const net = Network.MAINNET
const phrase = process.env.VAULT_PHRASE
Expand Down
18 changes: 10 additions & 8 deletions packages/asgardex-binance/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as BIP39 from 'bip39'
import bncClient from '@binance-chain/javascript-sdk'
import { BncClient, Address, MultiTransfer, Market, Balance, Network, TransferResult } from './types/binance'
import { BncClient, Address, MultiTransfer, Market, Network, TransferResult, Balances } from './types/binance'
const axios = require('axios').default

/**
Expand All @@ -18,7 +18,7 @@ export interface BinanceClient {
validatePhrase(phrase: string): boolean
getAddress(): string
validateAddress(address: string): boolean
getBalance(address?: Address): Promise<Balance>
getBalance(address?: Address): Promise<Balances>
// TODO Add return type
// https://gitlab.com/thorchain/asgardex-common/asgardex-binance/-/issues/2
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
Expand Down Expand Up @@ -102,7 +102,7 @@ class Client implements BinanceClient {
}

// Sets this.phrase to be accessed later
setPhrase = (phrase?: string) => {
setPhrase = (phrase = '') => {
if (phrase) {
if (BIP39.validateMnemonic(phrase)) {
this.phrase = phrase
Expand Down Expand Up @@ -131,14 +131,16 @@ class Client implements BinanceClient {
return this.bncClient.checkAddress(address, this.getPrefix())
}

getBalance = async (address?: Address): Promise<Balance> => {
let balance
getBalance = async (address?: Address): Promise<Balances> => {
if (address) {
balance = this.bncClient.getBalance(address)
return this.bncClient.getBalance(address)
} else {
balance = this.bncClient.getBalance(this.getAddress())
try {
return this.bncClient.getBalance(this.getAddress())
} catch (e) {
return Promise.reject(e)
}
}
return balance
}

// TODO Add proper return type
Expand Down
4 changes: 3 additions & 1 deletion packages/asgardex-binance/src/types/binance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ export type Balance = {
frozen: string
}

export type Balances = Balance[]

/**
* Result of `bncClient.transfer(...)`
* to transfer tokens from one address to another.
Expand Down Expand Up @@ -472,7 +474,7 @@ export interface BncClient {
* Get balances
* https://github.com/binance-chain/javascript-sdk/wiki/API-Documentation#clientgetbalancesbalances
*/
getBalance(address: Address): Promise<Balance>
getBalance(address: Address): Promise<Balances>

/**
* Get Transactions
Expand Down

0 comments on commit 7a27c74

Please sign in to comment.