From 96242110bfbf0f0ff6ba8e4067bc689c343a323c Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Tue, 16 Oct 2018 13:51:04 -0700 Subject: [PATCH] fix: add Token flowtype declarations --- web3.js/module.flow.js | 57 +++++++++++++++++++++++++++++++++++- web3.js/src/token-program.js | 8 ++--- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/web3.js/module.flow.js b/web3.js/module.flow.js index 79b4958efd..4890bd5b40 100644 --- a/web3.js/module.flow.js +++ b/web3.js/module.flow.js @@ -10,6 +10,8 @@ * */ +import BN from 'bn.js'; + declare module '@solana/web3.js' { // === src/publickey.js === declare export class PublicKey { @@ -95,6 +97,59 @@ declare module '@solana/web3.js' { } // === src/token-program.js === - /* TODO */ + declare export class TokenAmount extends BN { + toBuffer(): Buffer; + fromBuffer(buffer: Buffer): TokenAmount; + } + + declare export type TokenInfo = {| + supply: TokenAmount, + decimals: number, + name: string, + symbol: string, + |}; + declare export type TokenAccountInfo = {| + token: PublicKey; + owner: PublicKey; + amount: TokenAmount; + source: null | PublicKey; + |} + declare type TokenAndPublicKey = [Token, PublicKey]; + + declare export class Token { + static programId: PublicKey; + token: PublicKey; + + static createNewToken( + connection: Connection, + owner: Account, + supply: TokenAmount, + name: string, + symbol: string, + decimals: number, + ): Promise; + + constructor(connection: Connection, token: PublicKey) : Token; + newAccount(owner: Account, source: null | PublicKey): Promise; + tokenInfo(): Promise; + accountInfo(account: PublicKey): Promise; + transfer( + owner: Account, + source: PublicKey, + destination: PublicKey, + amount: number | TokenAmount, + ): Promise; + approve( + owner: Account, + source: PublicKey, + delegate: PublicKey, + amount: number | TokenAmount + ): Promise; + ( + owner: Account, + source: PublicKey, + delegate: PublicKey + ): Promise; + } } diff --git a/web3.js/src/token-program.js b/web3.js/src/token-program.js index cb1df92254..09bf454509 100644 --- a/web3.js/src/token-program.js +++ b/web3.js/src/token-program.js @@ -52,7 +52,7 @@ export class TokenAmount extends BN { /** * Information about a token */ -type TokenInfo = { +type TokenInfo = {| /** * Total supply of tokens */ @@ -72,7 +72,7 @@ type TokenInfo = { * Symbol for this token */ symbol: string, -}; +|}; /** * @private @@ -87,7 +87,7 @@ const TokenInfoLayout = BufferLayout.struct([ /** * Information about a token account */ -type TokenAccountInfo = { +type TokenAccountInfo = {| /** * The kind of token this account holds */ @@ -111,7 +111,7 @@ type TokenAccountInfo = { * an allowance of tokens that may be transferred from the source account */ source: null | PublicKey, -}; +|}; /** * @private