-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migration guide copy and mobile support
- Loading branch information
1 parent
8ed326c
commit 30bdd17
Showing
3 changed files
with
133 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import Admonition from '@theme/Admonition'; | ||
|
||
# Migration Guide | ||
|
||
This guide will cover how to set up a React app, integrate Wallet Kit, check the balance of the connected account, and call a token swap. If you want to integrate Station into an existing React app, jump to the [Wrap your app in `WalletProvider` section](#2-wrap-your-app-in-walletprovider). | ||
|
||
## Prerequisites | ||
|
||
- [Station Chrome extension](../../learn/station/download/station-extension.mdx) | ||
- [NPM](https://www.npmjs.com/) | ||
- [NVM](https://github.com/nvm-sh/nvm) | ||
- Node.js version 16 | ||
|
||
<Admonition type="tip" icon="💡" title="Node version 16"> | ||
<details> | ||
<summary> | ||
{' '} | ||
Most users will need to specify Node version 16 before continuing. You can | ||
manage node versions [with NVM](https://github.com/nvm-sh/nvm).{' '} | ||
</summary> | ||
```sh nvm install 16 nvm use 16 ``` | ||
</details> | ||
</Admonition> | ||
|
||
## 1. Dependency Setup | ||
|
||
1. To get started, install and uninstall the pre-exsisting Station wallet packages. | ||
|
||
```sh | ||
npm uninstall @terra-money/use-wallet @terra-money/wallet-controller @terra-money/wallet-provider | ||
``` | ||
|
||
2. Then, install the `@terra-money/wallet-kit` package: | ||
|
||
```sh | ||
npm install @terra-money/wallet-kit @terra-money/terra-station-mobile | ||
``` | ||
|
||
## 2. Change `WalletProvider` setup | ||
|
||
1. Navigate to your `index.js` in a code editor and change the following in your `WalletProvider` component. Instead of calling `getChainOptions` use `getInitalConfig` and pass in the `defaultNetworks` as a prop. Its reccomended to also add Station Mobile as shown in the below code sample. | ||
|
||
```js | ||
import ReactDOM from 'react-dom'; | ||
import App from './App'; | ||
import TerraStationMobileWallet from '@terra-money/terra-station-mobile'; | ||
import { getInitialConfig, WalletProvider } from '@terra-money/wallet-kit'; | ||
getInitialConfig().then((defaultNetworks) => { | ||
ReactDOM.render( | ||
<WalletProvider | ||
extraWallets={[new TerraStationMobileWallet()]} | ||
defaultNetworks={defaultNetworks} | ||
> | ||
<App /> | ||
</WalletProvider>, | ||
document.getElementById('root'), | ||
); | ||
}); | ||
``` | ||
## 3. Code tweaks to comply with Wallet Kit API | ||
1. Fix package imports. Import key Station wallet utility from @terra-money/wallet-kit instead of prior packages. | ||
```js | ||
import { useWallet, useConnectedWallet } from '@terra-money/wallet-kit'; | ||
``` | ||
2. Fix minor code changes. For example, `WalletStatus` enum now has properties `CONNECTED` instead of `WALLET_CONNECTED`. And `availableConnections` and `availableInstallations` have been consolidated into `availableWallets`. | ||
```js | ||
const { connect, availableWallets } = useWallet(); | ||
const list = [ | ||
...availableWallets | ||
.filter(({ isInstalled }) => isInstalled) | ||
.map(({ id, name, icon }) => ({ | ||
src: icon, | ||
children: name, | ||
onClick: () => connect(id), | ||
})), | ||
...availableWallets | ||
.filter(({ isInstalled, website }) => !isInstalled && website) | ||
.map(({ name, icon, website }) => ({ | ||
src: icon, | ||
children: t(`Install ${name}`), | ||
href: website ?? '', | ||
})), | ||
]; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters