index.js
// Create new deposit addresses for user
Create new deposit addresses for user
Create new deposit addresses for user
async createDepositAddresses(userId) {
    if (!this.ready)
      throw new Error(
        "[Coinbase] createDepositAddresses() : Please wait until accounts have been loaded."
      );
    if (this.debug)
      console.log(
        "[Coinbase] createDepositAddresses(userId) : Creating addresses for",
        userId + "..."
      );
    if (!userId)
      throw new Error(
        "[Coinbase] createDepositAddresses(userId) : Missing userId parameter. This is required!"
      );
    return new Promise(async (resolve, reject) => {
      const btcAccountId = this.cashierWallets.BTC.id;
      const ethAccountId = this.cashierWallets.ETH.id;
      const ltcAccountId = this.cashierWallets.LTC.id;
      try {
        const btcWallet = await this.api.post(
          `/accounts/${btcAccountId}/addresses`,
          { name: userId }
        );
        const ethWallet = await this.api.post(
          `/accounts/${ethAccountId}/addresses`,
          { name: userId }
        );
        const ltcWallet = await this.api.post(
          `/accounts/${ltcAccountId}/addresses`,
          { name: userId }
        );
        if (this.debug)
          console.log(
            "[Coinbase] createDepositAddresses(userId) : Created addresses for",
            userId + "!"
          );
        resolve({
          BTC: btcWallet.data.address,
          ETH: ethWallet.data.address,
          LTC: ltcWallet.data.address,
        });
      } catch (error) {
        reject(error);
      }
    });
  }
async createDepositAddresses ( userId ) { if ( ! this . ready ) throw new Error ( "[Coinbase] createDepositAddresses() : Please wait until accounts have been loaded." ) ; if ( this . debug ) console . log ( "[Coinbase] createDepositAddresses(userId) : Creating addresses for" , userId + "..." ) ; if ( ! userId ) throw new Error ( "[Coinbase] createDepositAddresses(userId) : Missing userId parameter. This is required!" ) ; return new Promise ( async ( resolve , reject ) => { const btcAccountId = this . cashierWallets . BTC . id ; const ethAccountId = this . cashierWallets . ETH . id ; const ltcAccountId = this . cashierWallets . LTC . id ; try { const btcWallet = await this . api . post ( ` ${ btcAccountId } ` , { name : userId } ) ; const ethWallet = await this . api . post ( ` ${ ethAccountId } ` , { name : userId } ) ; const ltcWallet = await this . api . post ( ` ${ ltcAccountId } ` , { name : userId } ) ; if ( this . debug ) console . log ( "[Coinbase] createDepositAddresses(userId) : Created addresses for" , userId + "!" ) ; resolve ( { BTC : btcWallet . data . address , ETH : ethWallet . data . address , LTC : ltcWallet . data . address , } ) ; } catch ( error ) { reject ( error ) ; } } ) ; }
Create new deposit addresses for user
Create new deposit addresses for user
// Check that package is ready // Check that parameters exist // Get id's from state // Make API calls to create addresses // Return wallet addresses