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

[Proxy Colonies] Feat: Proxy colony balance validation #4253

Open
wants to merge 4 commits into
base: feat/M3-proxy-colonies
Choose a base branch
from

Conversation

iamsamgibbs
Copy link
Contributor

@iamsamgibbs iamsamgibbs commented Feb 5, 2025

Description

This PR adds validation for balances on a proxy chain to the simple payment action (and should work for other actions once those forms have been updated).

It also fixes an issue with the fetchTokenFromChain lambda which was returning a malformed token due to the fragment changes.

Testing

  • Step 1 - Create a "Manage supported chain" action to add proxy chain 1.

Screenshot 2025-01-31 at 11 50 31

  • Step 2 - Switch your metamask wallet to proxy chain 1 (follow the steps in [Proxy colonies] Handle incoming funds #4174 if you haven't already set it up)
  • Step 3 - Copy the colony address and send tokens via metamask to the colony.

Screenshot 2025-01-31 at 11 54 51

  • Step 4 - Deploy a token to the proxy chain, mint tokens and add it as an approved token.

In your terminal, run node scripts/deploy-token-to-chain.js
Please use the following values for the input
foreignChainId 265669101
foreignChainRpcUrl http://localhost:8546
colonyAddress <COLONY_ADDRESS_HERE>

Then we must mint some tokens to generate our incoming funds. Copy the token address that was printed to the console and paste it somewhere to access later.

Run node scripts/unlock-mint-tokens-on-chain.js
Please use the following values for the input
foreignChainRpcUrl http://localhost:8546
colonyAddress <COLONY_ADDRESS_HERE>
tokenAddress <TOKEN_ADDRESS_YOU_COPIED_FROM_THE_CONSOLE>
tokenAmount 100

Then we need to add this as an approved token, otherwise it won't show in the incoming funds list. The "manage tokens" action has yet to be updated to support this, so we must manually add it to the database. In GraphiQL, run this query:

mutation MyMutation {
  createColonyTokens(input: {tokenID: "<TOKEN_ADDRESS>", colonyID: "<COLONY_ADDRESS>"})
}

Screenshot 2025-01-31 at 12 04 39

Screenshot 2025-01-31 at 12 00 19

  • Step 7 - Back to the balances page, check that the newly claimed tokens are shown.

Screenshot 2025-01-31 at 12 00 35

  • Step 8 - Create a simple payment action. In the "From" field, select the proxy chain. In the "Amount" field, select a token and enter an amount higher than the available balance. Check the error validation shows. Then check it disappears with an amount below the available balance.

Screenshot 2025-02-06 at 09 49 10

  • Step 9 - Switch the "From" field to the "Ganache" main chain. (Note: The amount is not revalidated when switching chains or domains (the same is true on master for domains) - this should be handled as a separate issue.) Enter a new amount and check the validation works as expected.

Screenshot 2025-02-06 at 09 49 24

Diffs

New stuff

  • Balances are now validated correctly for proxy chain balances

Changes 🏗

  • Fix token structure in fetchTokenByChain lambda

Resolves #4193

@iamsamgibbs iamsamgibbs self-assigned this Feb 5, 2025
Base automatically changed from feat/4189-simple-payment-proxies to feat/M3-proxy-colonies February 6, 2025 08:54
Comment on lines +208 to +212
const proxyChainTokens = tokens.filter(
(token) => token.token.chainMetadata.chainId === proxyChainId,
);

proxyChainTokens.map(async ({ token }) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't bother mapping through tokens that don't exist on this chain where the balances will definitely be 0.

@iamsamgibbs iamsamgibbs force-pushed the feat/4193-proxy-colony-balance-validation branch from e99564e to 3ae3485 Compare February 6, 2025 14:47
@iamsamgibbs iamsamgibbs marked this pull request as ready for review February 6, 2025 14:53
@iamsamgibbs iamsamgibbs requested a review from a team as a code owner February 6, 2025 14:53
@iamsamgibbs iamsamgibbs changed the title Feat: Proxy colony balance validation [Proxy Colonies] Feat: Proxy colony balance validation Feb 6, 2025
Copy link
Member

@rdig rdig left a comment

Choose a reason for hiding this comment

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

Good to go

Copy link
Contributor

@mmioana mmioana left a comment

Choose a reason for hiding this comment

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

Really nice work @iamsamgibbs 🎉 the amount field is validated based on the available funds on each chain
Screenshot 2025-02-07 at 13 42 51

Screen.Recording.2025-02-07.at.13.43.20.mov

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.

[Proxy colonies M3] feat: implement form validation of a proxy colony's balance
3 participants