Skip to content
Permalink
Browse files

Upgrade `ow` dependency (#593)

  • Loading branch information...
sindresorhus committed Feb 23, 2019
1 parent 3612a4f commit 4a3798007c9feeff88d167323d819edbd7aea7e2
Showing with 57 additions and 45 deletions.
  1. +48 −36 app/renderer/api.js
  2. +2 −2 app/renderer/block-explorer.js
  3. +1 −1 app/renderer/fetch-currency-info.js
  4. +1 −1 package.json
  5. +5 −5 yarn.lock
@@ -19,9 +19,9 @@ const genericError = object => errorWithObject('Encountered an error', object);

export default class Api {
constructor({endpoint, seedPhrase, concurrency = 1}) {
ow(endpoint, ow.string.label('endpoint'));
ow(seedPhrase, ow.string.label('seedPhrase'));
ow(concurrency, ow.number.integerOrInfinite.positive.label('concurrency'));
ow(endpoint, 'endpoint', ow.string);
ow(seedPhrase, 'seedPhrase', ow.string);
ow(concurrency, 'concurrency', ow.number.positive.integerOrInfinite);

this.endpoint = endpoint;
this.token = sha256(seedPhrase);
@@ -43,7 +43,7 @@ export default class Api {
}

async request(data) {
ow(data, ow.object.label('data'));
ow(data, 'data', ow.object);

const queueId = (this.useQueue && this.socket) ? ++this.currentQueueId : 0;

@@ -100,7 +100,7 @@ export default class Api {
}

async enableCurrency(symbol) {
ow(symbol, symbolPredicate.label('symbol'));
ow(symbol, 'symbol', symbolPredicate);

const currency = getCurrency(symbol);

@@ -137,7 +137,7 @@ export default class Api {
}

disableCoin(coin) {
ow(coin, symbolPredicate.label('coin'));
ow(coin, 'coin', symbolPredicate);

return this.request({
method: 'disable',
@@ -150,8 +150,8 @@ export default class Api {
}

balance(coin, address) {
ow(coin, symbolPredicate.label('coin'));
ow(address, ow.string.label('address'));
ow(coin, 'coin', symbolPredicate);
ow(address, 'address', ow.string);

return this.request({
method: 'balance',
@@ -165,8 +165,8 @@ export default class Api {
}

async orderBook(base, rel) {
ow(base, symbolPredicate.label('base'));
ow(rel, symbolPredicate.label('rel'));
ow(base, 'base', symbolPredicate);
ow(rel, 'rel', symbolPredicate);

const response = await this.request({
method: 'orderbook',
@@ -197,12 +197,14 @@ export default class Api {
}

order(opts) {
ow(opts.type, ow.string.oneOf(['buy', 'sell']).label('type'));
ow(opts.baseCurrency, symbolPredicate.label('baseCurrency'));
ow(opts.quoteCurrency, symbolPredicate.label('quoteCurrency'));
ow(opts.amount, ow.number.finite.label('amount'));
ow(opts.total, ow.number.finite.label('total'));
ow(opts.price, ow.number.finite.label('price'));
ow(opts, 'opts', ow.object.exactShape({
type: ow.string.oneOf(['buy', 'sell']),
baseCurrency: symbolPredicate,
quoteCurrency: symbolPredicate,
amount: ow.number.finite,
total: ow.number.finite,
price: ow.number.finite,
}));

return this.request({
method: opts.type,
@@ -216,7 +218,7 @@ export default class Api {
}

async cancelOrder(uuid) {
ow(uuid, uuidPredicate.label('uuid'));
ow(uuid, 'uuid', uuidPredicate);

const response = await this.request({
method: 'cancel',
@@ -239,7 +241,7 @@ export default class Api {
}

async getFee(coin) {
ow(coin, symbolPredicate.label('coin'));
ow(coin, 'coin', symbolPredicate);

const response = await this.request({
method: 'getfee',
@@ -254,9 +256,11 @@ export default class Api {
}

async _createTransaction(opts) {
ow(opts.symbol, symbolPredicate.label('symbol'));
ow(opts.address, ow.string.label('address'));
ow(opts.amount, ow.number.positive.finite.label('amount'));
ow(opts, 'opts', ow.object.exactShape({
symbol: symbolPredicate,
address: ow.string,
amount: ow.number.positive.finite,
}));

const result = await this.request({
method: 'withdraw',
@@ -276,8 +280,8 @@ export default class Api {
}

async _broadcastTransaction(symbol, rawTransaction) {
ow(symbol, symbolPredicate.label('symbol'));
ow(rawTransaction, ow.string.label('rawTransaction'));
ow(symbol, 'symbol', symbolPredicate);
ow(rawTransaction, 'rawTransaction', ow.string);

const response = await this.request({
method: 'sendrawtransaction',
@@ -293,9 +297,11 @@ export default class Api {
}

async _withdrawBtcFork(opts) {
ow(opts.symbol, symbolPredicate.label('symbol'));
ow(opts.address, ow.string.label('address'));
ow(opts.amount, ow.number.positive.finite.label('amount'));
ow(opts, 'opts', ow.object.exactShape({
symbol: symbolPredicate,
address: ow.string,
amount: ow.number.positive.finite,
}));

const {
hex: rawTransaction,
@@ -323,9 +329,11 @@ export default class Api {
}

async _withdrawEth(opts) {
ow(opts.symbol, symbolPredicate.label('symbol'));
ow(opts.address, ow.string.label('address'));
ow(opts.amount, ow.number.positive.finite.label('amount'));
ow(opts, 'opts', ow.object.exactShape({
symbol: symbolPredicate,
address: ow.string,
amount: ow.number.positive.finite,
}));

const {
eth_fee: txFee,
@@ -376,16 +384,20 @@ export default class Api {
}

withdraw(opts) {
ow(opts.symbol, symbolPredicate.label('symbol'));
ow(opts.address, ow.string.label('address'));
ow(opts.amount, ow.number.positive.finite.label('amount'));
ow(opts, 'opts', ow.object.exactShape({
symbol: symbolPredicate,
address: ow.string,
amount: ow.number.positive.finite,
}));

return getCurrency(opts.symbol).etomic ? this._withdrawEth(opts) : this._withdrawBtcFork(opts);
}

kickstart(opts) {
ow(opts.requestId, ow.number.positive.finite.label('requestId'));
ow(opts.quoteId, ow.number.positive.finite.label('quoteId'));
ow(opts, 'opts', ow.object.exactShape({
requestId: ow.number.positive.finite,
quoteId: ow.number.positive.finite,
}));

return this.request({
method: 'kickstart',
@@ -395,8 +407,8 @@ export default class Api {
}

listUnspent(coin, address) {
ow(coin, symbolPredicate.label('coin'));
ow(address, ow.string.label('address'));
ow(coin, 'coin', symbolPredicate);
ow(address, 'address', ow.string);

return this.request({
method: 'listunspent',
@@ -163,8 +163,8 @@ const explorers = new Map(Object.entries({
const blockExplorer = {};

blockExplorer.tx = (symbol, txid) => {
ow(symbol, ow.string.label('symbol'));
ow(txid, ow.string.label('txid'));
ow(symbol, 'symbol', ow.string.uppercase);
ow(txid, 'txid', ow.string);

const explorer = explorers.get(isEtomic(symbol) ? 'ETH' : symbol);

@@ -6,7 +6,7 @@ import {ignoreExternalPrice} from '../constants';
const baseURL = 'https://api.coingecko.com/api/v3';

const fetchCurrencyInfo = async symbols => {
ow(symbols, ow.array.ofType(ow.string.uppercase));
ow(symbols, 'symbols', ow.array.ofType(ow.string.uppercase));

const filteredSymbols = symbols.filter(symbol => !ignoreExternalPrice.has(symbol));

@@ -31,7 +31,7 @@
"mem": "^4.0.0",
"modern-normalize": "^0.5.0",
"moment": "^2.23.0",
"ow": "^0.8.0",
"ow": "^0.12.0",
"p-any": "^1.1.0",
"p-event": "^2.1.0",
"p-map": "^2.0.0",
@@ -8091,16 +8091,16 @@ osenv@0, osenv@^0.1.4:
os-homedir "^1.0.0"
os-tmpdir "^1.0.0"

ow@^0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/ow/-/ow-0.12.0.tgz#ce3b53a81af78171a21478bd684bd9862b152b35"
integrity sha512-GWAoq5RiK3HpMbwvM/aszyYYm7UvZzNfx5QPDbCXd52lROiDVBn6x6M06DhsL/Y8BTl42djQAPWhu6adaWwZyQ==

ow@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/ow/-/ow-0.6.0.tgz#1371352713192a8dd54ec13ab0f0f1464b58941f"
integrity sha512-CJRcySlsICcZoVH5L259wYecV7JRiGOGyxTpMF0YL2QIaETrl75ZhNpvn+jJN19HlCcUS2QyPpWJmOMya8kwCw==

ow@^0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/ow/-/ow-0.8.0.tgz#d360d779c996f4132941a596c87f86ce8e812e62"
integrity sha512-hYgYZNcRfIZ2JppSTqh6mxdU1zkUXsGlwy4eBsRG91R6CiZk7cB+AfHl+SVKBdynQvAnNHNfu0ZrtJN1jj7Mow==

p-any@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/p-any/-/p-any-1.1.0.tgz#1d03835c7eed1e34b8e539c47b7b60d0d015d4e1"

0 comments on commit 4a37980

Please sign in to comment.
You can’t perform that action at this time.