2021-05-16 17:53:57 -07:00
|
|
|
# `@project-serum/swap-ui`
|
2021-05-12 10:57:22 -07:00
|
|
|
|
2021-05-16 17:53:57 -07:00
|
|
|
[![Build Status](https://travis-ci.com/project-serum/swap-ui.svg?branch=master)](https://travis-ci.com/project-serum/swap-ui)
|
|
|
|
[![npm](https://img.shields.io/npm/v/@project-serum/swap-ui.svg)](https://www.npmjs.com/package/@project-serum/swap-ui)
|
|
|
|
|
|
|
|
A reusable React component for swapping on the Serum DEX. The Solana program can be
|
2021-05-21 14:58:01 -07:00
|
|
|
found [here](https://github.com/project-serum/swap).
|
2021-05-16 17:53:57 -07:00
|
|
|
|
2021-05-21 15:42:20 -07:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
#### Install
|
|
|
|
|
|
|
|
First install the required peer dependencies into your React project.
|
|
|
|
|
|
|
|
```
|
|
|
|
yarn add @material-ui/core @material-ui/icons @material-ui/lab @project-serum/anchor @solana/spl-token-registry @solana/web3.js material-ui-popup-state react-async-hook
|
|
|
|
```
|
|
|
|
|
|
|
|
Then install the package.
|
|
|
|
|
|
|
|
```
|
|
|
|
yarn add @project-serum/swap-ui
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Add the Swap Component
|
|
|
|
|
|
|
|
To embed the `Swap` component into your application,
|
|
|
|
one can minimally provide an [Anchor](https://github.com/project-serum/anchor)
|
|
|
|
[Provider](https://project-serum.github.io/anchor/ts/classes/provider.html)
|
|
|
|
and [TokenListContainer](https://github.com/solana-labs/token-list).
|
|
|
|
For example,
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
<Swap provider={provider} tokenList={tokenList} />
|
|
|
|
```
|
|
|
|
|
|
|
|
All of the complexity of communicating with the Serum DEX and managing
|
|
|
|
its data is handled internally by the component.
|
|
|
|
|
|
|
|
#### Referral Fees
|
|
|
|
|
|
|
|
To earn referral fees, one can also pass in a `referral` property,
|
|
|
|
which is the `PublicKey` of the Solana wallet that *owns* the associated
|
|
|
|
token accounts in which referral fees are paid (i.e., USDC and USDT).
|
|
|
|
|
2021-05-16 17:53:57 -07:00
|
|
|
## Developing
|
|
|
|
|
|
|
|
#### Install dependencies
|
|
|
|
|
|
|
|
```
|
|
|
|
yarn
|
|
|
|
```
|
|
|
|
|
2021-05-21 14:58:01 -07:00
|
|
|
#### Build
|
2021-05-16 17:53:57 -07:00
|
|
|
|
|
|
|
```
|
2021-05-21 14:58:01 -07:00
|
|
|
yarn build
|
2021-05-16 17:53:57 -07:00
|
|
|
```
|
|
|
|
|
2021-05-21 14:58:01 -07:00
|
|
|
## Run the example app
|
2021-05-16 17:53:57 -07:00
|
|
|
|
2021-05-21 14:58:01 -07:00
|
|
|
For local development and educational purposes, a minimal React app is provided
|
|
|
|
in the `example/` subdirectory.
|
2021-05-16 17:53:57 -07:00
|
|
|
|
2021-05-21 14:58:01 -07:00
|
|
|
To run, change directories via `cd example/` and start the app.
|
|
|
|
|
|
|
|
### Start the app
|
2021-05-16 17:53:57 -07:00
|
|
|
|
|
|
|
```
|
2021-05-21 14:58:01 -07:00
|
|
|
yarn start
|
2021-05-16 17:53:57 -07:00
|
|
|
```
|