mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-24 14:15:49 +00:00
Typecheck remaining files in src/api
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user