Add new fundWallet which only requires address
Currently if you want to fund an existing wallet you need to provide a Wallet object. Since fundWallet doesn't ever use any part of a Wallet besides classicAddress there should be a version which takes address, amount, and memos.
This new function can be wrapped by the existing fundWallet to maintain the existing interface.
This was from a suggestion from @interc0der.
Couldn't we just add support for a string type in the same param?
I thought about this too but the function currently returns and object with { amount: number, wallet: Wallet }. It should be its own method called something like fundAccount.
TS supports polymorphic return iirc The fact I can't remember off hand, while on mobile, says a lot though
TS supports polymorphic return iirc The fact I can't remember off hand, while on mobile, says a lot though
It definitely does - we use it for client.request
There you go :) !
Though I guess in this case request is nicely vague compared to fundWallet:
request(xxxx, ... ) vs requestXXXX( ... )
fundWallet is in fundXXXX form
The following implementations could be considered.
public async fundWallet<T extends Wallet | string>(
this: Client,
walletOrAddress?: T | null,
options: FundingOptions = {},
): Promise<
T extends Wallet
? {
wallet: Wallet
balance: number
}
: { balance: number }
> {
I was thinking something more like this:
public async fundWallet<T extends Wallet | string>(
this: Client,
walletOrAddress?: T | null,
options: FundingOptions = {},
): Promise<
T extends Wallet
? {
wallet: T
balance: number
}
: {
account: T
balance: number
}
> {
It keeps the same API for addresses.