Skip to content

Commit

Permalink
Merge pull request #3760 from NotEternal/tsIgnoreGetBalance
Browse files Browse the repository at this point in the history
TypeScript @ts-ignore: getBalance
  • Loading branch information
Orsoev Mikhail authored Dec 7, 2020
2 parents 83e8511 + 109802c commit 8773500
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 27 deletions.
13 changes: 8 additions & 5 deletions src/common/coins/BTC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import BigNumber from 'bignumber.js'

import { networkType } from './../domain/network'
import bip44 from './../helpers/bip44'

import {
ICoin,
ILibAdapter,
IConnector
} from './interfaces'

const netNames = {
'mainnet': 'mainnet',
'testnet': 'testnet',
}

const BTC = {
const BTC: ICoin = {
ticker: 'BTC',
name: 'Bitcoin',
precision: 8,
Expand Down Expand Up @@ -80,11 +84,10 @@ export default BTC



const libAdapter = {
const libAdapter: ILibAdapter = {

accountFromMnemonic(mnemonic, netName) {
const network = BTC[netName]
// @ts-ignore
const settings = network.settings

// todo: move?
Expand Down Expand Up @@ -134,7 +137,7 @@ const libAdapter = {



const connector = {
const connector: IConnector = {

// bitcore API documentation:
// https://github.com/bitpay/bitcore/blob/master/packages/bitcore-node/docs/api-documentation.md
Expand Down
13 changes: 8 additions & 5 deletions src/common/coins/GHOST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import fetch from 'node-fetch'

import { networkType } from './../domain/network'
import bip44 from './../helpers/bip44'
import {
ICoin,
ILibAdapter,
IConnector
} from './interfaces'


const netNames = {
'mainnet': 'mainnet',
'testnet': 'testnet',
}

const GHOST = {
const GHOST: ICoin = {
ticker: 'GHOST',
name: 'Ghost',
precision: 8,
Expand Down Expand Up @@ -85,11 +90,10 @@ export default GHOST



const libAdapter = {
const libAdapter: ILibAdapter = {

accountFromMnemonic(mnemonic, netName) {
const network = GHOST[netName]
//@ts-ignore
const settings = network.settings

const seed = bip39.mnemonicToSeedSync(mnemonic)
Expand Down Expand Up @@ -126,7 +130,6 @@ const libAdapter = {

const network = GHOST[netName]
const addressStr = address.toString()
//@ts-ignore
const unspent = await connector.fetchUnspents(network.type, addressStr)

const tx = new ghost_bitcore.Transaction()
Expand All @@ -143,7 +146,7 @@ const libAdapter = {



const connector = {
const connector: IConnector = {

getApiUrl(netType) {
if (netType === networkType.mainnet) {
Expand Down
11 changes: 6 additions & 5 deletions src/common/coins/LTC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import fetch from 'node-fetch'

import { networkType } from './../domain/network'
import bip44 from './../helpers/bip44'

import {
ICoin,
ILibAdapter
} from './interfaces'

const netNames = {
'mainnet': 'mainnet',
'testnet': 'testnet',
}

const LTC = {
const LTC: ICoin = {
ticker: 'LTC',
name: 'Litecoin',
precision: 8, // ?
Expand Down Expand Up @@ -71,17 +74,15 @@ export default LTC



const libAdapter = {
const libAdapter: ILibAdapter = {

accountFromMnemonic(mnemonic, netName) {
const network = LTC[netName]
//@ts-ignore
const settings = network.settings

// todo: move?

const seed = bip39.mnemonicToSeedSync(mnemonic)
//@ts-ignore
const root = bip32.fromSeed(seed, network.bip32settings)
const derivePath = bip44.createDerivePath(network)
const child = root.derivePath(derivePath)
Expand Down
13 changes: 8 additions & 5 deletions src/common/coins/NEXT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import fetch from 'node-fetch'

import { networkType } from './../domain/network'
import bip44 from './../helpers/bip44'
import {
ICoin,
ILibAdapter,
IConnector
} from './interfaces'


const netNames = {
'mainnet': 'mainnet',
//'testnet': 'testnet', // testnet is down
}

const NEXT = {
const NEXT: ICoin = {
ticker: 'NEXT',
name: 'NEXT.coin',
precision: 8,
Expand Down Expand Up @@ -64,11 +69,10 @@ export default NEXT



const libAdapter = {
const libAdapter: ILibAdapter = {

accountFromMnemonic(mnemonic, netName) {
const network = NEXT[netName]
//@ts-ignore
const settings = network.settings

const seed = bip39.mnemonicToSeedSync(mnemonic)
Expand Down Expand Up @@ -117,7 +121,6 @@ const libAdapter = {

const network = NEXT[netName]
const addressStr = address.toString()
//@ts-ignore
const unspent = await connector.fetchUnspents(network.type, addressStr)

const tx = new bitcore.Transaction()
Expand All @@ -134,7 +137,7 @@ const libAdapter = {



const connector = {
const connector: IConnector = {

// next.exhnage API documentation:
// https://explore.next.exchange/#/api
Expand Down
27 changes: 27 additions & 0 deletions src/common/coins/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export interface ICoin {
ticker: string
name: string
precision: number
networks: { [key: string]: string }
}

export interface ILibAdapter {
accountFromMnemonic(mnemonic: string, netName: string): {
privateKey: string
publicKey: string
address: string
}
createTx?({ netName, account, amount, to }): Promise<string> // not sure what the <string>
}

export interface IConnector {
getApiUrl(netwType: string): string
getTxUrl(netType: string, txId: string): string
fetchBalance(networkType: string, address: string): Promise<number>

fetchUnspents?(netType: string, addr: string): Promise<JSON>
fetchTx?(txid: string): Promise<void> // this method is empty now
fetchRawTx?(txid: string): Promise<void> // this method is empty now
publishRawTx?(netType: string, rawTx: string): Promise<JSON>
publishTx?(networkType: string, rawTx: string): Promise<JSON>
}
2 changes: 1 addition & 1 deletion src/common/tests/test-getBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const tests = [
}
const { coin, network, address, isCoins } = test;
console.log(`Test: getBalance, ${coin} ${network}, balance ${isCoins ? '> 0' : '= 0'}`)
//@ts-ignore

const balance = await coins[coin][network].getBalance(address)
//console.log(balance)
if ((balance > 0) == isCoins) {
Expand Down
3 changes: 1 addition & 2 deletions src/core/swap.swaps/SumSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class SumSwap extends SwapInterface {
* @param {object|string} data - scriptValues or wallet address
* @returns {Promise.<void>}
*/
async getBalance(data, hashName) {
async getBalance(data, hashName?) {
let address

if (typeof data === 'string') {
Expand Down Expand Up @@ -341,7 +341,6 @@ class SumSwap extends SwapInterface {
async checkBalance(data) {
const { ownerAddress, expectedValue } = data
let balance = await util.helpers.repeatAsyncUntilResult(() =>
//@ts-ignore
this.getBalance( ownerAddress )
)

Expand Down
2 changes: 0 additions & 2 deletions src/front/shared/pages/Wallet/Row/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,12 @@ export default class Row extends Component<any, any> {

switch (currency) {
case 'BTC (SMS-Protected)':
//@ts-ignore
await actions.btcmultisig.getBalance()
break
case 'BTC (Multisig)':
await actions.btcmultisig.getBalanceUser(address)
break
case 'BTC (PIN-Protected)':
//@ts-ignore
await actions.btcmultisig.getBalancePin()
break
default:
Expand Down
3 changes: 1 addition & 2 deletions src/front/shared/redux/actions/btcmultisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,6 @@ const addSMSWallet = async (mnemonicOrKey) => {
let btcSmsPublicKeys = [btcSMSServerKey, mnemonicKey]

await actions.btcmultisig.login_SMS(privateKey, btcSmsPublicKeys)
//@ts-ignore
await getBalance()
}

Expand Down Expand Up @@ -934,7 +933,7 @@ const getBalance = (ownAddress = null, ownDataKey = null) => {
})
}

const getBalancePin = (checkAddress) => {
const getBalancePin = () => {
const { user: { btcMultisigPinData: { address } } } = getState()

return getBalance(address, 'btcMultisigPinData')
Expand Down

0 comments on commit 8773500

Please sign in to comment.