xrpl.js icon indicating copy to clipboard operation
xrpl.js copied to clipboard

Add new fundWallet which only requires address

Open ckniffen opened this issue 2 years ago • 7 comments

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.

ckniffen avatar May 03 '23 18:05 ckniffen

Couldn't we just add support for a string type in the same param?

mvadari avatar May 03 '23 18:05 mvadari

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.

ckniffen avatar May 03 '23 18:05 ckniffen

TS supports polymorphic return iirc The fact I can't remember off hand, while on mobile, says a lot though

sublimator avatar May 04 '23 01:05 sublimator

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

mvadari avatar May 04 '23 12:05 mvadari

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

sublimator avatar May 05 '23 07:05 sublimator

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 }
  > {

tequdev avatar Aug 29 '23 09:08 tequdev

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.

mvadari avatar Aug 31 '23 12:08 mvadari