Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts: Export wallet type #1122

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { isBrowser } from "./utils/common.js";

export { default as BN } from "bn.js";
export * as web3 from "@solana/web3.js";
export { default as Provider, getProvider, setProvider } from "./provider.js";
export {
default as Provider,
getProvider,
setProvider,
Wallet,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this conflict with the conditional export down below? Wallet is an interface while Node wallet is a class, but they're exported via the same namespace.

} from "./provider.js";
export {
default as Coder,
InstructionCoder,
Expand Down
10 changes: 2 additions & 8 deletions ts/src/program/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,8 @@ export class Program<IDL extends Idl = Idl> {
this._events = new EventManager(this._programId, provider, this._coder);

// Dynamic namespaces.
const [
rpc,
instruction,
transaction,
account,
simulate,
state,
] = NamespaceFactory.build(idl, this._coder, programId, provider);
const [rpc, instruction, transaction, account, simulate, state] =
NamespaceFactory.build(idl, this._coder, programId, provider);
this.rpc = rpc;
this.instruction = instruction;
this.transaction = transaction;
Expand Down
7 changes: 4 additions & 3 deletions ts/src/program/namespace/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,10 @@ export class AccountClient<
fromPubkey: this._provider.wallet.publicKey,
newAccountPubkey: signer.publicKey,
space: sizeOverride ?? size,
lamports: await this._provider.connection.getMinimumBalanceForRentExemption(
sizeOverride ?? size
),
lamports:
await this._provider.connection.getMinimumBalanceForRentExemption(
sizeOverride ?? size
),
programId: this._programId,
});
}
Expand Down
10 changes: 4 additions & 6 deletions ts/src/program/namespace/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ type TypeMap = {
bool: boolean;
} & {
[K in "u8" | "i8" | "u16" | "i16" | "u32" | "i32"]: number;
} &
{
[K in "u64" | "i64" | "u128" | "i128"]: BN;
};
} & {
[K in "u64" | "i64" | "u128" | "i128"]: BN;
};

export type DecodeType<T extends IdlType, Defined> = T extends keyof TypeMap
? TypeMap[T]
Expand All @@ -108,8 +107,7 @@ type ArgsTuple<A extends IdlField[], Defined> = {
[K in keyof A]: A[K] extends IdlField
? DecodeType<A[K]["type"], Defined>
: unknown;
} &
unknown[];
} & unknown[];

type FieldsOfType<I extends IdlTypeDef> = NonNullable<
I["type"] extends IdlTypeDefTyStruct
Expand Down
7 changes: 3 additions & 4 deletions ts/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export const isBrowser =
* @returns A two dimensional array where each T[] length is < the provided size.
*/
export function chunks<T>(array: T[], size: number): T[][] {
return Array.apply(
0,
new Array(Math.ceil(array.length / size))
).map((_, index) => array.slice(index * size, (index + 1) * size));
return Array.apply(0, new Array(Math.ceil(array.length / size))).map(
(_, index) => array.slice(index * size, (index + 1) * size)
);
}