Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

UI & Backend improvements to the Mesh Security testing UI#2

Draft
josefleventon wants to merge 15 commits into
CosmWasm:mainfrom
josefleventon:main
Draft

UI & Backend improvements to the Mesh Security testing UI#2
josefleventon wants to merge 15 commits into
CosmWasm:mainfrom
josefleventon:main

Conversation

@josefleventon

@josefleventon josefleventon commented Oct 5, 2022

Copy link
Copy Markdown

Draft!

This PR aims to overhaul the current MS UI.

  • An app-wide client allows all of the contract clients to be stored (and created) once instead of every time a transaction needs to be completed.
  • A transaction context allows tx's to be fired easily across the app without needing to use the client.
  • Queries and execute messages can be saved in the client folder and reused across the app. (Componentization for reoccurring transactions!)

To Do (Backend)

  • Create app client
  • Create transaction context
  • Create executemsgs for app client
  • Create queries for app client (Won't be necessary)
  • Use app client in provider
  • Use app client in consumer

To Do (UI)

  • Navigation
  • Transition to TailwindCSS

Will add more to the lists as I go.

@ethanfrey ethanfrey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this PR and sorry it took so long to find the space to review properly.

I appreciate all the new components and new transaction handling. I have a few main change requests:

  • The whole client/core/* files seem like unnecessary levels of abstraction around the ts-codegen client, and need maintenance every time a new method is added. This is what codegen is trying to remove. Let's get rid of those and just call the ts-codegen objects directly in the components.
  • This "build message" and "submit message" separation seems a bit unnatural to me. But I do see how you need it to handle toasts properly. I made one suggestion to make it a bit cleaner IMO. If you can use your method with minimal handwritten code per method that doesn't come from codegen then I will look again - maybe it is the better way
  • You update all the contract addresses. Did you change network? Why the redeploy? Old contracts should be usable permissionlessly. If you have a reason for the deploy, please add as a comment and also link which commit hash was there.

Comment thread client/contexts/MeshProvider.tsx
meshProviderClient.contractAddress,
)

const msg = meshProviderComposer.unstake({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How much value does this have over calling the SigningProviderClient wrapper itself?
I like the ts-codegen APIs and a lot of people get use to them. I would not wrap them without good reason.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

To be honest it's more for the sake of code being organized.

Client methods go into client/ and page content into pages/.

@@ -0,0 +1,27 @@
import type { MeshLockupClient } from 'codegen/MeshLockup.client'
import { MeshLockupMessageComposer } from 'codegen/MeshLockup.message-composer'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Huh? Message-composer? never used those. why not just call directly?

Comment thread client/core/index.ts
if (!chain) return
const contracts = {
junotestnet: [
this.createMeshConsumerClient,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

None of these are async.

Creating the SigningCosmWasmClient is async and needs it's hooks. (what you do in connectSigning).

The rest of these helpers (eg. signingMetaStakingClient) are simple sync constructors and can be called as normal functions. No need for caching and hooks here IMO.
The

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

We wait for the init to be completed here:

const completed = await Promise.all(initClients)

Function won't complete until all of them have been initialized. IMO this is more efficient that individually awaiting every one of them. Also want to avoid initializing clients right before they are needed, will take some time off of queries and will also save some resources. Every MB of memory matters!

@@ -0,0 +1,395 @@
/**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are you using the message-composers everywhere?

You can just use the SigningClients.

Message Composers are great for when you want to eg. prepare some message for a DAO to execute. But let's just execute them now (well, send them to keplr, where it asks for use approval)

Comment thread components/wallet.tsx
@@ -1,181 +1,127 @@
import { useWallet } from '@cosmos-kit/react';
import { MouseEventHandler, useEffect, useMemo } from 'react'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This file is pure create-cosmos-app afaik.
I would upstream any changes here to that. Calling @pyramation

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

My goal here was to restyle the components here to use TailwindCSS. The original buttons are ChakraUI and include some data that is not necessary to this specific application. create-cosmos-app is the boilerplate for us to adapt to our needs :)

Comment thread config/contracts.ts
meshSlasherAddr: "osmo1fewayl23e89rkejx932ljxf0ylsmtqc49r4myzzsvxcpweptmu0szshpkv"
};
meshLockupAddr:
'osmo1nhenmvnx25v66ww0mzv6mgcyqzl963ld8cclyvyd0wqrukfnhr8s05tkkk',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wait, why did you change the addresses here? Did you redeploy?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Jake redeployed these contracts, were missing some queries.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah, we will change them again soon when I redeploy the latest.

Comment thread config/contracts.ts
metaStakingAddr: "juno15tuw2fdyl666j7569ynt9dpdqykwzqw4d4sxrf0smcezudeafedsqu7n97",
meshConsumerAddr: "juno12e2p5rgcmcgu2t63mwystxzlfwf50kpgn9gjlnz2sf6q76pnkcjqrna22u",
meshConsumerPort: "wasm.juno12e2p5rgcmcgu2t63mwystxzlfwf50kpgn9gjlnz2sf6q76pnkcjqrna22u"
metaStakingAddr:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here. Where are new addresses from?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Jake redeployed these contracts, were missing some queries.

Comment thread contexts/tx.tsx
) => {
// Gas config
const fee = {
amount: coins(0, 'uosmo'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems like bad overrides. I think keplr has better pre-chain defaults.
Why not remove this from the client, and just let keplr do it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We use fee: 'auto' to defer to keplr

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Pretty sure 'auto' throws an error when using signingCosmWasmCleint.broadcastTx but will look into it. You can also override the default gas in the context's options object when calling tx().

Comment thread contexts/tx.tsx
tx: () => new Promise(() => {}),
})

export function TxProvider({ children }: { children: ReactNode }) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ahhh.... this is why you build messages, so you can have one submit item here.

Hmmm... I get the idea and feedback, but I still don't like all the indirection around just calling the client.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about some function that would be called:

await doTx(async () => meshLockupClient.stake({amount: "1000", validator: "juno1swfuihwiufh"}));

It could set up the toasts and then call the passed function, capturing errors or success and doing the toasts.

I feel this is much cleaner than trying to add all kind of changes to each generation event and then submitting them in some custom way. We can avoid a lot of the hand-written client code, and rather just add a few lines around each action to ensure toasts are shown

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

We don't want to the toasts to show when the message hasn't been broadcast yet.
MessageComposer & then signingCosmWasmClient.broadcastTx is the only way to do this.

Think of the user flow as following:

Press button -> Keplr popup -> Broadcast -> "Broadcasting..." toast -> Success!

In my opinion this is optimal & better UX.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants