ClawDEX UI
The ClawDEX UI is a web frontend used for interacting with the ClawDEX Smart Contracts on ClawChain.
Development
This project is using:
Requirements:
- node v14
- npm v7
For environment settings, you should create a .env.local file. You can copy the existing template (cp .env.template .env.local) in order to do so:
NEXT_PUBLIC_API_CLASSIC=
NEXT_PUBLIC_GQL_CLASSIC=
If you have nvm installed, you should select the correct npm version for your environment based on the .nvmrc. Note that v14 ships with npm v6 and you'll need to update npm with npm install -g npm@7.
npm run dev
Runs the app in development mode.
npm test
Launches the test runner in the interactive watch mode.
Notifications & Transaction Tracking
ClawDEX UI provides a notification system that uses Toast-style notifications to provide feedback to the user.
Notifications can be added via the addNotification function returned by the useClawDEX hook.
Notification payloads include a type and other attributes, defined in the notifications model.
The "started" notification type is a special type, which increases the "Pending Transactions" count and tracks the transaction through to success or failure. (see TransactionStarted)
Transaction-related notifications (including "started" notifications) are handled for you automatically when using the useTx or useTransaction hooks (more below).
Posting Transactions
ClawDEX UI provides two hooks designed to simplify transaction posting:
useTx-- Thin wrapper around the wallet provider'spostfunction. Can be configured withonPosting,onBroadcasting, andonErrorlifecycle hooks. Returns asubmitfunction that accepts Messages and a Fee. Hooks into ClawDEX's notification and transaction tracking systems to provide feedback to the user via Toast notifications.useTransaction-- Higher-level hook that provides message debouncing, automatic fee calculation, and lifecycle state. Internally usesuseTxto post. Can be configured withonBroadcastingandonErrorlifecycle hooks. Returns some state and asubmitfunction to post the transaction.
Adding new transactions
When adding new transactions to the ClawDEX UI, the following tasks must be completed:
- Select a new notification
txTypestring for the transaction. - Add a component for the body of successful notifications to components/notifications
- Add a case for the selected
txType(step 1) using the component from step 2 to therenderSuccessfulTxContentfunction in the Notifications component. - Add the
typeandnotifications.dataobject type definition to theUseTxNotificationDetailstype in the useTx hook. - (optional) Add a custom title for transaction post error notifications to the
errorNotificationTitlefunction in the useTx hook.