Skip to content

Commit be9d9cb

Browse files
authored
Merge pull request #327 from JoinColony/feat/create-stream-motion
Streaming Payments API: Creating streams using motions
2 parents d8f4322 + 030397b commit be9d9cb

File tree

7 files changed

+69
-1
lines changed

7 files changed

+69
-1
lines changed

src/graphql/generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,8 @@ export enum ColonyActionType {
652652
CreateExpenditure = 'CREATE_EXPENDITURE',
653653
/** An action related to creating a streaming payment */
654654
CreateStreamingPayment = 'CREATE_STREAMING_PAYMENT',
655+
/** An action related to creating a streaming payment via a motion */
656+
CreateStreamingPaymentMotion = 'CREATE_STREAMING_PAYMENT_MOTION',
655657
/** An action related to editing a domain's details */
656658
EditDomain = 'EDIT_DOMAIN',
657659
/** An action related to editing a domain's details via a motion */

src/handlers/motions/motionCreated/handlers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ export { handleMulticallMotion } from './multicall';
1313
export { handleMakeArbitraryTransactionsMotion } from './makeArbitraryTransactions';
1414
export { handleMetadataDeltaMotion } from './metadataDelta';
1515
export * from './expenditures';
16-
export * from './streamingPayments.ts';
16+
export * from './streamingPayments';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { TransactionDescription } from 'ethers/lib/utils';
2+
import { ContractEvent, motionNameMapping } from '~types';
3+
import { createMotionInDB } from '../../helpers';
4+
import {
5+
getDomainDatabaseId,
6+
getExpenditureDatabaseId,
7+
toNumber,
8+
} from '~utils';
9+
10+
export default async (
11+
colonyAddress: string,
12+
event: ContractEvent,
13+
{ name, args: actionArgs }: TransactionDescription,
14+
): Promise<void> => {
15+
const { args } = event;
16+
const [, , streamingPaymentId] = actionArgs;
17+
const [, , domainId] = args;
18+
19+
await createMotionInDB(colonyAddress, event, {
20+
type: motionNameMapping[name],
21+
fromDomainId: getDomainDatabaseId(colonyAddress, domainId),
22+
streamingPaymentId: getExpenditureDatabaseId(
23+
colonyAddress,
24+
toNumber(streamingPaymentId),
25+
),
26+
});
27+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { TransactionDescription } from 'ethers/lib/utils';
2+
import { ContractEvent, motionNameMapping } from '~types';
3+
import { createMotionInDB } from '../../helpers';
4+
import {
5+
getDomainDatabaseId,
6+
getExpenditureDatabaseId,
7+
toNumber,
8+
} from '~utils';
9+
10+
export default async (
11+
colonyAddress: string,
12+
event: ContractEvent,
13+
{ name, args: actionArgs }: TransactionDescription,
14+
): Promise<void> => {
15+
const { args } = event;
16+
const [, , streamingPaymentId] = actionArgs;
17+
const [, , domainId] = args;
18+
19+
await createMotionInDB(colonyAddress, event, {
20+
type: motionNameMapping[name],
21+
fromDomainId: getDomainDatabaseId(colonyAddress, domainId),
22+
streamingPaymentId: getExpenditureDatabaseId(
23+
colonyAddress,
24+
toNumber(streamingPaymentId),
25+
),
26+
});
27+
};

src/handlers/motions/motionCreated/motionCreated.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,15 @@ export const handleMotionCreated: EventHandler = async (
236236
break;
237237
}
238238

239+
case StreamingPaymentsOperations.CreateStreamingPayment: {
240+
await handleCancelStreamingPaymentsMotion(
241+
colonyAddress,
242+
event,
243+
parsedAction,
244+
);
245+
break;
246+
}
247+
239248
default: {
240249
break;
241250
}

src/types/motions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export enum ColonyOperations {
2727
}
2828

2929
export enum StreamingPaymentsOperations {
30+
CreateStreamingPayment = 'create',
3031
CancelStreamingPayment = 'cancel',
3132
}
3233

@@ -75,6 +76,8 @@ export const motionNameMapping: { [key: string]: ColonyActionType } = {
7576
ColonyActionType.ReleaseStagedPaymentsMotion,
7677
[StreamingPaymentsOperations.CancelStreamingPayment]:
7778
ColonyActionType.CancelStreamingPaymentMotion,
79+
[StreamingPaymentsOperations.CreateStreamingPayment]:
80+
ColonyActionType.CreateStreamingPaymentMotion,
7881
};
7982

8083
export enum MotionSide {

0 commit comments

Comments
 (0)