Skip to content

Commit

Permalink
Merge pull request #3931 from JoinColony/fix/#3899-staged-payment
Browse files Browse the repository at this point in the history
Fix: Staged payments with locked tokens
  • Loading branch information
davecreaser authored Dec 16, 2024
2 parents e31760e + ce7bdce commit e323a02
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import { useColonyContext } from '~context/ColonyContext/ColonyContext.ts';
import { usePaymentBuilderContext } from '~context/PaymentBuilderContext/PaymentBuilderContext.ts';
import { ExpenditureType } from '~gql';
import useNetworkInverseFee from '~hooks/useNetworkInverseFee.ts';
import useTokenLockStates from '~hooks/useTokenLockStates.ts';
import { ActionTypes } from '~redux';
import { mapPayload } from '~utils/actions.ts';
import { notNull } from '~utils/arrays/index.ts';
import getLastIndexFromPath from '~utils/getLastIndexFromPath.ts';
import { formatText } from '~utils/intl.ts';
import { shouldPreventPaymentsWithTokenInColony } from '~utils/tokens.ts';
import { amountGreaterThanZeroValidation } from '~utils/validation/amountGreaterThanZeroValidation.ts';
import {
ACTION_BASE_VALIDATION_SCHEMA,
Expand Down Expand Up @@ -41,6 +43,7 @@ export const useValidationSchema = () => {
.map((colonyToken) => colonyToken.token) || [],
[colony.tokens?.items],
);
const tokenLockStatesMap = useTokenLockStates();

return useMemo(
() =>
Expand Down Expand Up @@ -119,7 +122,18 @@ export const useValidationSchema = () => {
colony,
}),
),
[TOKEN_FIELD_NAME]: string().required(),
[TOKEN_FIELD_NAME]: string()
.test(
'token-unlocked',
formatText({ id: 'errors.amount.tokenIsLocked' }) || '',
(value) =>
!shouldPreventPaymentsWithTokenInColony(
value || '',
colony,
tokenLockStatesMap,
),
)
.required(),
})
.defined()
.required(),
Expand All @@ -145,9 +159,10 @@ export const useValidationSchema = () => {
});
},
)

.defined()
.concat(ACTION_BASE_VALIDATION_SCHEMA),
[colony, colonyTokens],
[colony, colonyTokens, tokenLockStatesMap],
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ const MilestoneReleaseModal: FC<MilestoneReleaseModalProps> = ({
});

const onSubmit = async ({ decisionMethod }) => {
const tokenAddresses: string[] = [];

items.forEach((item) => {
if (!tokenAddresses.includes(item.tokenAddress)) {
tokenAddresses.push(item.tokenAddress);
}
});

try {
const motionPayload: ReleaseExpenditureStagesMotionPayload = {
colonyAddress: colony.colonyAddress,
Expand All @@ -217,12 +225,12 @@ const MilestoneReleaseModal: FC<MilestoneReleaseModalProps> = ({
expenditure,
slotIds: items.map(({ slotId }) => slotId),
motionDomainId: expenditure.nativeDomainId,
tokenAddresses: [colony.nativeToken.tokenAddress],
tokenAddresses,
};
const payload: ReleaseExpenditureStagesPayload = {
colonyAddress: colony.colonyAddress,
expenditure,
tokenAddresses: [colony.nativeToken.tokenAddress],
tokenAddresses,
stagedExpenditureAddress: stagedExpenditureAddress || '',
slotIds: items.map(({ slotId }) => slotId),
userAddress: user?.walletAddress || '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ const ReleaseActionItem: FC<ReleaseActionItemProps> = ({

const isReleasingMultipleMilestones = releasedSlotIds.length > 1;

const wasSuccessful = expenditure.slots
.filter((slot) => releasedSlotIds.includes(slot.id))
.every((slot) => slot.payouts?.every((payout) => payout.isClaimed));

return (
<button
className="group flex w-full items-center justify-between gap-2"
Expand All @@ -63,10 +67,15 @@ const ReleaseActionItem: FC<ReleaseActionItemProps> = ({
</span>
{!action.motionData ? (
<PillsBase
className="bg-success-100 text-success-400"
className={clsx({
'bg-success-100 text-success-400': wasSuccessful,
'bg-negative-100 text-negative-400': !wasSuccessful,
})}
isCapitalized={false}
>
{formatText({ id: 'action.passed' })}
{wasSuccessful
? formatText({ id: 'action.passed' })
: formatText({ id: 'action.failed' })}
</PillsBase>
) : (
<>
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,7 @@
"motion.staking.button.submit": "Stake",
"motion.staking.chart.thresholdLabel": "Not public until min {value} is staked",
"action.passed": "Passed",
"action.failed": "Failed",
"motion.voting.label": "Voting",
"motion.reveal.label": "Reveal",
"motion.outcome.label": "Outcome",
Expand Down

0 comments on commit e323a02

Please sign in to comment.