├── .eslintignore ├── .eslintrc.js ├── .github └── workflows │ ├── gh-pages.yml │ └── tests.yml ├── .gitignore ├── CONTRIBUTING.md ├── DEVELOP.md ├── LICENSE ├── README.md ├── assets └── images │ ├── rainbow-icon.png │ ├── rainbow-og.png │ └── rainbow.png ├── example ├── .gitignore ├── .npmignore ├── App.css ├── Dapp.tsx ├── assets │ ├── images │ │ ├── arbitrum.png │ │ ├── ethereum.png │ │ ├── optimism.png │ │ └── polygon.png │ └── rainbow-og.png ├── dapps │ ├── constants │ │ └── index.tsx │ ├── helpers │ │ ├── accounts.tsx │ │ └── eip712.ts │ ├── store.ts │ └── v1 │ │ ├── hooks.ts │ │ └── index.tsx ├── fonts │ ├── subset-SFRounded-Bold.eot │ ├── subset-SFRounded-Bold.svg │ ├── subset-SFRounded-Bold.woff │ ├── subset-SFRounded-Bold.woff2 │ ├── subset-SFRounded-Heavy.eot │ ├── subset-SFRounded-Heavy.svg │ ├── subset-SFRounded-Heavy.woff │ ├── subset-SFRounded-Heavy.woff2 │ ├── subset-SFRounded-Medium.eot │ ├── subset-SFRounded-Medium.svg │ ├── subset-SFRounded-Medium.woff │ ├── subset-SFRounded-Medium.woff2 │ ├── subset-SFRounded-Regular.eot │ ├── subset-SFRounded-Regular.svg │ ├── subset-SFRounded-Regular.woff │ ├── subset-SFRounded-Regular.woff2 │ ├── subset-SFRounded-Semibold.eot │ ├── subset-SFRounded-Semibold.svg │ ├── subset-SFRounded-Semibold.woff │ └── subset-SFRounded-Semibold.woff2 ├── index.html ├── index.tsx ├── package.json ├── styled.tsx ├── tsconfig.json └── yarn.lock ├── package.json ├── src ├── components │ ├── EmojiPop.tsx │ ├── QRExpandedState.tsx │ ├── button │ │ ├── ConnectButton.tsx │ │ └── ConnectButtonV1.tsx │ └── qrcode │ │ ├── QRCard.tsx │ │ └── QRCode.tsx ├── constants │ └── index.ts ├── helpers │ └── deeplink.ts ├── icons │ ├── ButtonLabel.tsx │ ├── LogoAppStore.tsx │ └── XButton.tsx ├── index.tsx ├── styled │ └── index.tsx ├── typings.d.ts └── utils │ └── index.ts ├── tsconfig.json ├── tsdx.config.js └── yarn.lock /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .cache 3 | dist 4 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['rainbow'], 3 | overrides: [ 4 | { 5 | files: ['example/**'], 6 | rules: { 7 | 'import/no-extraneous-dependencies': 'off', 8 | }, 9 | }, 10 | ], 11 | }; 12 | -------------------------------------------------------------------------------- /.github/workflows/gh-pages.yml: -------------------------------------------------------------------------------- 1 | name: Deploy to gh-pages 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 7 | 8 | 9 | 10 | jobs: 11 | deploy: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2.3.4 16 | 17 | - name: Use Node.js 18 | uses: actions/setup-node@v2 19 | with: 20 | node-version: lts/* 21 | - run: yarn 22 | - name: Build and deploy website 23 | run: | 24 | cd example 25 | yarn 26 | yarn build 27 | cd .. 28 | - name: Deploy 29 | uses: peaceiris/actions-gh-pages@v3 30 | with: 31 | github_token: ${{ secrets.GITHUB_TOKEN }} 32 | publish_dir: ./example/dist 33 | force_orphan: true 34 | keep_files: false 35 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: tests 3 | 4 | on: [pull_request, push] 5 | 6 | jobs: 7 | test: 8 | runs-on: ${{ matrix.os }} 9 | 10 | strategy: 11 | matrix: 12 | os: [ubuntu-latest] 13 | node: ['lts/*'] 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Use Node.js ${{ matrix.node-version }} 18 | uses: actions/setup-node@v2 19 | with: 20 | node-version: ${{ matrix.node-version }} 21 | - run: yarn 22 | - run: cd example && yarn && cd .. 23 | - run: yarn lint 24 | - run: yarn test 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | 25 | dist 26 | *.tgz 27 | 28 | example/.cache 29 | 30 | package-lock.json 31 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Rainbow button is a React component library written in Typescript using the [`tsdx`](https://tsdx.io) toolchain. 4 | 5 | ## Building 6 | 7 | ```console 8 | # in the root of the repo 9 | yarn 10 | yarn run build 11 | ``` 12 | 13 | ## Developing 14 | 15 | ```console 16 | # in the root of the repo 17 | yarn 18 | yarn start 19 | ``` 20 | 21 | This will automatically regenerate the library wheny you make changes to it. 22 | 23 | ## Testing 24 | 25 | Make sure the tests pass on contributions. Using the linter within your editor will help catch bugs early. 26 | 27 | ```console 28 | yarn test 29 | yarn lint 30 | ``` 31 | 32 | ## Example 33 | 34 | See [./example](./example) code for an simple implementation example that is deployed to [rainbow-me.github.io/rainbow-button/](https://rainbow-me.github.io/rainbow-button/). 35 | 36 | To run the example locally, you can do the folliwing: 37 | 38 | ```console 39 | # in the root of the repo 40 | yarn 41 | # build rainbow-button library 42 | yarn build 43 | cd example 44 | rm -rf node_modules yarn.lock dist 45 | yarn 46 | yarn start 47 | ``` 48 | 49 | *Note:* This copies the locally built rainbow-button into `example/node_modules`. If you would like to modify `rainbow-button` and have the changes relfected automatically in the running example, you need to link `rainbow-button` with `rainbow-botton/example`. 50 | 51 | ```console 52 | # in the root of the repo 53 | yarn 54 | yarn link 55 | yarn watch 56 | ``` 57 | 58 | In another console 59 | 60 | ```console 61 | cd example 62 | yarn 63 | yarn link @rainbow-me/rainbow-button 64 | yarn start 65 | ``` 66 | -------------------------------------------------------------------------------- /DEVELOP.md: -------------------------------------------------------------------------------- 1 | # TSDX React w/ Storybook User Guide 2 | 3 | Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it. 4 | 5 | > This TSDX setup is meant for developing React component libraries (not apps!) that can be published to NPM. If you’re looking to build a React-based app, you should use `create-react-app`, `razzle`, `nextjs`, `gatsby`, or `react-static`. 6 | 7 | > If you’re new to TypeScript and React, checkout [this handy cheatsheet](https://github.com/sw-yx/react-typescript-cheatsheet/) 8 | 9 | ## Commands 10 | 11 | TSDX scaffolds your new library inside `/src`, and also sets up a [Parcel-based](https://parceljs.org) playground for it inside `/example`. 12 | 13 | The recommended workflow is to run TSDX in one terminal: 14 | 15 | ```bash 16 | npm start # or yarn start 17 | ``` 18 | 19 | This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`. 20 | 21 | Then run either Storybook or the example playground: 22 | 23 | ### Storybook 24 | 25 | Run inside another terminal: 26 | 27 | ```bash 28 | yarn storybook 29 | ``` 30 | 31 | This loads the stories from `./stories`. 32 | 33 | > NOTE: Stories should reference the components as if using the library, similar to the example playground. This means importing from the root project directory. This has been aliased in the tsconfig and the storybook webpack config as a helper. 34 | 35 | ### Example 36 | 37 | Then run the example inside another: 38 | 39 | ```bash 40 | cd example 41 | npm i # or yarn to install dependencies 42 | npm start # or yarn start 43 | ``` 44 | 45 | The default example imports and live reloads whatever is in `/dist`, so if you are seeing an out of date component, make sure TSDX is running in watch mode like we recommend above. **No symlinking required**, we use [Parcel's aliasing](https://parceljs.org/module_resolution.html#aliases). 46 | 47 | To do a one-off build, use `npm run build` or `yarn build`. 48 | 49 | To run tests, use `npm test` or `yarn test`. 50 | 51 | ## Configuration 52 | 53 | Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly. 54 | 55 | ### Jest 56 | 57 | Jest tests are set up to run with `npm test` or `yarn test`. 58 | 59 | ### Bundle analysis 60 | 61 | Calculates the real cost of your library using [size-limit](https://github.com/ai/size-limit) with `npm run size` and visulize it with `npm run analyze`. 62 | 63 | #### Setup Files 64 | 65 | This is the folder structure we set up for you: 66 | 67 | ```txt 68 | /example 69 | index.html 70 | index.tsx # test your component here in a demo app 71 | package.json 72 | tsconfig.json 73 | /src 74 | index.tsx # EDIT THIS 75 | /test 76 | blah.test.tsx # EDIT THIS 77 | /stories 78 | Thing.stories.tsx # EDIT THIS 79 | /.storybook 80 | main.js 81 | preview.js 82 | .gitignore 83 | package.json 84 | README.md # EDIT THIS 85 | tsconfig.json 86 | ``` 87 | 88 | #### React Testing Library 89 | 90 | We do not set up `react-testing-library` for you yet, we welcome contributions and documentation on this. 91 | 92 | ### Rollup 93 | 94 | TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details. 95 | 96 | ### TypeScript 97 | 98 | `tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs. 99 | 100 | ## Continuous Integration 101 | 102 | ### GitHub Actions 103 | 104 | Two actions are added by default: 105 | 106 | - `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix 107 | - `size` which comments cost comparison of your library on every pull request using [size-limit](https://github.com/ai/size-limit) 108 | 109 | ## Optimizations 110 | 111 | Please see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations: 112 | 113 | ```js 114 | // ./types/index.d.ts 115 | declare var __DEV__: boolean; 116 | 117 | // inside your code... 118 | if (__DEV__) { 119 | console.log('foo'); 120 | } 121 | ``` 122 | 123 | You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions. 124 | 125 | ## Module Formats 126 | 127 | CJS, ESModules, and UMD module formats are supported. 128 | 129 | The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found. 130 | 131 | ## Deploying the Example Playground 132 | 133 | The Playground is just a simple [Parcel](https://parceljs.org) app, you can deploy it anywhere you would normally deploy that. Here are some guidelines for **manually** deploying with the Netlify CLI (`npm i -g netlify-cli`): 134 | 135 | ```bash 136 | cd example # if not already in the example folder 137 | npm run build # builds to dist 138 | netlify deploy # deploy the dist folder 139 | ``` 140 | 141 | Alternatively, if you already have a git repo connected, you can set up continuous deployment with Netlify: 142 | 143 | ```bash 144 | netlify init 145 | # build command: yarn build && cd example && yarn && yarn build 146 | # directory to deploy: example/dist 147 | # pick yes for netlify.toml 148 | ``` 149 | 150 | ## Named Exports 151 | 152 | Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library. 153 | 154 | ## Including Styles 155 | 156 | There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinion on this, configure how you like. 157 | 158 | For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader. 159 | 160 | ## Publishing to NPM 161 | 162 | We recommend using [np](https://github.com/sindresorhus/np). 163 | 164 | ## Usage with Lerna 165 | 166 | When creating a new package with TSDX within a project set up with Lerna, you might encounter a `Cannot resolve dependency` error when trying to run the `example` project. To fix that you will need to make changes to the `package.json` file _inside the `example` directory_. 167 | 168 | The problem is that due to the nature of how dependencies are installed in Lerna projects, the aliases in the example project's `package.json` might not point to the right place, as those dependencies might have been installed in the root of your Lerna project. 169 | 170 | Change the `alias` to point to where those packages are actually installed. This depends on the directory structure of your Lerna project, so the actual path might be different from the diff below. 171 | 172 | ```diff 173 | "alias": { 174 | - "react": "../node_modules/react", 175 | - "react-dom": "../node_modules/react-dom" 176 | + "react": "../../../node_modules/react", 177 | + "react-dom": "../../../node_modules/react-dom" 178 | }, 179 | ``` 180 | 181 | An alternative to fixing this problem would be to remove aliases altogether and define the dependencies referenced as aliases as dev dependencies instead. [However, that might cause other problems.](https://github.com/palmerhq/tsdx/issues/64) 182 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Esteban Miño 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rainbow Button 🌈 2 | [![npm version](https://img.shields.io/npm/v/@rainbow-me/rainbow-button.svg)](https://npmjs.org/package/@rainbow-me/rainbow-button) 3 | [![Actions Status](https://github.com/rainbow-me/rainbow-button/workflows/tests/badge.svg)](https://github.com/rainbow-me/rainbow-button/actions) 4 | 5 | Rainbow Button is a react component that renders an opinionated button built on top of [WalletConnect](https://walletconnect.org/) v1 which allows you to connect to [Rainbow](https://rainbow.me/) on mobile (via Mobile Deeplinking) and desktop (via QR codes). 6 | 7 | ## Demo Dapp 8 | 9 | 🌎 [Demo Link](https://rainbow-me.github.io/rainbow-button) 10 | 11 | ## Install 12 | 13 | ``` 14 | 15 | yarn add @rainbow-me/rainbow-button 16 | 17 | ``` 18 | 19 | **Required peerDependencies:** 20 | 21 | The following packages also need to be installed along side `@rainbow/rainbow-button`. 22 | 23 | - `@walletconnect/client@>=1.6.0` 24 | - `react@>=16` 25 | 26 | ## How to use 27 | 28 | ```js 29 | import React from 'react'; 30 | import ReactDOM from 'react-dom'; 31 | import { RainbowButton } from '@rainbow-me/rainbow-button'; 32 | 33 | ReactDOM.render( 34 | console.log(connector)} 38 | />, 39 | document.getElementById('rainbowButton') 40 | ); 41 | ``` 42 | 43 | ## Rainbow button without styling or custom button 44 | 45 | ```js 46 | ReactDOM.render( 47 | console.log(connector)} 51 | customButton={() => } 52 | />, 53 | document.getElementById('rainbowButton') 54 | ); 55 | ``` 56 | 57 | ## RainbowButton Props 58 | 59 | | params | value | default value | description | 60 | | ---------------------- | -------- | ------------- | ---------------------------------------------------------------------------------- | 61 | | chainId | number | REQUIRED | Rainbow supported chainId | 62 | | connectorOptions | object | REQUIRED | _Wallet Connect_ `connector` options. `bridge` param is required | 63 | | onConnectorInitialized | function | REQUIRED | Will be called when the button is instantiated, will return the `connector` object | 64 | | customButton | function | - | Render prop to use a custom element | 65 | | animate | boolean | true | Whether or not animate the button | 66 | 67 | ## onConnectorInitialized callback 68 | 69 | This callback will return a `WalletConnect` connector object, you should store it and use it as a normal `WalletConnect` client object. 70 | 71 | ## Initiate connection and listen to events 72 | 73 | ```js 74 | const onConnectorInitialized = useCallback( 75 | (connector) => { 76 | setConnector(connector); 77 | }, 78 | [setConnector] 79 | ); 80 | 81 | // Subscribe to connection events and update your app accordingly 82 | 83 | const subscribeToEvents = useCallback(() => { 84 | connector.on('connect', (error, payload) => { 85 | if (error) { 86 | throw error; 87 | } 88 | // Get provided accounts and chainId 89 | const { accounts, chainId } = payload.params[0]; 90 | }); 91 | 92 | connector.on('session_update', (error, payload) => { 93 | if (error) { 94 | throw error; 95 | } 96 | // Get updated accounts and chainId 97 | const { accounts, chainId } = payload.params[0]; 98 | }); 99 | 100 | connector.on('disconnect', (error, payload) => { 101 | if (error) { 102 | throw error; 103 | } 104 | // Delete connector 105 | setConnector(null); 106 | }); 107 | }, [connector]); 108 | ``` 109 | 110 | More details can be found in the Wallet Connect docs: 111 | 112 | - [Wallet Connect client](https://docs.walletconnect.org/quick-start/dapps/client) 113 | 114 | ## Exported assets 115 | 116 | ```js 117 | import { assets } from '@rainbow-me/rainbow-button'; 118 | 119 | ReactDOM.render( 120 |
121 | 122 | 123 |
, 124 | document.getElementById('assets') 125 | ); 126 | ``` 127 | 128 | ## Exported utils 129 | 130 | ```js 131 | import { utils } from '@rainbow-me/rainbow-button'; 132 | 133 | // Triggers a deeplink to go to the app. Only mobile. 134 | utils.goToRainbow(); 135 | ``` 136 | 137 | ## Exported constants 138 | 139 | ```js 140 | import { constants } from '@rainbow-me/rainbow-button'; 141 | 142 | console.log('Rainbow supported chain ids', constants.SUPPORTED_MAIN_CHAIN_IDS); 143 | console.log( 144 | 'Rainbow supported test chain ids', 145 | constants.SUPPORTED_TEST_CHAIN_IDS 146 | ); 147 | ``` 148 | 149 | ## Contributing 150 | 151 | See [CONTRIBUTING.md](./CONTRIBUTING.md) 152 | -------------------------------------------------------------------------------- /assets/images/rainbow-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/assets/images/rainbow-icon.png -------------------------------------------------------------------------------- /assets/images/rainbow-og.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/assets/images/rainbow-og.png -------------------------------------------------------------------------------- /assets/images/rainbow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/assets/images/rainbow.png -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | /node_modules 4 | /.cache 5 | /dist 6 | -------------------------------------------------------------------------------- /example/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .cache 3 | dist -------------------------------------------------------------------------------- /example/App.css: -------------------------------------------------------------------------------- 1 | .text-center { 2 | text-align: center; 3 | } 4 | 5 | @font-face { 6 | font-family: SFRounded; 7 | src: url(/fonts/subset-SFRounded-Regular.eot); 8 | src: url(/fonts/subset-SFRounded-Regular.eot?#iefix) 9 | format('embedded-opentype'), 10 | url(/fonts/subset-SFRounded-Regular.woff2) format('woff2'), 11 | url(/fonts/subset-SFRounded-Regular.woff) format('woff'), 12 | url(/fonts/subset-SFRounded-Regular.svg#SFRounded-Regular) format('svg'); 13 | font-weight: 400; 14 | font-style: normal; 15 | font-display: auto; 16 | } 17 | 18 | @font-face { 19 | font-family: SFRounded; 20 | src: url(/fonts/subset-SFRounded-Medium.eot); 21 | src: url(/fonts/subset-SFRounded-Medium.eot?#iefix) 22 | format('embedded-opentype'), 23 | url(/fonts/subset-SFRounded-Medium.woff2) format('woff2'), 24 | url(/fonts/subset-SFRounded-Medium.woff) format('woff'), 25 | url(/fonts/subset-SFRounded-Medium.svg#SFRounded-Medium) format('svg'); 26 | font-weight: 500; 27 | font-style: normal; 28 | font-display: auto; 29 | } 30 | 31 | @font-face { 32 | font-family: SFRounded; 33 | src: url(/fonts/subset-SFRounded-Semibold.eot); 34 | src: url(/fonts/subset-SFRounded-Semibold.eot?#iefix) 35 | format('embedded-opentype'), 36 | url(/fonts/subset-SFRounded-Semibold.woff2) format('woff2'), 37 | url(/fonts/subset-SFRounded-Semibold.woff) format('woff'), 38 | url(/fonts/subset-SFRounded-Semibold.svg#SFRounded-Semibold) format('svg'); 39 | font-weight: 600; 40 | font-style: normal; 41 | font-display: auto; 42 | } 43 | 44 | @font-face { 45 | font-family: SFRounded; 46 | src: url(/fonts/subset-SFRounded-Bold.eot); 47 | src: url(/fonts/subset-SFRounded-Bold.eot?#iefix) format('embedded-opentype'), 48 | url(/fonts/subset-SFRounded-Bold.woff2) format('woff2'), 49 | url(/fonts/subset-SFRounded-Bold.woff) format('woff'), 50 | url(/fonts/subset-SFRounded-Bold.svg#SFRounded-Bold) format('svg'); 51 | font-weight: 700; 52 | font-style: normal; 53 | font-display: auto; 54 | } 55 | 56 | @font-face { 57 | font-family: SFRounded; 58 | src: url(/fonts/subset-SFRounded-Heavy.eot); 59 | src: url(/fonts/subset-SFRounded-Heavy.eot?#iefix) format('embedded-opentype'), 60 | url(/fonts/subset-SFRounded-Heavy.woff2) format('woff2'), 61 | url(/fonts/subset-SFRounded-Heavy.woff) format('woff'), 62 | url(/fonts/subset-SFRounded-Heavy.svg#SFRounded-Heavy) format('svg'); 63 | font-weight: 800; 64 | font-style: normal; 65 | font-display: auto; 66 | } 67 | 68 | body { 69 | -moz-osx-font-smoothing: grayscale; 70 | -webkit-font-smoothing: antialiased; 71 | -webkit-text-size-adjust: 100%; 72 | font-family: SFRounded, ui-rounded, SF Pro Rounded, system-ui, Helvetica Neue, 73 | Arial, Helvetica, sans-serif; 74 | font-size: 16px; 75 | font-weight: 400; 76 | position: relative; 77 | text-rendering: optimizeLegibility; 78 | } 79 | 80 | html, 81 | body { 82 | height: 100%; 83 | } 84 | 85 | html { 86 | display: table; 87 | margin: auto; 88 | } 89 | 90 | body { 91 | display: table-cell; 92 | } 93 | 94 | h1 { 95 | color: #25292e; 96 | font-size: 3.75em; 97 | font-weight: 800; 98 | line-height: 1.1em; 99 | margin: 60px auto 30px; 100 | max-width: 666px; 101 | padding: 0 60px; 102 | text-align: center; 103 | } 104 | 105 | p { 106 | color: rgba(60, 66, 82, 0.8); 107 | font-size: 23px; 108 | font-weight: bold; 109 | margin-right: 10px; 110 | } 111 | 112 | .network-icon { 113 | margin-bottom: -8px; 114 | width: 42px; 115 | } 116 | 117 | .ethereum { 118 | margin-bottom: -1px; 119 | margin-left: 10px; 120 | margin-right: 10px; 121 | width: 20px; 122 | } 123 | -------------------------------------------------------------------------------- /example/Dapp.tsx: -------------------------------------------------------------------------------- 1 | import 'react-app-polyfill/ie11'; 2 | import * as React from 'react'; 3 | import './App.css'; 4 | import { useMemo, useState } from 'react'; 5 | import DappV1 from './dapps/v1'; 6 | import { Button, Wrapper } from './styled'; 7 | 8 | const Dapp = () => { 9 | const [version, setVersion] = useState('v1'); 10 | 11 | const renderDapp = useMemo(() => { 12 | if (version === 'v1') return ; 13 | }, [version]); 14 | 15 | return ( 16 |
17 |

Rainbow Button Dapp

18 | {version && renderDapp} 19 | {!version && ( 20 |
21 |

Choose a RainbowButton

22 | 23 | 30 | 31 |
32 | )} 33 |
34 | ); 35 | }; 36 | 37 | export default Dapp; 38 | -------------------------------------------------------------------------------- /example/assets/images/arbitrum.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/assets/images/arbitrum.png -------------------------------------------------------------------------------- /example/assets/images/ethereum.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/assets/images/ethereum.png -------------------------------------------------------------------------------- /example/assets/images/optimism.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/assets/images/optimism.png -------------------------------------------------------------------------------- /example/assets/images/polygon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/assets/images/polygon.png -------------------------------------------------------------------------------- /example/assets/rainbow-og.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/assets/rainbow-og.png -------------------------------------------------------------------------------- /example/dapps/constants/index.tsx: -------------------------------------------------------------------------------- 1 | export const SUPPORTED_METHODS = [ 2 | 'eth_sendTransaction', 3 | 'personal_sign', 4 | 'eth_signTypedData', 5 | ]; 6 | 7 | export const supportedMainChainsInfoEip155 = { 8 | 'eip155:1': { color: '#0E76FD', name: 'Ethereum Mainnet' }, 9 | 'eip155:10': { color: '#FF4040', name: 'Optimism' }, 10 | 'eip155:137': { color: '#8247E5', name: 'Polygon' }, 11 | 'eip155:42161': { color: '#2D374B', name: 'Arbitrum' }, 12 | }; 13 | 14 | export const supportedMainChainsInfo = { 15 | '1': { 16 | color: '#0E76FD', 17 | iconWidth: '20', 18 | name: 'Ethereum', 19 | value: 'ethereum', 20 | }, 21 | '10': { 22 | color: '#FF4040', 23 | iconWidth: '42', 24 | name: 'Optimism', 25 | value: 'optimism', 26 | }, 27 | '137': { 28 | color: '#8247E5', 29 | iconWidth: '42', 30 | name: 'Polygon', 31 | value: 'polygon', 32 | }, 33 | // '42161': { name: "Arbitrum", color: '#2D374B', value: "arbitrum", iconWidth: "42"}, 34 | }; 35 | -------------------------------------------------------------------------------- /example/dapps/helpers/accounts.tsx: -------------------------------------------------------------------------------- 1 | export async function formatTestTransactionExperimental(account: string) { 2 | const [, , /*chainId*/ address] = account.split(':'); 3 | 4 | // gasLimit 5 | const gasLimit = '0x5208'; 6 | 7 | // value 8 | const value = '0x0'; 9 | 10 | const tx = { data: '0x', from: address, gasLimit, to: address, value }; 11 | 12 | return tx; 13 | } 14 | 15 | export async function formatTestTransaction(address: string) { 16 | // gasLimit 17 | const gasLimit = '0x5208'; 18 | 19 | // value 20 | const value = '0x0'; 21 | 22 | const tx = { data: '0x', from: address, gasLimit, to: address, value }; 23 | 24 | return tx; 25 | } 26 | 27 | export const renderAddress = (address = '') => { 28 | return [address.substring(0, 4), address.substring(address.length - 4)].join( 29 | '...' 30 | ); 31 | }; 32 | -------------------------------------------------------------------------------- /example/dapps/helpers/eip712.ts: -------------------------------------------------------------------------------- 1 | const example = { 2 | domain: { 3 | chainId: 42, 4 | name: 'GSN Relayed Transaction', 5 | verifyingContract: '0x6453D37248Ab2C16eBd1A8f782a2CBC65860E60B', 6 | version: '1', 7 | }, 8 | message: { 9 | encodedFunction: 10 | '0xa9059cbb0000000000000000000000002e0d94754b348d208d64d52d78bcd443afa9fa520000000000000000000000000000000000000000000000000000000000000007', 11 | gasData: { 12 | baseRelayFee: '0', 13 | gasLimit: '39507', 14 | gasPrice: '1700000000', 15 | pctRelayFee: '70', 16 | }, 17 | relayData: { 18 | paymaster: '0x957F270d45e9Ceca5c5af2b49f1b5dC1Abb0421c', 19 | relayWorker: '0x3baee457ad824c94bd3953183d725847d023a2cf', 20 | senderAddress: '0x22d491bde2303f2f43325b2108d26f1eaba1e32b', 21 | senderNonce: '3', 22 | }, 23 | target: '0x9cf40ef3d1622efe270fe6fe720585b4be4eeeff', 24 | }, 25 | primaryType: 'RelayRequest', 26 | types: { 27 | EIP712Domain: [ 28 | { name: 'name', type: 'string' }, 29 | { name: 'version', type: 'string' }, 30 | { name: 'verifyingContract', type: 'address' }, 31 | ], 32 | GasData: [ 33 | { name: 'gasLimit', type: 'uint256' }, 34 | { name: 'gasPrice', type: 'uint256' }, 35 | { name: 'pctRelayFee', type: 'uint256' }, 36 | { name: 'baseRelayFee', type: 'uint256' }, 37 | ], 38 | RelayData: [ 39 | { name: 'senderAddress', type: 'address' }, 40 | { name: 'senderNonce', type: 'uint256' }, 41 | { name: 'relayWorker', type: 'address' }, 42 | { name: 'paymaster', type: 'address' }, 43 | ], 44 | RelayRequest: [ 45 | { name: 'target', type: 'address' }, 46 | { name: 'encodedFunction', type: 'bytes' }, 47 | { name: 'gasData', type: 'GasData' }, 48 | { name: 'relayData', type: 'RelayData' }, 49 | ], 50 | }, 51 | }; 52 | 53 | export const eip712 = { 54 | example, 55 | }; 56 | -------------------------------------------------------------------------------- /example/dapps/store.ts: -------------------------------------------------------------------------------- 1 | import WalletConnect from '@walletconnect/client'; 2 | import { createStore } from 'redux'; 3 | 4 | const SET_CONNECTOR = 'SET_CONNECTOR'; 5 | const SET_ACCOUNTS = 'SET_ACCOUNTS'; 6 | const SET_CHAIN_ID = 'SET_CHAIN_ID'; 7 | 8 | export const setConnector = (connector: WalletConnect | null) => ({ 9 | payload: connector, 10 | type: SET_CONNECTOR, 11 | }); 12 | 13 | export const setAccounts = (accounts: string[] | null) => ({ 14 | payload: accounts, 15 | type: SET_ACCOUNTS, 16 | }); 17 | 18 | export const setChainId = (chainId: string | null) => ({ 19 | payload: chainId, 20 | type: SET_CHAIN_ID, 21 | }); 22 | 23 | const INITIAL_STATE = { 24 | accounts: undefined, 25 | chainId: undefined, 26 | connector: undefined, 27 | }; 28 | 29 | const reducer = (state = INITIAL_STATE, action) => { 30 | switch (action.type) { 31 | case SET_CONNECTOR: 32 | return { ...state, connector: action.payload }; 33 | case SET_ACCOUNTS: 34 | return { ...state, accounts: action.payload }; 35 | case SET_CHAIN_ID: 36 | return { ...state, chainId: action.payload }; 37 | default: 38 | return state; 39 | } 40 | }; 41 | 42 | export const store = createStore(reducer); 43 | -------------------------------------------------------------------------------- /example/dapps/v1/hooks.ts: -------------------------------------------------------------------------------- 1 | import WalletConnect from '@walletconnect/client'; 2 | import { useDispatch, useSelector } from 'react-redux'; 3 | import { createSelector } from 'reselect'; 4 | import { 5 | setAccounts as rawSetAccounts, 6 | setChainId as rawSetChainId, 7 | setConnector as rawSetConnector, 8 | } from '../store'; 9 | 10 | const selector = createSelector( 11 | ({ connector, accounts, chainId }) => ({ accounts, chainId, connector }), 12 | ({ connector, accounts, chainId }) => { 13 | return { 14 | accounts, 15 | chainId, 16 | connector, 17 | }; 18 | } 19 | ); 20 | 21 | export default function useWalletConnectState() { 22 | const { connector, accounts, chainId } = useSelector(selector); 23 | 24 | const dispatch = useDispatch(); 25 | 26 | const setConnector = (connector: WalletConnect | null) => 27 | dispatch(rawSetConnector(connector)); 28 | const setAccounts = (accounts: string[] | null) => 29 | dispatch(rawSetAccounts(accounts)); 30 | const setChainId = (chainId: string | null) => 31 | dispatch(rawSetChainId(chainId)); 32 | 33 | return { 34 | accounts, 35 | chainId, 36 | connector, 37 | setAccounts, 38 | setChainId, 39 | setConnector, 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /example/dapps/v1/index.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | import 'react-app-polyfill/ie11'; 3 | import { constants, RainbowButton, utils } from '@rainbow-me/rainbow-button'; 4 | import { isMobile } from '@walletconnect/browser-utils'; 5 | import * as encUtils from 'enc-utils'; 6 | import { utils as ethersUtils } from 'ethers'; 7 | import * as React from 'react'; 8 | import { useCallback, useEffect, useMemo, useState } from 'react'; 9 | import { ActionButton, Button, Wrapper } from '../../styled'; 10 | import { supportedMainChainsInfo } from '../constants'; 11 | import { formatTestTransaction, renderAddress } from '../helpers/accounts'; 12 | import { eip712 } from '../helpers/eip712'; 13 | import useWalletConnectState from '../v1/hooks'; 14 | 15 | const { goToRainbow } = utils; 16 | const { SUPPORTED_MAIN_CHAIN_IDS } = constants; 17 | 18 | const images = { 19 | /* eslint-disable import/no-commonjs */ 20 | arbitrum: require('../../assets/images/arbitrum.png'), 21 | ethereum: require('../../assets/images/ethereum.png'), 22 | optimism: require('../../assets/images/optimism.png'), 23 | polygon: require('../../assets/images/polygon.png'), 24 | /* eslint-enable import/no-commonjs */ 25 | }; 26 | 27 | const Dapp = () => { 28 | const { 29 | connector, 30 | accounts, 31 | chainId, 32 | setConnector, 33 | setAccounts, 34 | setChainId, 35 | } = useWalletConnectState(); 36 | const [selectedChain, setSelectedChain] = useState(null); 37 | 38 | const selectChain = useCallback((chain) => setSelectedChain(chain), []); 39 | 40 | const onConnectorInitialized = useCallback( 41 | (connector) => setConnector(connector), 42 | [] /* eslint-disable-line react-hooks/exhaustive-deps */ 43 | ); 44 | 45 | useEffect(() => { 46 | if (!connector) return; 47 | 48 | // Capture initial connector state 49 | setAccounts(connector.accounts); 50 | setChainId(connector.chainId); 51 | 52 | // Subscribe to connection events 53 | connector.on('connect', (error, payload) => { 54 | if (error) { 55 | throw error; 56 | } 57 | 58 | // Get provided accounts and chainId 59 | const { accounts, chainId } = payload.params[0]; 60 | setAccounts(accounts); 61 | setChainId(chainId); 62 | }); 63 | 64 | connector.on('session_update', (error, payload) => { 65 | if (error) { 66 | throw error; 67 | } 68 | 69 | // Get updated accounts and chainId 70 | const { accounts, chainId } = payload.params[0]; 71 | setAccounts(accounts); 72 | setChainId(chainId); 73 | }); 74 | 75 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 76 | connector.on('disconnect', (error, payload) => { 77 | if (error) { 78 | throw error; 79 | } 80 | 81 | // Delete connector 82 | // IMPORTANT if users reject the session request you have to 83 | // create a new session from scratch. `disconnect` will trigger 84 | // in that case 85 | setConnector(null); 86 | setAccounts(null); 87 | setChainId(null); 88 | setSelectedChain(null); 89 | }); 90 | }, [connector]); /* eslint-disable-line react-hooks/exhaustive-deps */ 91 | 92 | const sendTransaction = useCallback(async () => { 93 | if (!connector) return; 94 | try { 95 | const tx = await formatTestTransaction(accounts?.[0]); 96 | 97 | isMobile() && goToRainbow(); 98 | const result = await connector.sendTransaction(tx); 99 | console.log('RESULT', result); 100 | } catch (error) { 101 | console.error(error); 102 | } 103 | }, [connector, accounts]); 104 | 105 | const disconnect = useCallback( 106 | async () => connector?.killSession(), 107 | [connector] 108 | ); 109 | 110 | const signMessage = useCallback(async () => { 111 | if (!connector) return; 112 | try { 113 | const message = `Hello from Rainbow! `; 114 | const hexMsg = encUtils.utf8ToHex(message, true); 115 | const address = accounts?.[0]; 116 | const params = [address, hexMsg]; 117 | 118 | // send message 119 | isMobile() && goToRainbow(); 120 | const result = await connector.signMessage(params); 121 | const splitSignature = ethersUtils.splitSignature(result); 122 | const res = ethersUtils.verifyMessage(message, splitSignature); 123 | console.log('RESULT', result); 124 | console.log('Address verified', res === address); 125 | } catch (error) { 126 | console.error(error); 127 | } 128 | }, [connector, accounts]); 129 | 130 | const signPersonalMessage = useCallback(async () => { 131 | if (!connector) return; 132 | try { 133 | const message = `Hello from Rainbow! `; 134 | const hexMsg = encUtils.utf8ToHex(message, true); 135 | const address = accounts?.[0]; 136 | const params = [hexMsg, address]; 137 | 138 | // send message 139 | isMobile() && goToRainbow(); 140 | const result = await connector.signPersonalMessage(params); 141 | const splitSignature = ethersUtils.splitSignature(result); 142 | const res = ethersUtils.verifyMessage(message, splitSignature); 143 | 144 | console.log('RESULT', result); 145 | console.log('Address verified', res === address); 146 | } catch (error) { 147 | console.error(error); 148 | } 149 | }, [connector, accounts]); 150 | 151 | const signTypedData = useCallback(async () => { 152 | if (!connector) return; 153 | try { 154 | const message = JSON.stringify(eip712.example); 155 | const address = accounts?.[0]; 156 | const params = [address, message]; 157 | 158 | // send message 159 | isMobile() && goToRainbow(); 160 | const result = await connector.signTypedData(params); 161 | console.log('RESULT', result); 162 | } catch (error) { 163 | console.error(error); 164 | } 165 | }, [connector, accounts]); 166 | 167 | const renderNotConnected = useMemo(() => { 168 | return ( 169 |
170 |

