Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/15873666 edit #3320

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Feat/15873666 edit #3320

wants to merge 3 commits into from

Conversation

CzarekDryl
Copy link
Contributor

Description

This PR adds the ability to edit actions after the locked state during the Funding, Release steps. Editing in Payment step is not possible for now.

  • Edit Mode:

    • Displays yellow border and Edit Pill.
    • Disables stepper buttons and hides Kebab menu.
    • Makes Recipients, Amounts, and Claim Delays editable.
    • Change payment button opens modal, disabled until changes are made.
  • Change Payment Modal:

    • Dropdown for execution options (Reputation and Permissions).
  • Changes Step in Stepper:

    • Changes pill appears after edits in Funding, Release step.
    • Shows details on edits, permissions, and a change counter.
  • If there is funding needed after editing, new pill should show after changes one

Testing

  • Install Lazy Consensus extension to test funding with motion
  • Create advanced payment action and lock it
  • Play around with funding and editing

Closed PR with comments - #3075

Design

Resolves #2238

@CzarekDryl CzarekDryl self-assigned this Oct 14, 2024
@CzarekDryl CzarekDryl requested review from a team as code owners October 14, 2024 11:00
@CzarekDryl CzarekDryl changed the base branch from master to feat/advanced-payments October 14, 2024 11:00
@jakubcolony jakubcolony force-pushed the feat/advanced-payments branch from c0099a8 to c60c833 Compare October 14, 2024 22:02
Base automatically changed from feat/advanced-payments to master October 14, 2024 22:14
@jakubcolony
Copy link
Collaborator

This one also needs a rebase @CzarekDryl

@CzarekDryl
Copy link
Contributor Author

@jakubcolony @arrenv Branch rebased and ready to review

Copy link
Collaborator

@jakubcolony jakubcolony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work overall @CzarekDryl, this was not a simple feature to handle 👍

Some notes from my testing:

  • Missing translations:
image image
  • Should the Make changes button be disabled if there are no changes? Otherwise it is just sending empty transactions.

  • After making changes, the values only update after a few seconds. I can't see this mentioned in the spec, but we may want to update them manually in cache so that they're visible to the user straightaway.

  • If amount is 0, the row should be hidden, that is how they get deleted on the contracts level:

image
  • When I select an edit action, should it be the slots after the changes that are shown? That's what seems to be the case, but they change order when clicked on (could be also related to the issue below):
image image
  • The payment table should be sorted by slot ID, after editing the slots returned from the backend are not necessarily in order (see slot with ID 1 is displayed under slot with ID 2):
image image
  • I feel like this could be related to the above, I edited only the claim delay but the UI mentions 6 changes:
"expenditureSlotChanges": {
  "oldSlots": [
    {
      "id": 1,
      "recipientAddress": "0xb77D57F4959eAfA0339424b83FcFaf9c15407461",
      "claimDelay": "0",
      "payouts": [
        {
          "amount": "1000000000000000000000",
          "tokenAddress": "0xeF841fe1611ce41bFCf0265097EFaf50486F5111"
        }
      ]
    },
    {
      "id": 2,
      "recipientAddress": "0x9dF24e73f40b2a911Eb254A8825103723E13209C",
      "claimDelay": "3600",
      "payouts": [
        {
          "amount": "2000000000000000000000",
          "tokenAddress": "0xeF841fe1611ce41bFCf0265097EFaf50486F5111"
        }
      ]
    }
  ],
  "newSlots": [
    {
      "id": 2,
      "recipientAddress": "0x9dF24e73f40b2a911Eb254A8825103723E13209C",
      "claimDelay": "3600",
      "payouts": [
        {
          "amount": "2000000000000000000000",
          "tokenAddress": "0xeF841fe1611ce41bFCf0265097EFaf50486F5111"
        }
      ]
    },
    {
      "id": 1,
      "recipientAddress": "0xb77D57F4959eAfA0339424b83FcFaf9c15407461",
      "claimDelay": "18000",
      "payouts": [
        {
          "amount": "1000000000000000000000",
          "tokenAddress": "0xeF841fe1611ce41bFCf0265097EFaf50486F5111"
        }
      ]
    }
  ]
}
  • After making a change that required another funding step, I'm being asked to fund the entire amount instead of just the difference between payout sum and current expenditure balance for a given token

  • Adding slots seems to work fine ✅

image
  • Editing in different steps shows correctly in the list, nicely done:
image

