Skip to content

Commit 001056d

Browse files
committed
Set expenditureId field for MOVE_FUNDS motions that are funding expenditures
1 parent b162639 commit 001056d

File tree

4 files changed

+45
-24
lines changed

4 files changed

+45
-24
lines changed

src/handlers/actions/moveFunds.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@ import {
99
isDomainFromFundingPotSupported,
1010
getUpdatedExpenditureBalances,
1111
transactionHasEvent,
12+
getExpenditureByFundingPot,
1213
} from '~utils';
1314
import {
1415
ColonyActionType,
1516
ExpenditureFragment,
16-
GetExpenditureByNativeFundingPotIdAndColonyDocument,
17-
GetExpenditureByNativeFundingPotIdAndColonyQuery,
18-
GetExpenditureByNativeFundingPotIdAndColonyQueryVariables,
1917
UpdateExpenditureDocument,
2018
UpdateExpenditureMutation,
2119
UpdateExpenditureMutationVariables,
2220
} from '~graphql';
23-
import { mutate, query } from '~amplifyClient';
21+
import { mutate } from '~amplifyClient';
2422

2523
export default async (event: ContractEvent): Promise<void> => {
2624
const {
@@ -90,25 +88,6 @@ export default async (event: ContractEvent): Promise<void> => {
9088
}
9189
};
9290

93-
const getExpenditureByFundingPot = async (
94-
colonyAddress: string,
95-
fundingPotId: number,
96-
): Promise<ExpenditureFragment | null> => {
97-
const response = await query<
98-
GetExpenditureByNativeFundingPotIdAndColonyQuery,
99-
GetExpenditureByNativeFundingPotIdAndColonyQueryVariables
100-
>(GetExpenditureByNativeFundingPotIdAndColonyDocument, {
101-
colonyAddress,
102-
nativeFundingPotId: fundingPotId,
103-
});
104-
105-
const expenditure =
106-
response?.data?.getExpendituresByNativeFundingPotIdAndColony?.items?.[0] ??
107-
null;
108-
109-
return expenditure;
110-
};
111-
11291
const updateExpenditureBalances = async (
11392
expenditure: ExpenditureFragment,
11493
tokenAddress: string,

src/handlers/motions/motionCreated/handlers/moveFunds.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ContractEvent, motionNameMapping } from '~types';
55
import {
66
getCachedColonyClient,
77
getDomainDatabaseId,
8+
getExpenditureByFundingPot,
89
isDomainFromFundingPotSupported,
910
toNumber,
1011
} from '~utils';
@@ -53,6 +54,12 @@ export const handleMoveFundsMotion = async (
5354
});
5455
}
5556

57+
// Check if the target pot belongs to an expenditure
58+
const targetExpenditure = await getExpenditureByFundingPot(
59+
colonyAddress,
60+
toNumber(toPot),
61+
);
62+
5663
await createMotionInDB(colonyAddress, event, {
5764
type: motionNameMapping[name],
5865
tokenAddress,
@@ -63,5 +70,6 @@ export const handleMoveFundsMotion = async (
6370
toDomainId: toDomainId
6471
? getDomainDatabaseId(colonyAddress, toNumber(toDomainId))
6572
: undefined,
73+
expenditureId: targetExpenditure?.id,
6674
});
6775
};

src/handlers/multiSig/multiSigCreated/handlers/moveFunds.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ContractEvent, multiSigNameMapping } from '~types';
33
import {
44
getCachedColonyClient,
55
getDomainDatabaseId,
6+
getExpenditureByFundingPot,
67
isDomainFromFundingPotSupported,
78
toNumber,
89
} from '~utils';
@@ -54,6 +55,12 @@ export const handleMoveFundsMultiSig = async (
5455
});
5556
}
5657

58+
// Check if the target pot belongs to an expenditure
59+
const targetExpenditure = await getExpenditureByFundingPot(
60+
colonyAddress,
61+
toNumber(toPot),
62+
);
63+
5764
await createMultiSigInDB(colonyAddress, event, {
5865
type: multiSigNameMapping[name],
5966
tokenAddress,
@@ -64,5 +71,6 @@ export const handleMoveFundsMultiSig = async (
6471
toDomainId: toDomainId
6572
? getDomainDatabaseId(colonyAddress, toNumber(toDomainId))
6673
: undefined,
74+
expenditureId: targetExpenditure?.id,
6775
});
6876
};

src/utils/expenditures.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { BigNumber, utils } from 'ethers';
2+
import { query } from '~amplifyClient';
23

3-
import { ExpenditureBalance } from '~graphql';
4+
import {
5+
ExpenditureBalance,
6+
ExpenditureFragment,
7+
GetExpenditureByNativeFundingPotIdAndColonyDocument,
8+
GetExpenditureByNativeFundingPotIdAndColonyQuery,
9+
GetExpenditureByNativeFundingPotIdAndColonyQueryVariables,
10+
} from '~graphql';
411

512
import { insertAtIndex } from './arrays';
613

@@ -48,3 +55,22 @@ export const getUpdatedExpenditureBalances = (
4855

4956
return updatedBalances;
5057
};
58+
59+
export const getExpenditureByFundingPot = async (
60+
colonyAddress: string,
61+
fundingPotId: number,
62+
): Promise<ExpenditureFragment | null> => {
63+
const response = await query<
64+
GetExpenditureByNativeFundingPotIdAndColonyQuery,
65+
GetExpenditureByNativeFundingPotIdAndColonyQueryVariables
66+
>(GetExpenditureByNativeFundingPotIdAndColonyDocument, {
67+
colonyAddress,
68+
nativeFundingPotId: fundingPotId,
69+
});
70+
71+
const expenditure =
72+
response?.data?.getExpendituresByNativeFundingPotIdAndColony?.items?.[0] ??
73+
null;
74+
75+
return expenditure;
76+
};

0 commit comments

Comments
 (0)