Skip to content
This repository was archived by the owner on Feb 9, 2024. It is now read-only.
This repository was 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

Description

@DoubleOTheven

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions