Skip to content

Commit

Permalink
fix: add Token flowtype declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Oct 17, 2018
1 parent 1289e6c commit 9b851f0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
57 changes: 56 additions & 1 deletion module.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*
*/

import BN from 'bn.js';

declare module '@solana/web3.js' {
// === src/publickey.js ===
declare export class PublicKey {
Expand Down Expand Up @@ -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<TokenAndPublicKey>;

constructor(connection: Connection, token: PublicKey) : Token;
newAccount(owner: Account, source: null | PublicKey): Promise<PublicKey>;
tokenInfo(): Promise<TokenInfo>;
accountInfo(account: PublicKey): Promise<TokenAccountInfo>;
transfer(
owner: Account,
source: PublicKey,
destination: PublicKey,
amount: number | TokenAmount,
): Promise<void>;
approve(
owner: Account,
source: PublicKey,
delegate: PublicKey,
amount: number | TokenAmount
): Promise<void>;
(
owner: Account,
source: PublicKey,
delegate: PublicKey
): Promise<void>;
}

}
8 changes: 4 additions & 4 deletions src/token-program.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class TokenAmount extends BN {
/**
* Information about a token
*/
type TokenInfo = {
type TokenInfo = {|
/**
* Total supply of tokens
*/
Expand All @@ -72,7 +72,7 @@ type TokenInfo = {
* Symbol for this token
*/
symbol: string,
};
|};

/**
* @private
Expand All @@ -87,7 +87,7 @@ const TokenInfoLayout = BufferLayout.struct([
/**
* Information about a token account
*/
type TokenAccountInfo = {
type TokenAccountInfo = {|
/**
* The kind of token this account holds
*/
Expand All @@ -111,7 +111,7 @@ type TokenAccountInfo = {
* an allowance of tokens that may be transferred from the source account
*/
source: null | PublicKey,
};
|};

/**
* @private
Expand Down

0 comments on commit 9b851f0

Please sign in to comment.