1.7.1 • Published 4 months ago

@trustswap/web-widgets v1.7.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

Team Finance widget collection

This is a collection of widgets related to Team Finance ecosystem.

Powered by

Getting Started

You will need:

  • NodeJS latest LTS version. Actually it also works with Node 18, but latest LTS is recommended. On Linux / Mac, we recommend using nodenv

Deploy with Docker

WIP, but the simplest command should be:

docker build -f Dockerfile -t tf-widgets .
docker run -it --rm -d -p 8080:80 --name=tf-widgets-impl tf-widgets

How to test locally

  1. Clone the project:
git clone https://github.com/trustswap/teamfinance-widgets.git
cd teamfinance-widgets
  1. Install dependencies:
npm i
  1. Add the pool info:

Create an .env file in the root of this project with following information. This is just a sample, you should bring your own pool id, chain id,... if you want to test with your own token. You can change the app.tsx file as a playground with the widget settings and props:

VITE_STAKING_POOL_ADDRESS="0x0f2A5800f9Da5Fc765D28d64b554036b58fA8156"
# Leo token
VITE_STAKING_POOL_ID=0
VITE_STAKING_CHAIN_ID=97
  1. Run the dev server
npm run build:library
npm run dev

Your dev server should be live in http://localhost:5173/ .

Usage - Staking Widget

Using npm

Here’s how you can integrate the widget into your project:

Install the package:

npm i @trustswap/web-widgets

or

yarn add @trustswap/web-widgets

then use it:

import { StakingWidget } from "@trustswap/web-widgets";

const chainId = 97;
const poolAddress = "YOUR_CONTRACT_ADDRESS";
const poolId = 1;

export default function App() {
  return (
    <StakingWidget
      chainId={chainId}
      poolId={poolId}
      stakingPoolAddress={poolAddress}
      themeConfig={{
        primaryColor: "#bf6636",
        container: "#F6F6FA",
      }}
    />
  );
}

Alternatively, you can import the StakingWidget module only, so your bundle size will be smaller:

import StakingWidget from "@trustswap/web-widgets/staking";

Note that bundle size is quite large because of bundled styling (from Mantine) and the RainbowKit library. A trimmed version is planned.

Using embeddable JS script

Please refer to test.html for the usage. This project use Web Component so it can be used in any websites, not just React.

You need to add 2 HTML tags for it to work though. First is the script, it looks like:

<script
  src="https://widgets.team.finance/assets/js/staking-widget.js"
  type="module"
></script>

the second is the Web Component placeholder, which is like:

<teamfinance-staking-widget
  staking-pool-address="staking-address"
  pool-id="4"
  chain-id="97"
/>
PropWebComponent AttributeUsageRequired
stakingPoolAddressstaking-pool-addressThe staking pool contract addressYes
poolIdpool-idThe default pool ID to display. It must be provided even if poolIds is presentedYes
chainIdchain-idChain ID, in number format.Yes
poolIdspool-idsAn array of Pool IDs. If provided, the widget will show a list of pool for the user to choose from. In following format: [{"poolId": number, "poolLabel": string}]No
customTitlecustom-titleA string that override default widget's titleNo

Usage - Vesting Widget

Using npm

Here’s how you can integrate the widget into your project:

Install the package:

npm i @trustswap/web-widgets

or

yarn add @trustswap/web-widgets

then use it:

import { VestingWidget } from "@trustswap/web-widgets";

const chainId = 97;
const tokenAddress = "Ox";
const apiKey = "Your_API_Key";

export default function App() {
  return (
    <VestingWidget
      chainId={chainId}
      tokenAddress={tokenAddress}
      customTokenImageUrl="TOKEN_IMAGE_URL"
      apiKey={apiKey}
    />
  );
}

Alternatively, you can import the StakingWidget module only, so your bundle size will be smaller:

import VestingWidget from "@trustswap/web-widgets/vesting";

Note that bundle size is quite large because of bundled styling (from Mantine) and the RainbowKit library. A trimmed version is planned.

Using embeddable JS script

If you are using embeddable JS script:

<script
  src="https://widgets.team.finance/assets/js/vesting-widget.js"
  type="module"
></script>
<teamfinance-vesting-widget
  api-key="YOUR_API_KEY"
  token-address="0xb091b669f3f..."
  chain-id="97"
  custom-token-image-url="TOKEN_IMAGE_URL"
/>
PropWebComponent AttributeUsageRequired
apiKeyapi-keyThe provided API Key for the widget, contact our support team to get one.Yes
tokenAddresstoken-addressThe token address to filter the list of vestings.No
chainIdchain-idDefault chain ID, in number format.No
customTokenImageUrlcustom-token-image-urlReplace the default token image with this.No

Testing

This project uses Vitest and Playwright.

Inside that directory, you can run several commands:

Runs the end-to-end tests.

npx playwright test

Starts the interactive UI mode.

npx playwright test --ui

Runs the tests only on Desktop Chrome.

npx playwright test --project=chromium

Runs the tests in a specific file.

npx playwright test example

Runs the tests in debug mode.

npx playwright test --debug

Auto generate tests with Codegen.

npx playwright codegen

We suggest that you begin by typing:

npx playwright test

Contributing

  1. Checkout a branch from develop branch and create a PR from there.
  2. Change the code.
  3. Run the lint, using npm run lint. Lefthook does this automatically for you but it's a good practice to do it usually.
  4. Create a PR with short but easy to understand description.
  5. If you want to make a release, bump the version in package.json. It will be auto-published if its version is different with current NPM version.
1.7.1

4 months ago

1.6.1

4 months ago

1.6.0

4 months ago

1.5.8

4 months ago

1.5.7

4 months ago

1.5.6

5 months ago

1.5.5

5 months ago

1.5.4

5 months ago

1.5.3

5 months ago

1.7.0

4 months ago

1.5.2

5 months ago

1.5.1

5 months ago

1.5.0

5 months ago

1.4.7

5 months ago

1.4.6

5 months ago

1.4.5

6 months ago

1.4.4

6 months ago

1.4.3

6 months ago

1.4.2-beta.5

6 months ago

1.4.2-beta.4

6 months ago

1.4.2-beta.3

6 months ago

1.4.2-beta.1

7 months ago

1.4.2-beta.2

7 months ago

1.4.2

7 months ago

1.4.3-alpha.0

7 months ago

1.4.1

8 months ago

1.4.0

8 months ago

1.3.1

8 months ago

1.3.0-beta.1

9 months ago

1.3.0-beta.2

9 months ago

1.3.0-beta.3

8 months ago

1.3.0-beta.4

8 months ago

1.3.0-beta.5

8 months ago

1.2.6

10 months ago

1.2.0

1 year ago

1.2.5

12 months ago

1.2.4

12 months ago

1.2.3

12 months ago

1.2.1

12 months ago

1.1.41

1 year ago

1.1.40

1 year ago

1.1.42

1 year ago

1.1.38

1 year ago

1.1.37

1 year ago

1.1.36

1 year ago

1.1.39

1 year ago

1.1.35

1 year ago

1.1.34

1 year ago

1.1.29

1 year ago

1.1.28

1 year ago

1.1.30

1 year ago

1.1.33

1 year ago

1.1.32

1 year ago

1.1.31

1 year ago

1.1.27

1 year ago

1.1.26

1 year ago

1.1.25

1 year ago

1.1.24

1 year ago

1.1.23

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.12

1 year ago

1.1.10

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.22

1 year ago

1.1.21

1 year ago

1.1.20

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago