Typecheck remaining files in src/api

This commit is contained in:
Alan Cohen
2015-07-29 14:23:26 -07:00
parent 7fffbe0c64
commit e583eb4592
4 changed files with 43 additions and 19 deletions

View File

@@ -1,17 +1,20 @@
/* @flow */
'use strict';
const BigNumber = require('bignumber.js');
const core = require('../../core');
const errors = require('./errors');
function dropsToXrp(drops) {
type Amount = {currency: string, issuer: string, value: string}
function dropsToXrp(drops: string): string {
return (new BigNumber(drops)).dividedBy(1000000.0).toString();
}
function xrpToDrops(xrp) {
function xrpToDrops(xrp: string): string {
return (new BigNumber(xrp)).times(1000000.0).floor().toString();
}
function toRippledAmount(amount) {
function toRippledAmount(amount: Amount): string|Amount {
if (amount.currency === 'XRP') {
return xrpToDrops(amount.value);
}
@@ -22,7 +25,9 @@ function toRippledAmount(amount) {
};
}
function wrapCatch(asyncFunction: () => void): () => void {
type AsyncFunction = (...x: any) => void
function wrapCatch(asyncFunction: AsyncFunction): AsyncFunction {
return function() {
try {
asyncFunction.apply(this, arguments);
@@ -33,7 +38,10 @@ function wrapCatch(asyncFunction: () => void): () => void {
};
}
function composeAsync(wrapper, callback) {
type Callback = (err: any, data: any) => void
type Wrapper = (data: any) => any
function composeAsync(wrapper: Wrapper, callback: Callback): Callback {
return function(error, data) {
if (error) {
callback(error);
@@ -50,7 +58,7 @@ function composeAsync(wrapper, callback) {
};
}
function convertExceptions(f) {
function convertExceptions<T>(f: () => T): () => T {
return function() {
try {
return f.apply(this, arguments);