Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
Make it possible to pay multiple addresses at once
Browse files Browse the repository at this point in the history
  • Loading branch information
chmanie committed Jan 20, 2023
1 parent d75fa65 commit ecb889e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
8 changes: 4 additions & 4 deletions docs/api/classes/OneTxPayment.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ___

**pay**(`recipient`, `amount`, `teamId?`, `tokenAddress?`): [`ColonyTxCreator`](ColonyTxCreator.md)<`OneTxPaymentClientV4`, ``"makePaymentFundedFromDomain"``, { `agent?`: `string` ; `fundamentalId?`: `BigNumber` ; `nPayouts?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\>

Make a payment to a single address using a single token
Make a payment to a single or multiple addresses using one or more tokens

**`Remarks`**

Expand Down Expand Up @@ -83,10 +83,10 @@ import { Id, Tokens, w } from '@colony/sdk';

| Name | Type | Description |
| :------ | :------ | :------ |
| `recipient` | `string` | Wallet address of account to send the funds to (also awarded reputation when sending the native token) |
| `amount` | `BigNumberish` | Amount to pay in wei |
| `recipient` | `string` \| `string`[] | Wallet address of account to send the funds to (also awarded reputation when sending the native token) - can also be an array of addresses to pay |
| `amount` | `BigNumberish` \| `BigNumberish`[] | Amount to pay in wei - can also be an array of amounts for the different tokens |
| `teamId?` | `BigNumberish` | The team to use to send the funds from. Has to have funding of at least the amount you need to send. See [Colony.moveFundsToTeam](Colony.md#movefundstoteam). Defaults to the Colony's root team |
| `tokenAddress?` | `string` | The address of the token to make the payment in. Default is the Colony's native token |
| `tokenAddress?` | `string` \| `string`[] | The address of the token to make the payment in. Default is the Colony's native token - can also be an array of token addresses (needs to be the same length as `amount`) |

#### Returns

Expand Down
36 changes: 24 additions & 12 deletions src/ColonyNetwork/OneTxPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class OneTxPayment {
}

/**
* Make a payment to a single address using a single token
* Make a payment to a single or multiple addresses using one or more tokens
*
* @remarks Requires the `OneTxPayment` extension to be installed for the Colony (this is usually the case for Colonies created via the Dapp). Note that most tokens use 18 decimals, so add a bunch of zeros or use our `w` or `toWei` functions (see example)
*
Expand All @@ -99,9 +99,9 @@ export class OneTxPayment {
* })();
* ```
*
* @param recipient - Wallet address of account to send the funds to (also awarded reputation when sending the native token)
* @param amount - Amount to pay in wei
* @param tokenAddress - The address of the token to make the payment in. Default is the Colony's native token
* @param recipient - Wallet address of account to send the funds to (also awarded reputation when sending the native token) - can also be an array of addresses to pay
* @param amount - Amount to pay in wei - can also be an array of amounts for the different tokens
* @param tokenAddress - The address of the token to make the payment in. Default is the Colony's native token - can also be an array of token addresses (needs to be the same length as `amount`)
* @param teamId - The team to use to send the funds from. Has to have funding of at least the amount you need to send. See [[Colony.moveFundsToTeam]]. Defaults to the Colony's root team
* @returns A transaction creator
*
Expand All @@ -114,15 +114,27 @@ export class OneTxPayment {
* | `nPayouts` | BigNumber | Number of payouts in total |
*/
pay(
recipient: string,
amount: BigNumberish,
recipient: string | string[],
amount: BigNumberish | BigNumberish[],
teamId?: BigNumberish,
tokenAddress?: string,
tokenAddress?: string | string[],
) {
const setTeamId = teamId || Id.RootDomain;
const colonyClient = this.colony.getInternalColonyClient();

const setTokenAddress = tokenAddress || colonyClient.tokenClient.address;
const setReceipient = ([] as string[]).concat(recipient);
const setTeamId = teamId || Id.RootDomain;
const setTokenAddress = tokenAddress
? ([] as string[]).concat(tokenAddress)
: [colonyClient.tokenClient.address];
const setAmount = ([] as BigNumberish[]).concat(amount);

if (Array.isArray(setTokenAddress) && Array.isArray(setAmount)) {
if (setTokenAddress.length !== setAmount.length) {
throw new Error(
'amount and tokenAddress arrays need to have the same size',
);
}
}

return this.colony.createColonyTxCreator(
this.oneTxPaymentClient,
Expand All @@ -148,9 +160,9 @@ export class OneTxPayment {
extChildSkillIndex,
userPermissionDomainId,
userChildSkillIndex,
[recipient],
[setTokenAddress],
[amount],
setReceipient,
setTokenAddress,
setAmount,
setTeamId,
// Skill associated with this payment. Ignore for now
Id.SkillIgnore,
Expand Down

0 comments on commit ecb889e

Please sign in to comment.