Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Add helper functions to easily display customized messages for a contract transaction #30

Open
DoubleOTheven opened this issue Mar 30, 2023 · 0 comments

Comments

@DoubleOTheven
Copy link
Contributor

DoubleOTheven commented Mar 30, 2023

Feature Request

Define a good design pattern to handle status messages then create helper functions to make it easy.

const tx = useContractTx(...) sets a variable that can use a signAndSend() functions to initiate a wallet signature and contract transaction like this tx.signAndSend(...args).

We can then track the status with tx.status, which will change from 'NONE', to 'PENDING_SIGNATURE', to 'IN_BLOCK', etc. It is very common to set a button to disabled and change the title if a transaction status is not 'NONE' or 'FINALIZED'.

Suggestion

We should create a helper function that returns a formatted string. e.g.

<button
  onClick={flipTx.signAndSend}
  disabled={shouldDisable(flipTx)}                 
>
  {toStatusName(fipTx)}
</button>

where toStatusName(flipTx) will return "Please sign the transaction to flip!"` for 'PENDING_SIGNATURE', then "Flipping..." when the status is 'IN_BLOCK', etc. Messages should be customizable and allow for 18n.

Do we provide defaults? Can a user define generic ones such as "Pending signature" for 'PENDING_SIGNATURE' status?

Motivation

Simplify a very common use case.

Use Cases

Building a UI for any contract transaction.

@DoubleOTheven DoubleOTheven changed the title Add helper functions for displaying Transaction status of a contract Add helper functions to easily display customized messages for a contract transaction Mar 30, 2023
@nicolad nicolad mentioned this issue Apr 5, 2023
3 tasks
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 a pull request may close this issue.

1 participant