171 | {selectedChain 172 | ? `Selected chain id: ${selectedChain}` 173 | : `Select chain to use with the button`} 174 |

175 | {!selectedChain && ( 176 | 177 | {Object.values(SUPPORTED_MAIN_CHAIN_IDS).map( 178 | (chain) => 179 | supportedMainChainsInfo[chain]?.name && ( 180 | 188 | ) 189 | )} 190 | 191 | )} 192 | 193 | {selectedChain && ( 194 | Custom} 201 | /> 202 | )} 203 | 204 |
205 | ); 206 | /* eslint-disable-next-line react-hooks/exhaustive-deps */ 207 | }, [selectedChain, onConnectorInitialized]); 208 | 209 | const renderConnected = useMemo(() => { 210 | return ( 211 |
212 | 213 |

214 | Connected to {supportedMainChainsInfo[chainId]?.name} 215 |

216 |

Account: {renderAddress(accounts?.[0])}

217 |
218 | 219 | 220 | sendTransaction 221 | 222 | 223 | signMessage 224 | 225 | 226 | signPersonalMessage 227 | 228 | 229 | signTypedData 230 | 231 | 232 | 233 | 234 | Disconnect 235 | 236 | 237 |
238 | ); 239 | /* eslint-disable-next-line react-hooks/exhaustive-deps */ 240 | }, [chainId, accounts]); 241 | 242 | return ( 243 |
244 | {connector?.connected && accounts?.length 245 | ? renderConnected 246 | : renderNotConnected} 247 |
248 | ); 249 | }; 250 | 251 | export default Dapp; 252 | -------------------------------------------------------------------------------- /example/fonts/subset-SFRounded-Bold.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/fonts/subset-SFRounded-Bold.eot -------------------------------------------------------------------------------- /example/fonts/subset-SFRounded-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/fonts/subset-SFRounded-Bold.woff -------------------------------------------------------------------------------- /example/fonts/subset-SFRounded-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/fonts/subset-SFRounded-Bold.woff2 -------------------------------------------------------------------------------- /example/fonts/subset-SFRounded-Heavy.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/fonts/subset-SFRounded-Heavy.eot -------------------------------------------------------------------------------- /example/fonts/subset-SFRounded-Heavy.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/fonts/subset-SFRounded-Heavy.woff -------------------------------------------------------------------------------- /example/fonts/subset-SFRounded-Heavy.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/fonts/subset-SFRounded-Heavy.woff2 -------------------------------------------------------------------------------- /example/fonts/subset-SFRounded-Medium.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/fonts/subset-SFRounded-Medium.eot -------------------------------------------------------------------------------- /example/fonts/subset-SFRounded-Medium.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/fonts/subset-SFRounded-Medium.woff -------------------------------------------------------------------------------- /example/fonts/subset-SFRounded-Medium.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/fonts/subset-SFRounded-Medium.woff2 -------------------------------------------------------------------------------- /example/fonts/subset-SFRounded-Regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/fonts/subset-SFRounded-Regular.eot -------------------------------------------------------------------------------- /example/fonts/subset-SFRounded-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/fonts/subset-SFRounded-Regular.woff -------------------------------------------------------------------------------- /example/fonts/subset-SFRounded-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/fonts/subset-SFRounded-Regular.woff2 -------------------------------------------------------------------------------- /example/fonts/subset-SFRounded-Semibold.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/fonts/subset-SFRounded-Semibold.eot -------------------------------------------------------------------------------- /example/fonts/subset-SFRounded-Semibold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/fonts/subset-SFRounded-Semibold.woff -------------------------------------------------------------------------------- /example/fonts/subset-SFRounded-Semibold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainbow-me/rainbow-button/8216851e0691adbf3edf439066f6debbf9f6b8c5/example/fonts/subset-SFRounded-Semibold.woff2 -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Rainbow Button Dapp 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /example/index.tsx: -------------------------------------------------------------------------------- 1 | import 'react-app-polyfill/ie11'; 2 | import * as React from 'react'; 3 | import * as ReactDOM from 'react-dom'; 4 | import './App.css'; 5 | import { Provider } from 'react-redux'; 6 | import Dapp from './Dapp'; 7 | import { store } from './dapps/store'; 8 | 9 | const App = () => ; 10 | 11 | ReactDOM.render( 12 | 13 | 14 | , 15 | document.getElementById('root') 16 | ); 17 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "start": "parcel index.html", 8 | "build-dev": "yarn run build --no-minify", 9 | "build": "rm -rf dist/ && parcel build index.html --public-url ./", 10 | "push-gh-pages": "push-dir --dir=dist --branch=gh-pages --cleanup --verbose" 11 | }, 12 | "dependencies": { 13 | "@rainbow-me/rainbow-button": "../.", 14 | "@types/react-redux": "^7.1.18", 15 | "@walletconnect/client": "^1.6.1", 16 | "enc-utils": "^3.0.0", 17 | "lodash": "^4.17.21", 18 | "react-app-polyfill": "^1.0.0", 19 | "react-redux": "^7.2.4", 20 | "redux-persist": "^6.0.0", 21 | "reselect": "^4.0.0", 22 | "styled-components": "^5.3.0" 23 | }, 24 | "alias": { 25 | "react": "../node_modules/react", 26 | "react-dom": "../node_modules/react-dom/profiling", 27 | "scheduler/tracing": "../node_modules/scheduler/tracing-profiling" 28 | }, 29 | "devDependencies": { 30 | "@types/react": "^16.9.11", 31 | "@types/react-dom": "^16.8.4", 32 | "parcel": "^1.12.3", 33 | "parcel-bundler": "^1.12.5", 34 | "typescript": "^3.4.5", 35 | "push-dir": "^0.4.1" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /example/styled.tsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | export const Button = styled.a` 4 | -webkit-tap-highlight-color: transparent; 5 | -webkit-box-align: center; 6 | align-items: center; 7 | background: rgb(255, 255, 255); 8 | border-radius: 15px; 9 | box-shadow: rgb(37 41 46 / 10%) 0px 4px 12px; 10 | box-sizing: content-box; 11 | color: rgba(60, 66, 82, 0.8); 12 | cursor: pointer; 13 | display: flex; 14 | height: 28px; 15 | margin-bottom: 10px; 16 | margin-right: 10px; 17 | padding: 0px 16px 2px 2px; 18 | font-size: 16px; 19 | font-weight: 800; 20 | transition: all 0.125s ease 0s; 21 | user-select: none; 22 | will-change: transform; 23 | 24 | :hover { 25 | transform: scale(1.125); 26 | } 27 | :active { 28 | transform: scale(0.875); 29 | } 30 | `; 31 | 32 | export const ActionButton = styled.a` 33 | -webkit-tap-highlight-color: transparent; 34 | -webkit-box-align: center; 35 | align-items: center; 36 | background: rgb(255, 255, 255); 37 | border-radius: 15px; 38 | box-shadow: rgb(37 41 46 / 10%) 0px 4px 12px; 39 | box-sizing: content-box; 40 | color: rgba(60, 66, 82, 0.8); 41 | cursor: pointer; 42 | display: flex; 43 | height: 28px; 44 | padding: 0px 10px; 45 | margin: 10px 10px; 46 | font-size: 16px; 47 | font-weight: 800; 48 | transition: all 0.125s ease 0s; 49 | user-select: none; 50 | will-change: transform; 51 | 52 | :hover { 53 | transform: scale(1.125); 54 | } 55 | :active { 56 | transform: scale(0.875); 57 | } 58 | `; 59 | 60 | export const Wrapper = styled.div` 61 | display: flex; 62 | align-items: center; 63 | justify-content: center; 64 | flex-wrap: wrap; 65 | `; 66 | -------------------------------------------------------------------------------- /example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": false, 4 | "target": "es5", 5 | "module": "commonjs", 6 | "jsx": "react", 7 | "moduleResolution": "node", 8 | "noImplicitAny": false, 9 | "noUnusedLocals": false, 10 | "noUnusedParameters": false, 11 | "removeComments": true, 12 | "strictNullChecks": true, 13 | "preserveConstEnums": true, 14 | "sourceMap": true, 15 | "lib": ["es2015", "es2016", "dom"], 16 | "types": ["node"] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.2", 3 | "license": "MIT", 4 | "main": "dist/index.js", 5 | "typings": "dist/index.d.ts", 6 | "files": [ 7 | "dist", 8 | "src" 9 | ], 10 | "engines": { 11 | "node": ">=10" 12 | }, 13 | "scripts": { 14 | "start": "tsdx watch", 15 | "build": "tsdx build", 16 | "test": "tsdx test --passWithNoTests", 17 | "lint": "eslint . --ext js,ts,jsx,tsx", 18 | "prepare": "tsdx build", 19 | "size": "size-limit", 20 | "analyze": "size-limit --why", 21 | "clean-install": "rm -rf node_modules yarn.lock dist example/node_modules example/yarn.lock example/dist && yarn && cd example && yarn && yarn run build-dev" 22 | }, 23 | "peerDependencies": { 24 | "@walletconnect/client": ">=1.6.0", 25 | "react": ">=16" 26 | }, 27 | "husky": { 28 | "hooks": { 29 | "pre-commit": "tsdx lint" 30 | } 31 | }, 32 | "prettier": { 33 | "printWidth": 80, 34 | "semi": true, 35 | "singleQuote": true, 36 | "trailingComma": "es5" 37 | }, 38 | "name": "@rainbow-me/rainbow-button", 39 | "author": "Esteban Miño", 40 | "module": "dist/rainbow-button.esm.js", 41 | "size-limit": [ 42 | { 43 | "path": "dist/rainbow-button.cjs.production.min.js", 44 | "limit": "10 KB" 45 | }, 46 | { 47 | "path": "dist/rainbow-button.esm.js", 48 | "limit": "10 KB" 49 | } 50 | ], 51 | "devDependencies": { 52 | "@babel/core": "^7.14.8", 53 | "@rollup/plugin-image": "^2.1.0", 54 | "@size-limit/preset-small-lib": "^5.0.1", 55 | "@types/qrcode": "^1.4.1", 56 | "@types/react": "^17.0.14", 57 | "@types/react-dom": "^17.0.9", 58 | "@types/styled-components": "^5.1.6", 59 | "@typescript-eslint/eslint-plugin": "^4.31.2", 60 | "@walletconnect/client": "^1.6.1", 61 | "autoprefixer": "^10.3.1", 62 | "babel-loader": "^8.2.2", 63 | "cssnano": "^5.0.7", 64 | "eslint": "^7.32.0", 65 | "eslint-config-rainbow": "^2.0.1", 66 | "eslint-plugin-jest": "^24.4.2", 67 | "husky": "^7.0.1", 68 | "postcss": "^8.3.6", 69 | "prettier": "^2.4.1", 70 | "react": ">= 16.8.0", 71 | "react-dom": ">= 16.8.0", 72 | "react-is": ">= 16.8.0", 73 | "size-limit": "^5.0.1", 74 | "tsdx": "^0.14.1", 75 | "tslib": "^2.3.0", 76 | "typescript": "^4.4.3" 77 | }, 78 | "dependencies": { 79 | "@walletconnect/browser-utils": "^1.5.4", 80 | "@walletconnect/types": "^1.6.5", 81 | "ethers": "^5.5.2", 82 | "framer-motion": "^4.1.17", 83 | "qrcode": "^1.4.4", 84 | "styled-components": "^5.3.0" 85 | } 86 | } -------------------------------------------------------------------------------- /src/components/EmojiPop.tsx: -------------------------------------------------------------------------------- 1 | import { RAINBOW_BUTTON_ID } from '../constants'; 2 | 3 | interface Particle { 4 | element: HTMLSpanElement; 5 | size: number; 6 | speedHorz: number; 7 | speedUp: number; 8 | spinVal: number; 9 | spinSpeed: number; 10 | top: number; 11 | left: number; 12 | direction: number; 13 | } 14 | 15 | const validateEventPosition = ( 16 | mouseX: number, 17 | mouseY: number, 18 | rect?: DOMRect 19 | ) => { 20 | if (!rect) return; 21 | return ( 22 | mouseX > rect.x && 23 | mouseX < rect.x + rect.width && 24 | mouseY > rect.y && 25 | mouseY < rect.y + rect.height 26 | ); 27 | }; 28 | 29 | class Fountain { 30 | limit: number; 31 | particles: Particle[]; 32 | autoAddParticle: boolean; 33 | height: number; 34 | sizes: number[]; 35 | variants: string[]; 36 | mouseX: number; 37 | mouseY: number; 38 | rect?: DOMRect; 39 | 40 | constructor() { 41 | this.limit = 7; 42 | this.particles = []; 43 | this.autoAddParticle = false; 44 | this.height = document.documentElement.clientHeight; 45 | this.sizes = [15, 20, 25, 35, 45]; 46 | this.mouseX = 0; 47 | this.mouseY = 0; 48 | this.variants = ['🌈']; 49 | this.addHandlers(); 50 | this.loop(); 51 | this.rect = document 52 | ?.getElementById(RAINBOW_BUTTON_ID) 53 | ?.getBoundingClientRect(); 54 | } 55 | 56 | loop() { 57 | if ( 58 | validateEventPosition(this.mouseX, this.mouseY, this.rect) && 59 | this.autoAddParticle && 60 | this.particles.length < this.limit 61 | ) { 62 | this.createParticle(); 63 | } 64 | 65 | this.updateParticles(); 66 | 67 | requestAnimationFrame(this.loop.bind(this)); 68 | } 69 | 70 | addHandlers() { 71 | const isTouchInteraction = 72 | 'ontouchstart' in window || navigator.msMaxTouchPoints; 73 | 74 | const tap = isTouchInteraction ? 'touchstart' : 'mousedown'; 75 | const tapCancel = isTouchInteraction ? 'touchcancel' : 'contextmenu'; 76 | const tapEnd = isTouchInteraction ? 'touchend' : 'mouseup'; 77 | const move = isTouchInteraction ? 'touchmove' : 'mousemove'; 78 | 79 | document?.getElementById(RAINBOW_BUTTON_ID)?.addEventListener( 80 | move, 81 | (e) => { 82 | this.mouseX = e instanceof MouseEvent ? e.pageX : e.touches[0].pageX; 83 | this.mouseY = e instanceof MouseEvent ? e.pageY : e.touches[0].pageY; 84 | }, 85 | { passive: false } 86 | ); 87 | 88 | document 89 | ?.getElementById(RAINBOW_BUTTON_ID) 90 | ?.addEventListener(tap, (e: MouseEvent | TouchEvent) => { 91 | this.mouseX = e instanceof MouseEvent ? e.pageX : e.touches[0].pageX; 92 | this.mouseY = e instanceof MouseEvent ? e.pageY : e.touches[0].pageY; 93 | this.autoAddParticle = true; 94 | }); 95 | 96 | document.addEventListener(tapCancel, () => { 97 | this.autoAddParticle = false; 98 | }); 99 | 100 | document.addEventListener(tapEnd, () => { 101 | this.autoAddParticle = false; 102 | }); 103 | 104 | document.addEventListener('mouseleave', () => { 105 | this.autoAddParticle = false; 106 | }); 107 | } 108 | 109 | createParticle() { 110 | const size = this.sizes[Math.floor(Math.random() * this.sizes.length)]; 111 | const speedHorz = Math.random() * 7; 112 | const speedUp = Math.random() * 25; 113 | const spinVal = Math.random() * 360; 114 | const spinSpeed = Math.random() * 25 * (Math.random() <= 0.5 ? -1 : 1); 115 | const top = this.mouseY - size; 116 | const left = this.mouseX - size; 117 | const direction = Math.random() <= 0.5 ? -1 : 1; 118 | 119 | const particle = document.createElement('span'); 120 | particle.innerHTML = 121 | this.variants[Math.floor(Math.random() * this.variants.length)]; 122 | particle.classList.add('particle'); 123 | 124 | particle.setAttribute( 125 | 'style', 126 | ` 127 | -webkit-user-select: none; 128 | font-size: ${size}px; 129 | left: ${left}px; 130 | pointer-events: none; 131 | position: fixed; 132 | top: ${top}px; 133 | overflow: hidden; 134 | transform: rotate(${spinVal}deg); 135 | ` 136 | ); 137 | 138 | document?.documentElement?.appendChild(particle); 139 | 140 | this.particles.push({ 141 | direction, 142 | element: particle, 143 | left, 144 | size, 145 | speedHorz, 146 | speedUp, 147 | spinSpeed, 148 | spinVal, 149 | top, 150 | }); 151 | } 152 | 153 | updateParticles() { 154 | this.particles.forEach((p) => { 155 | p.left = p.left - p.speedHorz * p.direction; 156 | p.top = p.top - p.speedUp; 157 | p.speedUp = Math.min(p.size, p.speedUp - 1); 158 | p.spinVal = p.spinVal + p.spinSpeed; 159 | 160 | if (p.top > this.height - p.size) { 161 | this.particles = this.particles.filter((o) => o !== p); 162 | p.element.remove(); 163 | } 164 | 165 | p.element.setAttribute( 166 | 'style', 167 | ` 168 | -webkit-user-select: none; 169 | font-size: ${p.size}px; 170 | left: ${p.left}px; 171 | pointer-events: none; 172 | position: fixed; 173 | top: ${p.top}px; 174 | transform: rotate(${p.spinVal}deg); 175 | ` 176 | ); 177 | }); 178 | } 179 | } 180 | 181 | export default Fountain; 182 | -------------------------------------------------------------------------------- /src/components/QRExpandedState.tsx: -------------------------------------------------------------------------------- 1 | import { AnimatePresence, motion } from 'framer-motion'; 2 | import React, { Dispatch, SetStateAction } from 'react'; 3 | import LogoAppStore from '../icons/LogoAppStore'; 4 | import XButton from '../icons/XButton'; 5 | import { 6 | Column, 7 | Container, 8 | DownloadButton, 9 | DownloadContainer, 10 | ExpandedState, 11 | ExpandedStateBackground, 12 | TitleText, 13 | UniqueTokenExpandedStateContent, 14 | XButtonWrapper, 15 | } from '../styled'; 16 | import QRCode from './qrcode/QRCode'; 17 | 18 | const easingConfig = { 19 | duration: 0.125, 20 | ease: [0.25, 0.1, 0.25, 1], 21 | }; 22 | 23 | const springConfig = { 24 | damping: 45, 25 | mass: 1, 26 | stiffness: 700, 27 | type: 'spring', 28 | }; 29 | 30 | const QRExpandedState = ({ 31 | enabled, 32 | value, 33 | setIsQRCodeOpen, 34 | }: { 35 | enabled: boolean; 36 | value: string; 37 | setIsQRCodeOpen: Dispatch>; 38 | }) => { 39 | return ( 40 | 41 | {enabled && ( 42 | <> 43 | 44 | 50 | setIsQRCodeOpen(false)} 52 | opacity={0.8} 53 | /> 54 | 55 | 64 | setIsQRCodeOpen(false)} 66 | style={{ height: '100%', justifyContent: 'center' }} 67 | > 68 | 69 | 70 | 📲 71 | {' '} 72 | Scan to connect to Rainbow 73 | 74 | proxy.stopPropagation()}> 75 | 76 | 77 | 78 | 79 | 80 | 👇 81 | {' '} 82 | Don’t have the app yet?{' '} 83 | 84 | 👇 85 | 86 | 87 |
88 | proxy.stopPropagation()} 91 | target="_blank" 92 | > 93 |
94 | 95 |
96 | App Store 97 |
98 |
99 |
100 |
101 |
102 |
103 | setIsQRCodeOpen(false)}> 104 | 110 | 111 | 112 | 113 | 114 | )} 115 |
116 | ); 117 | }; 118 | 119 | export default QRExpandedState; 120 | -------------------------------------------------------------------------------- /src/components/button/ConnectButton.tsx: -------------------------------------------------------------------------------- 1 | import { isMobile } from '@walletconnect/browser-utils'; 2 | import React, { useCallback, useEffect, useMemo, useState } from 'react'; 3 | import rainbow_icon from '../../../assets/images/rainbow-icon.png'; 4 | import { RAINBOW_BUTTON_ID } from '../../constants'; 5 | import { constructDeeplink } from '../../helpers/deeplink'; 6 | import ButtonLabel from '../../icons/ButtonLabel'; 7 | import { Button, ButtonInner, Content, Logo } from '../../styled'; 8 | import Fountain from '../EmojiPop'; 9 | import QRExpandedState from '../QRExpandedState'; 10 | 11 | function ConnectButton({ 12 | uri, 13 | customButton, 14 | animate = true, 15 | }: { 16 | uri: string; 17 | customButton?: any; 18 | animate?: boolean; 19 | }) { 20 | const [showQRCode, setShowQRCode] = useState(false); 21 | 22 | const deeplink = useMemo(() => uri && constructDeeplink(uri), [uri]); 23 | 24 | const connectToRainbow = useCallback(() => { 25 | if (!deeplink) return; 26 | if (isMobile()) { 27 | window.location.href = deeplink; 28 | } else { 29 | setShowQRCode(true); 30 | } 31 | }, [deeplink]); 32 | 33 | useEffect(() => { 34 | animate && new Fountain(); 35 | }, [animate]); 36 | 37 | return ( 38 |
39 | 44 | {customButton ? ( 45 |
46 | {customButton} 47 |
48 | ) : ( 49 | 50 | 56 | 57 | )} 58 |
59 | ); 60 | } 61 | 62 | export default React.memo(ConnectButton); 63 | -------------------------------------------------------------------------------- /src/components/button/ConnectButtonV1.tsx: -------------------------------------------------------------------------------- 1 | import WalletConnect from '@walletconnect/client'; 2 | // eslint-disable-next-line import/no-unresolved 3 | import { IWalletConnectOptions } from '@walletconnect/types'; 4 | import React, { useEffect, useState } from 'react'; 5 | import ConnectButton from './ConnectButton'; 6 | 7 | function ConnectButtonV1({ 8 | chainId, 9 | connectorOptions, 10 | onConnectorInitialized, 11 | customButton, 12 | animate, 13 | }: { 14 | chainId: number | undefined; 15 | connectorOptions: IWalletConnectOptions; 16 | onConnectorInitialized: (client: WalletConnect) => void; 17 | customButton?: any; 18 | animate?: boolean; 19 | }) { 20 | const [uri, setUri] = useState(''); 21 | 22 | useEffect(() => { 23 | const connector = new WalletConnect(connectorOptions); 24 | onConnectorInitialized(connector); 25 | 26 | if (connector && !connector.connected) { 27 | connector.createSession({ chainId }).then(() => { 28 | setUri(connector.uri); 29 | }); 30 | } 31 | }, [chainId, connectorOptions, onConnectorInitialized]); 32 | 33 | return ( 34 | 35 | ); 36 | } 37 | 38 | export default React.memo(ConnectButtonV1); 39 | -------------------------------------------------------------------------------- /src/components/qrcode/QRCard.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import styled from 'styled-components'; 3 | import QRCode from './QRCode'; 4 | 5 | const Content = styled.div<{ showQR?: boolean; size?: number }>` 6 | border-radius: 39px; 7 | box-shadow: 0px 10px 30px rgba(0, 0, 0, 0.4); 8 | height: ${({ size }) => (size ? `${size}px` : '200px')}; 9 | width: ${({ size }) => (size ? `${size}px` : '200px')}; 10 | opacity: ${({ showQR }) => (showQR ? 1 : 0)}; 11 | padding: 8px; 12 | transition: 0.225s ease; 13 | position: 'absolute'; 14 | `; 15 | 16 | const QRCard = ({ 17 | value, 18 | showQR, 19 | size, 20 | }: { 21 | value: string; 22 | showQR: boolean; 23 | size?: number; 24 | }) => { 25 | return ( 26 | 27 | 28 | 29 | ); 30 | }; 31 | 32 | export default QRCard; 33 | -------------------------------------------------------------------------------- /src/components/qrcode/QRCode.tsx: -------------------------------------------------------------------------------- 1 | import QRCodeUtil from 'qrcode'; 2 | import React, { ReactElement, useMemo } from 'react'; 3 | import styled from 'styled-components'; 4 | import rainbowOg from '../../../assets/images/rainbow-og.png'; 5 | 6 | const QRContainer = styled.div` 7 | height: 375px; 8 | user-select: none; 9 | `; 10 | 11 | const generateMatrix = ( 12 | value: string, 13 | errorCorrectionLevel: QRCodeUtil.QRCodeErrorCorrectionLevel 14 | ) => { 15 | const arr = Array.prototype.slice.call( 16 | QRCodeUtil.create(value, { errorCorrectionLevel }).modules.data, 17 | 0 18 | ); 19 | const sqrt = Math.sqrt(arr.length); 20 | return arr.reduce( 21 | (rows, key, index) => 22 | (index % sqrt === 0 23 | ? rows.push([key]) 24 | : rows[rows.length - 1].push(key)) && rows, 25 | [] 26 | ); 27 | }; 28 | 29 | type Props = { 30 | ecl?: QRCodeUtil.QRCodeErrorCorrectionLevel; 31 | logoMargin?: number; 32 | logoSize?: number; 33 | size?: number; 34 | value?: string; 35 | }; 36 | 37 | const QRCode = ({ 38 | ecl = 'M', 39 | logoMargin = 10, 40 | logoSize = 50, 41 | size = 200, 42 | value = 'QR Code', 43 | }: Props) => { 44 | const dots = useMemo(() => { 45 | const dots: ReactElement[] = []; 46 | const matrix = generateMatrix(value, ecl); 47 | const cellSize = size / matrix.length; 48 | let qrList = [ 49 | { x: 0, y: 0 }, 50 | { x: 1, y: 0 }, 51 | { x: 0, y: 1 }, 52 | ]; 53 | 54 | qrList.forEach(({ x, y }) => { 55 | const x1 = (matrix.length - 7) * cellSize * x; 56 | const y1 = (matrix.length - 7) * cellSize * y; 57 | for (let i = 0; i < 3; i++) { 58 | dots.push( 59 | 69 | ); 70 | } 71 | }); 72 | 73 | const clearArenaSize = Math.floor((logoSize + 5) / cellSize); 74 | const matrixMiddleStart = matrix.length / 2 - clearArenaSize / 2; 75 | const matrixMiddleEnd = matrix.length / 2 + clearArenaSize / 2 - 1; 76 | 77 | matrix.forEach((row: QRCodeUtil.QRCode[], i: number) => { 78 | row.forEach((_: any, j: number) => { 79 | if (matrix[i][j]) { 80 | if ( 81 | !( 82 | (i < 7 && j < 7) || 83 | (i > matrix.length - 8 && j < 7) || 84 | (i < 7 && j > matrix.length - 8) 85 | ) 86 | ) { 87 | if ( 88 | !( 89 | i > matrixMiddleStart && 90 | i < matrixMiddleEnd && 91 | j > matrixMiddleStart && 92 | j < matrixMiddleEnd && 93 | i < j + clearArenaSize / 2 && 94 | j < i + clearArenaSize / 2 + 1 95 | ) 96 | ) { 97 | dots.push( 98 | 105 | ); 106 | } 107 | } 108 | } 109 | }); 110 | }); 111 | 112 | return dots; 113 | }, [ecl, logoSize, size, value]); 114 | 115 | const logoPosition = size / 2 - logoSize / 2; 116 | const logoWrapperSize = logoSize + logoMargin * 2; 117 | 118 | return ( 119 | 120 |
128 | 135 |
136 | 137 | 138 | 139 | 140 | 141 | 144 | 145 | 146 | {dots} 147 | 148 |
149 | ); 150 | }; 151 | 152 | export default QRCode; 153 | -------------------------------------------------------------------------------- /src/constants/index.ts: -------------------------------------------------------------------------------- 1 | export enum SUPPORTED_MAIN_CHAIN_IDS { 2 | MAINNET = 1, 3 | OPTIMISM = 10, 4 | POLYGON = 137, 5 | ARBITRUM = 42161, 6 | } 7 | 8 | export enum SUPPORTED_TEST_CHAIN_IDS { 9 | ROPSTEN = 3, 10 | RINKEBY = 4, 11 | GÖRLI = 5, 12 | KOVAN = 42, 13 | } 14 | 15 | export enum SUPPORTED_MAIN_CHAINS_EIP155 { 16 | MAINNET = 'eip155:1', 17 | OPTIMISM = 'eip155:10', 18 | POLYGON = 'eip155:137', 19 | ARBITRUM = 'eip155:42161', 20 | } 21 | 22 | export enum SUPPORTED_TEST_CHAINS_EIP155 { 23 | ROPSTEN = 'eip155:3', 24 | RINKEBY = 'eip155:4', 25 | GÖRLI = 'eip155:5', 26 | KOVAN = 'eip155:42', 27 | } 28 | 29 | export enum SUPPORTED_MAIN_CHAINS_NAMES { 30 | MAINNET = 'Mainnet', 31 | OPTIMISM = 'Optimism', 32 | POLYGON = 'Polygon', 33 | ARBITRUM = 'Arbitrum', 34 | } 35 | 36 | export enum SUPPORTED_TEST_CHAINS_NAMES { 37 | ROPSTEN = 'Ropsten', 38 | RINKEBY = 'Rinkeby', 39 | GÖRLI = 'Gorli', 40 | KOVAN = 'Kovan', 41 | } 42 | export const RAINBOW_BUTTON_ID = '1628799713918-rainbow-button'; 43 | -------------------------------------------------------------------------------- /src/helpers/deeplink.ts: -------------------------------------------------------------------------------- 1 | const baseUrl = 'https://rnbwapp.com'; 2 | 3 | const constructDeeplink = (uri: string): string => { 4 | const encodedUri = encodeURIComponent(uri); 5 | const fullUrl = `${baseUrl}/wc?uri=${encodedUri}`; 6 | return fullUrl; 7 | }; 8 | 9 | export { constructDeeplink }; 10 | -------------------------------------------------------------------------------- /src/icons/ButtonLabel.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const ButtonLabel = () => ( 4 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | 64 | 68 | 72 | 76 | 77 | ); 78 | 79 | export default ButtonLabel; 80 | -------------------------------------------------------------------------------- /src/icons/LogoAppStore.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const LogoAppStore = () => ( 4 | 12 | 16 | 17 | ); 18 | 19 | export default LogoAppStore; 20 | -------------------------------------------------------------------------------- /src/icons/XButton.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const XButton = () => ( 4 | 13 | 14 | 18 | 19 | 20 | ); 21 | 22 | export default XButton; 23 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import WalletConnect from '@walletconnect/client'; 2 | 3 | // eslint-disable-next-line import/no-unresolved 4 | import { IWalletConnectOptions } from '@walletconnect/types'; 5 | import React from 'react'; 6 | import rainbow_icon from '../assets/images/rainbow-icon.png'; 7 | import rainbow from '../assets/images/rainbow.png'; 8 | import ConnectButtonV1 from './components/button/ConnectButtonV1'; 9 | import { 10 | SUPPORTED_MAIN_CHAIN_IDS, 11 | SUPPORTED_TEST_CHAIN_IDS, 12 | } from './constants'; 13 | import { goToRainbow } from './utils'; 14 | 15 | export interface Props { 16 | chainId: number | undefined; 17 | connectorOptions: IWalletConnectOptions; 18 | onConnectorInitialized: (client: WalletConnect) => void; 19 | customButton?: any; 20 | animate?: boolean; 21 | } 22 | 23 | export const RainbowButton = ({ 24 | chainId, 25 | connectorOptions, 26 | onConnectorInitialized, 27 | customButton, 28 | animate, 29 | }: Props) => { 30 | return ( 31 | 38 | ); 39 | }; 40 | 41 | export const assets = { 42 | rainbow: rainbow, 43 | rainbow_icon: rainbow_icon, 44 | }; 45 | 46 | export const utils = { 47 | goToRainbow, 48 | }; 49 | 50 | export const constants = { 51 | SUPPORTED_MAIN_CHAIN_IDS, 52 | SUPPORTED_TEST_CHAIN_IDS, 53 | }; 54 | -------------------------------------------------------------------------------- /src/styled/index.tsx: -------------------------------------------------------------------------------- 1 | import { motion } from 'framer-motion'; 2 | import styled, { keyframes } from 'styled-components'; 3 | 4 | export const XButtonWrapper = styled.div` 5 | all: revert; 6 | -webkit-tap-highlight-color: transparent; 7 | cursor: pointer; 8 | height: 27px; 9 | opacity: 1; 10 | overflow: visible; 11 | padding: 30px; 12 | pointer-events: 'auto'; 13 | position: fixed; 14 | top: 0; 15 | right: 0; 16 | width: 27px; 17 | transition: 0.125s ease; 18 | z-index: 100; 19 | svg { 20 | will-change: transform; 21 | } 22 | :hover { 23 | transform: scale(1.125); 24 | } 25 | :active { 26 | transform: scale(0.875); 27 | } 28 | @media (max-width: 1200px) { 29 | padding: 19px 24px 15px; 30 | position: fixed; 31 | right: 0; 32 | top: 0; 33 | } 34 | `; 35 | 36 | export const UniqueTokenExpandedStateContent = styled.div` 37 | all: revert; 38 | display: none; 39 | align-items: center; 40 | align-self: center; 41 | display: flex; 42 | height: 100%; 43 | justify-content: center; 44 | left: 0; 45 | overflow: hidden; 46 | position: fixed; 47 | top: 0; 48 | transition: 0.2s ease; 49 | width: 100%; 50 | will-change: transform; 51 | z-index: 40; 52 | animation: fadeIn 0.3s linear; 53 | @media (max-width: 850px) { 54 | overflow: visible; 55 | overflow-y: scroll; 56 | overflow-x: clip; 57 | } 58 | > div { 59 | height: 100%; 60 | } 61 | `; 62 | 63 | export const ExpandedState = styled(motion.div)<{ qr?: boolean }>` 64 | font-family: SFRounded, ui-rounded, 'SF Pro Rounded', system-ui, 65 | 'Helvetica Neue', Arial, Helvetica, sans-serif; 66 | align-items: center; 67 | align-self: center; 68 | background: transparent; 69 | display: flex; 70 | flex-direction: row; 71 | justify-content: center; 72 | height: 100%; 73 | margin: 0 42px; 74 | pointer-events: none; 75 | width: 1000px; 76 | @media (max-width: 850px) { 77 | box-sizing: border-box; 78 | flex-direction: column; 79 | margin: 0; 80 | max-width: 460px; 81 | padding: 0 30px; 82 | width: 100%; 83 | } 84 | @media (max-width: 650px) { 85 | max-width: 448px; 86 | padding: 0 24px; 87 | } 88 | @media (max-width: 375px) { 89 | height: 90%; 90 | width: 90%; 91 | } 92 | `; 93 | 94 | export const ExpandedStateBackground = styled.div<{ 95 | isPopoverVisible?: boolean; 96 | popover?: boolean; 97 | opacity?: number; 98 | }>` 99 | background-color: #000000; 100 | cursor: ${({ isPopoverVisible, popover }) => 101 | popover && isPopoverVisible ? 'auto' : 'default'}; 102 | ${({ theme: { isMobile } }) => !isMobile && 'left: -50vh;'} 103 | opacity: ${({ isPopoverVisible, opacity, popover }) => 104 | opacity || (popover && isPopoverVisible ? 0.1 : 0)}; 105 | pointer-events: ${({ isPopoverVisible, popover }) => 106 | popover && !isPopoverVisible ? 'none' : 'auto'}; 107 | position: fixed; 108 | top: 0; 109 | transition: 0.125s ease; 110 | width: ${({ theme: { isMobile } }) => (isMobile ? '100%' : '250vw')}; 111 | height: 100%; 112 | z-index: -100; 113 | `; 114 | 115 | export const Column = styled.div<{ 116 | width?: string; 117 | align?: string; 118 | justify?: string; 119 | padding?: string; 120 | border?: string; 121 | borderRadius?: string; 122 | }>` 123 | width: ${({ width }) => width ?? '100%'}; 124 | display: flex; 125 | flex-direction: column !important; 126 | padding: 0; 127 | align-items: ${({ align }) => align ?? 'center'}; 128 | justify-content: ${({ justify }) => justify ?? 'flex-start'}; 129 | padding: ${({ padding }) => padding}; 130 | border: ${({ border }) => border}; 131 | border-radius: ${({ borderRadius }) => borderRadius}; 132 | `; 133 | 134 | export const Container = styled.div` 135 | background: white; 136 | border-radius: 47px; 137 | box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); 138 | margin-bottom: 150px; 139 | padding: 30px; 140 | padding-bottom: 36px; 141 | transform: translate3d(0, 0, 0); 142 | transition: 0.125s ease; 143 | will-change: transform; 144 | z-index: 20; 145 | 146 | :active { 147 | transform: scale(1.025) translate3d(0, 0, 0); 148 | } 149 | 150 | @media (max-height: 750px) { 151 | margin-bottom: 135px; 152 | } 153 | 154 | @media (max-height: 680px) { 155 | margin-bottom: 24px; 156 | } 157 | `; 158 | 159 | export const TitleText = styled.div<{ subtitle?: boolean }>` 160 | color: white; 161 | letter-spacing: 0.35px; 162 | font-size: 20px; 163 | font-weight: 800; 164 | margin-bottom: ${({ subtitle }) => (subtitle ? 0 : '24px')}; 165 | text-align: center; 166 | `; 167 | 168 | export const DownloadContainer = styled.div` 169 | align-items: center; 170 | align-self: flex-end; 171 | bottom: 0; 172 | display: flex; 173 | flex-direction: column; 174 | justify-content: flex-end; 175 | left: 0; 176 | margin: 0 auto 42px; 177 | position: absolute; 178 | right: 0; 179 | z-index: 100; 180 | 181 | @media (max-height: 750px) { 182 | margin: 0 auto 24px; 183 | } 184 | 185 | @media (max-height: 680px) { 186 | display: none; 187 | } 188 | `; 189 | 190 | export const DownloadButton = styled.a` 191 | background: #000000; 192 | box-shadow: 0px 10px 30px rgba(0, 0, 0, 0.4); 193 | border-radius: 47px; 194 | box-sizing: border-box; 195 | color: white; 196 | cursor: pointer; 197 | display: flex; 198 | height: 46px; 199 | margin: 19px 7.5px; 200 | padding: 10px 19px 0; 201 | font-size: 18px; 202 | font-weight: 800; 203 | letter-spacing: 0.35px; 204 | text-align: center; 205 | transition: 0.125s ease; 206 | will-change: transform; 207 | text-decoration: none; 208 | z-index: 100; 209 | 210 | :hover { 211 | transform: scale(1.05); 212 | } 213 | :active { 214 | transform: scale(0.95); 215 | } 216 | `; 217 | 218 | export const animatedgradient = keyframes` 219 | 0% { 220 | background-position: 0% 50%; 221 | } 222 | 50% { 223 | background-position: 100% 50%; 224 | } 225 | 100% { 226 | background-position: 0% 50%; 227 | } 228 | `; 229 | 230 | export const Content = styled.div` 231 | all: revert; 232 | display: inline-block; 233 | overflow: hidden; 234 | height: 100%; 235 | padding: 4px; 236 | transition: 0.125s ease; 237 | justify-content: center; 238 | 239 | :hover { 240 | transform: scale(1.05); 241 | } 242 | 243 | :active { 244 | transform: scale(0.95) !important; 245 | } 246 | `; 247 | 248 | export const Button = styled.a` 249 | transition: 0.125s ease; 250 | will-change: transform; 251 | `; 252 | 253 | export const ButtonInner = styled.div` 254 | -webkit-user-select: none; 255 | align-items: center; 256 | color: #ffffff; 257 | cursor: pointer; 258 | display: flex; 259 | font-weight: 700; 260 | height: 44px; 261 | padding: 0 16px 2px 0; 262 | position: relative; 263 | text-align: center; 264 | transition: 0.125s ease; 265 | 266 | :hover { 267 | &:before { 268 | backdrop-filter: saturate(4); 269 | background: rgba(0, 0, 0, 0.925); 270 | } 271 | } 272 | 273 | &:before { 274 | backdrop-filter: saturate(4); 275 | background: rgba(0, 0, 0, 0.85); 276 | border-radius: 16px; 277 | content: ''; 278 | height: 100%; 279 | left: 0; 280 | position: absolute; 281 | top: 0; 282 | transition: 0.125s ease; 283 | width: 100%; 284 | will-change: transform; 285 | z-index: -1; 286 | } 287 | 288 | &:after { 289 | animation: ${animatedgradient} 80s ease-in-out alternate infinite; 290 | background: linear-gradient( 291 | 270deg, 292 | #174299 0%, 293 | #1edbae 9.09%, 294 | #00b2ff 18.18%, 295 | #9f4ced 27.27%, 296 | #d04c74 36.36%, 297 | #00b5d5 45.45%, 298 | #174299 54.54%, 299 | #00b6cf 63.63%, 300 | #00d56f 72.72%, 301 | #174299 81.81%, 302 | #01bcd5 90.9%, 303 | #174299 100% 304 | ); 305 | background-size: 1200% 1200%; 306 | border-radius: 18px; 307 | content: ''; 308 | height: calc(100% + 4px); 309 | left: -2px; 310 | right: -2px; 311 | position: absolute; 312 | top: -2px; 313 | transition: 0.125s ease; 314 | width: calc(100% + 4px); 315 | will-change: transform; 316 | z-index: -2; 317 | } 318 | 319 | @media (color-gamut: p3) { 320 | :hover { 321 | &:before { 322 | background: color(display-p3 0 0 0 / 92.5%); 323 | } 324 | } 325 | 326 | &:before { 327 | background: color(display-p3 0 0 0 / 85%); 328 | } 329 | 330 | &:after { 331 | background: linear-gradient( 332 | 315deg, 333 | color(display-p3 0.0902 0.25882 0.6) 0%, 334 | color(display-p3 0.11765 0.85882 0.68235) 9.09%, 335 | color(display-p3 0 0.69804 1) 18.18%, 336 | color(display-p3 0.62353 0.29804 0.92941) 27.27%, 337 | color(display-p3 0.81569 0.29804 0.65098) 36.36%, 338 | color(display-p3 0 0.7098 0.83529) 45.45%, 339 | color(display-p3 0.0902 0.25882 0.6) 54.54%, 340 | color(display-p3 0 0.71373 0.81176) 63.63%, 341 | color(display-p3 0 0.83529 0.43529) 72.72%, 342 | color(display-p3 0.0902 0.25882 0.6) 81.81%, 343 | color(display-p3 0.00392 0.73725 0.83529) 90.9%, 344 | color(display-p3 0.0902 0.25882 0.6) 100% 345 | ); 346 | background-size: 1200% 1200%; 347 | } 348 | } 349 | `; 350 | 351 | export const Logo = styled.img` 352 | all: revert; 353 | -webkit-touch-callout: none; 354 | -webkit-user-select: none; 355 | border-radius: 11px; 356 | box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.2); 357 | margin-left: 6px; 358 | margin-right: 10px; 359 | margin-top: 2px; 360 | height: 34px; 361 | width: 34px; 362 | `; 363 | 364 | export const Label = styled.div` 365 | background-size: 100% 100%; 366 | height: 14px; 367 | opacity: 1; 368 | transition: 0.125s ease; 369 | width: 175px; 370 | will-change: transform; 371 | `; 372 | -------------------------------------------------------------------------------- /src/typings.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.css' { 2 | const content: { [className: string]: string }; 3 | export default content; 4 | } 5 | declare namespace JSX { 6 | interface IntrinsicElements { 7 | customButton: any; 8 | } 9 | } 10 | declare module '*.png' { 11 | const value: any; 12 | export default value; 13 | } 14 | -------------------------------------------------------------------------------- /src/utils/index.ts: -------------------------------------------------------------------------------- 1 | // import WalletConnectClient from '@walletconnectv2/client'; 2 | 3 | /** 4 | * Go to rainbow app via deeplink 5 | */ 6 | export const goToRainbow = (): void => { 7 | window.location.href = 'https://rnbwapp.com/wc'; 8 | }; 9 | 10 | /** 11 | * Returns an array containing session topics, if any 12 | * 13 | * @param client - WalletConnectClient 14 | * @returns - Session topics 15 | */ 16 | // export const getClientPairings = (client: WalletConnectClient): string[] => { 17 | // return client?.session?.topics || []; 18 | // }; 19 | 20 | const fromEIP55Format = (chain: string) => chain?.replace('eip155:', ''); 21 | 22 | /** 23 | * 24 | * @param account - Wallet Connect formatted account 25 | * @returns - Object containing address and chainId 26 | */ 27 | export const getAddressAndChainIdFromAccount = ( 28 | account: string 29 | ): { address: string; chainId: number } => { 30 | const [address, eip155ChainId] = account.split('@'); 31 | const chainId = fromEIP55Format(eip155ChainId); 32 | return { address, chainId: Number(chainId) }; 33 | }; 34 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs 3 | "include": ["src", "types"], 4 | "compilerOptions": { 5 | "module": "esnext", 6 | "lib": ["dom", "esnext"], 7 | "importHelpers": true, 8 | // output .d.ts declaration files for consumers 9 | "declaration": true, 10 | // output .js.map sourcemap files for consumers 11 | "sourceMap": true, 12 | // match output dir to input dir. e.g. dist/index instead of dist/src/index 13 | "rootDir": "./src", 14 | // stricter type-checking for stronger correctness. Recommended by TS 15 | "strict": true, 16 | // linter checks for common issues 17 | "noImplicitReturns": true, 18 | "noFallthroughCasesInSwitch": true, 19 | // noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | // use Node's module resolution algorithm, instead of the legacy TS one 23 | "moduleResolution": "node", 24 | // transpile JSX to React.createElement 25 | "jsx": "react", 26 | // interop between ESM and CJS modules. Recommended by TS 27 | "esModuleInterop": true, 28 | // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS 29 | "skipLibCheck": true, 30 | // error out if import and file system have a casing mismatch. Recommended by TS 31 | "forceConsistentCasingInFileNames": true, 32 | // `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc` 33 | "noEmit": true, 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tsdx.config.js: -------------------------------------------------------------------------------- 1 | const images = require('@rollup/plugin-image'); 2 | 3 | module.exports = { 4 | // eslint-disable-next-line no-unused-vars 5 | rollup(config, options) { 6 | config.plugins = [ 7 | images({ incude: ['**/*.png', '**/*.jpg'] }), 8 | ...config.plugins, 9 | ]; 10 | 11 | return config; 12 | }, 13 | }; 14 | --------------------------------------------------------------------------------