Comment on lines 169 to 176
const getEditContent = () => {
switch (actionType) {
case ColonyActionType.CreateExpenditure:
return <PaymentBuilderEdit action={action} />;
default:
return <div>Not implemented yet</div>;
}
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be handled at the level of PaymentBuilder component? It would keep the generic CompletedAction free of feature-specific logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I've moved this to PaymentBuilder component

@arrenv
Copy link
Member

arrenv commented Oct 30, 2024

Should the Make changes button be disabled if there are no changes? Otherwise it is just sending empty transactions.

Preferably not disabled, but, we should validate on click if no changes have been made. With a validation message: "No changes have been made yet."

After making changes, the values only update after a few seconds. I can't see this mentioned in the spec, but we may want to update them manually in cache so that they're visible to the user straightaway.

My concern with showing cached values is if there is an issue with the transaction, you are going to get a flashing of the new then back to old values. My thinking here is that it would probably be better to show a skeleton loading state on the whole table. This could be done in a separate issue.

If amount is 0, the row should be hidden, that is how they get deleted on the contracts level:

Yes, I agree, the ones with 0 values should be hidden.

The payment table should be sorted by slot ID, after editing the slots returned from the backend are not necessarily in order (see slot with ID 1 is displayed under slot with ID 2):

Good pickup Jakub, yes, it would be good to have a consistent order.

@CzarekDryl
Copy link
Contributor Author

@jakubcolony I've sorted all data by slotId, please check it now

Copy link
Collaborator

@jakubcolony jakubcolony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might still be missing sorting by slot ID when viewing changes. The newly added slot is shown at the top:

image image image image

When I select a change request straight after it appears, the blue outline doesn't show:

Screen.Recording.2024-11-08.at.00.10.04.mov

Slots with amounts of 0 should not be shown in the edit mode:

Screen.Recording.2024-11-08.at.00.14.19.mov

In this scenario, I had a single slot and changed the token from CREDS to ETH. It counted 3 changes (should be one) and got a bit confused when displaying the differences:
image

I suspect this could be because you are comparing old and new payouts by indexes rather than token addresses.


The exit modal should not show if there weren't any changes to the expenditure.

@@ -178,10 +184,12 @@ const PaymentBuilderRecipientsField: FC<PaymentBuilderRecipientsFieldProps> = ({
isFullSize={isMobile}
onClick={() => {
fieldArrayMethods.append({
// @TODO: Add slotId (find highest existing slotId and add 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comment can now be removed

success: ActionTypes.EXPENDITURE_EDIT_SUCCESS,
});

const handleEditExpenditureViaMotion = async ({ decisionMethod }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to handle editing expenditures via both action and motion, so the name should be updated

Comment on lines 150 to 153
const showEditOption =
expenditure?.status !== ExpenditureStatus.Cancelled &&
expenditure?.status !== ExpenditureStatus.Draft &&
expenditure?.status !== ExpenditureStatus.Finalized &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about doing it the other way around, ie. checking for statuses that allow editing (Locked, Funding)?

@@ -0,0 +1,72 @@
import clsx from 'clsx';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If #3162 gets merged first, please try to reuse the shared component introduced there

Comment on lines +13 to +18
const sortedOldSlots = oldSlots
? [...oldSlots].sort((a, b) => a.id - b.id)
: [];
const sortedNewSlots = newSlots
? [...newSlots].sort((a, b) => a.id - b.id)
: [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old and new slots should be defined according to their types

Comment on lines 9 to 11
if (newSlots.length !== oldSlots.length) {
changes += newSlots.length - oldSlots.length;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it would subtract if there were less new slots than old ones, even though normally it shouldn't happen. Still, it feels sensible to wrap this in Math.abs

Copy link
Collaborator

@jakubcolony jakubcolony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I accidentally submitted my previous review too soon. Adding a few more comments

@@ -52,6 +52,7 @@ fragment Expenditure on Expenditure {
filter: {
or: [
{ type: { eq: MOVE_FUNDS } }
{ type: { eq: MOVE_FUNDS_MOTION } }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason behind adding this? Did you come across some funding motions misclassified as move funds?

Comment on lines 48 to 49
const [editValues, setEditValues] = useState<
ExpenditurePayoutFieldValue[] | undefined
>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could that be moved to expenditure-specific component, such as PaymentBuilderEdit?

() =>
object()
.shape({
payments: array()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost the same as validation in src/components/v5/common/ActionSidebar/partials/forms/PaymentBuilderForm/hooks.ts. Is there a way to reuse it?

if (!createdAt || !transactionHash) return;

const fundingActionTime = new Date(createdAt);
const actionKey = `${createdAt}-${transactionHash}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transactionHash, for now, is a unique identifier of an action so you can just use that

Comment on lines 3 to 4
import { type ExpenditureActionFragment, ExpenditureStatus } from '~gql';
import { type ExpenditureAction, type Expenditure } from '~types/graphql.ts';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExpenditureActionFragment is the same as ExpenditureAction

@CzarekDryl
Copy link
Contributor Author

@jakubcolony When you click to view the changes, the modified items are at the top of the table and separated by a blue line. This is the desired behavior.
image

Copy link
Member

@arrenv arrenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @CzarekDryl, coming along well! I noticed the following:

  1. If you click on the meatball menu, it sits under the action timeline.
    image

  2. Can we remove the bold on the dash, align the values and max the font size of all text the same at text-3 to match the design.
    image

  3. I also removed a recipient row completely, is there any way to see that? When returning, as I can see it says 4 changes, but clicking on it shows only 3 recipients changed.
    image

  4. I did a change where I removed leela, then funded, then went into edit mode again and I can see leela again in the list, removed rows should not show up again if removed. It also causes issues with validation and I need to remove it again.
    image

  5. Submitting that second change using Reputation did not have any affect, the motion did not show up despite the transaction succeeding. It did show up if using Permissions.
    image

  6. Increasing the total amount did prompt another funding step, meaning the payment was not fully funded, but allowed me to go to the Release step, however, that fails as the payment was not fully funded.
    image

@CzarekDryl
Copy link
Contributor Author

@arrenv Everything except the last point has been fixed because I cannot reproduce it
image

@CzarekDryl CzarekDryl requested a review from arrenv December 5, 2024 11:20
@davecreaser
Copy link
Contributor

Hey @CzarekDryl - looks like this one needs another rebase. I tried to test it by editing an advanced payment but got an error, maybe a rebase will fix it?

Screenshot 2025-01-03 at 10 33 56 Screenshot 2025-01-03 at 10 35 15 Screenshot 2025-01-03 at 10 36 42

@iamsamgibbs
Copy link
Contributor

I know this PR has been kicking around for a while now so would be good to get it rebased and we can try to get it pushed through!

I just wanted to leave a comment here as I've noticed whilst doing another piece of work that the editExpenditure saga does not use the same "chunked multicall" approach as the createExpenditure saga so I suspect it is likely that editing an expenditure with over 164 slots will fail as the transaction receipt will be too large. Once this PR is refactored we should test editing an expenditure with a large number of payments and open a new issue if we need to make these changes to the editExpenditure saga.

@rdig rdig requested a review from a team January 21, 2025 08:31
Copy link
Contributor

@iamsamgibbs iamsamgibbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First off, great work on this very complicated issue, there is a LOT going on here.

A lot of it is working great, I'm able to edit at the correct stage of the process, the edit button does not appear for users without permissions, validation messages are showing correctly, etc. On to the issues though, I'm sure some of these could just be handled as separate issues, it maybe even makes sense to make this a mini feature branch just to handle all the cases here.

The number of recipients in the subtitle is not updating correctly. I think it's maybe just not accounting for the rows where the amount is 0.

Screenshot 2025-01-21 at 10 57 53

There is an issue with the slotId not being properly set.

Screenshot 2025-01-21 at 10 32 38

There is an issue with the accordion rows on the changes view not closing properly.

Screenshot 2025-01-21 at 11 11 28

Here is a video:

Screen.Recording.2025-01-21.at.10.40.34.mov

The blue border is also having some issues:

Screen.Recording.2025-01-21.at.10.42.07.mov

There should be a "No changes have been made" validation error if you click the "Make changes" button without making any changes.

Screen.Recording.2025-01-21.at.10.48.02.mov

The additional funding steps also failed to show for me when I added an extra payment row resulting in failed release transaction.

Screen.Recording.2025-01-21.at.10.51.53.mov

I'm not sure if this is intended or not, but I think rows which have been removed in previous edits should not continue to show in future edits. (So for this example, Amy was removed in the first edit, then in the second edit the amount for Leela was changed. When viewing the second edit, I don't think Amy should show at all.)

Screenshot 2025-01-21 at 11 10 53

The change request buttons should be disabled whilst edit mode is active.

Screen.Recording.2025-01-21.at.11.15.06.mov

As mentioned in my previous comment, I suspect there will be issues with large payments over 164 rows, but we'll have to check this once the slotId issue is resolved.

Thanks again though for your work on this so far!

CzarekDryl and others added 3 commits February 14, 2025 15:14
fixes after rebase

fix: translations, table borders

Fix: Editing expenditure to not change slot IDs or override recipients

Chore: Add comments with guidance on edit expenditure implementation

Update ingestor image hash

fix: table styles

fix: remove unused prop

CR fixes

fixes after rebase

fix: edit changes
@adam-strzelec
Copy link
Contributor

@iamsamgibbs I fixed all comments from the list except the error that occurs after release transaction. I have no idea what it is caused by. I don't know if it's on the frontend or backend side, but I noticed that it occurs if we remove the row before the Funding step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Payment builder - Edit action - After Locked state - Action Creator path with Permissions
6 participants