From b28a7a8b11a9330ab60d56a8c2bc4e2f7f03a0b3 Mon Sep 17 00:00:00 2001
From: BusinessShellWallet
<136577895+BusinessShellWallet@users.noreply.github.com>
Date: Wed, 28 Jun 2023 16:09:32 +0700
Subject: [PATCH] Integrate Shell Wallet (#271)
---
components/Wallet/Modal/Modal.tsx | 2 +
.../Wallet/Modal/ShellConnectButton.tsx | 24 ++++++
.../components/TransferDialog/WalletInfo.tsx | 13 ++++
hooks/useConnectShell.tsx | 73 ++++++++++++++++++
public/img/shell-icon.png | Bin 0 -> 1704 bytes
5 files changed, 112 insertions(+)
create mode 100644 components/Wallet/Modal/ShellConnectButton.tsx
create mode 100644 hooks/useConnectShell.tsx
create mode 100644 public/img/shell-icon.png
diff --git a/components/Wallet/Modal/Modal.tsx b/components/Wallet/Modal/Modal.tsx
index 58c6f284..9e1110f3 100644
--- a/components/Wallet/Modal/Modal.tsx
+++ b/components/Wallet/Modal/Modal.tsx
@@ -13,6 +13,7 @@ import KeplrConnectButton from './KeplrConnectButton'
import CosmostationConnectButton from './CosmostationConnectButton'
import TerraStationConnectButton from './TerraStationConnectButton'
import LeapConnectButton from './LeapConnectButton'
+import ShellConnectButton from './ShellConnectButton'
function WalletModal({ isOpenModal, onCloseModal, chainId }) {
return (
@@ -26,6 +27,7 @@ function WalletModal({ isOpenModal, onCloseModal, chainId }) {
{chainId !== 'comdex-1' && chainId !== 'injective-1' && (
)}
+
diff --git a/components/Wallet/Modal/ShellConnectButton.tsx b/components/Wallet/Modal/ShellConnectButton.tsx
new file mode 100644
index 00000000..daa4879b
--- /dev/null
+++ b/components/Wallet/Modal/ShellConnectButton.tsx
@@ -0,0 +1,24 @@
+import React, { useCallback } from 'react'
+
+import { Button, HStack, Text } from '@chakra-ui/react'
+import useConnectShell from 'hooks/useConnectShell'
+
+function ShellConnectButton({ onCloseModal }) {
+ const { setShellAndConnect } = useConnectShell()
+
+ const setShellMemo = useCallback(() => {
+ setShellAndConnect()
+ onCloseModal()
+ }, [onCloseModal, setShellAndConnect])
+
+ return (
+
+ )
+}
+
+export default ShellConnectButton
diff --git a/features/assets/components/TransferDialog/WalletInfo.tsx b/features/assets/components/TransferDialog/WalletInfo.tsx
index 280a6b19..9d8f5a45 100644
--- a/features/assets/components/TransferDialog/WalletInfo.tsx
+++ b/features/assets/components/TransferDialog/WalletInfo.tsx
@@ -40,6 +40,19 @@ export const KeplrWalletInfo = ({ css, depositing }: WalletInfoProps) => {
)
}
+export const ShellWalletInfo = ({ css, depositing }: WalletInfoProps) => {
+ const { address: ibcWalletAddress } = useRecoilValue(ibcWalletState)
+
+ return (
+ }
+ address={ibcWalletAddress}
+ />
+ )
+}
+
export const AppWalletInfo = ({ css, depositing }: WalletInfoProps) => {
const { address: walletAddress } = useRecoilValue(walletState)
diff --git a/hooks/useConnectShell.tsx b/hooks/useConnectShell.tsx
new file mode 100644
index 00000000..eaddce8a
--- /dev/null
+++ b/hooks/useConnectShell.tsx
@@ -0,0 +1,73 @@
+import { GasPrice } from '@cosmjs/stargate'
+import { useConnectedWallet, useWallet } from '@terra-money/wallet-provider'
+import { useChainInfo } from 'hooks/useChainInfo'
+import { Router } from 'next/router'
+import { useRecoilState } from 'recoil'
+import { walletState, WalletStatusType } from 'state/atoms/walletAtoms'
+import { OfflineSigningWallet } from 'util/wallet-adapters'
+
+export default function useConnectShell() {
+ const [currentWalletState, setCurrentWalletState] =
+ useRecoilState(walletState)
+ const [chainInfo] = useChainInfo(currentWalletState.chainId)
+ const connectedWallet = useConnectedWallet()
+ const { disconnect } = useWallet()
+
+ const connectShell = async () => {
+ if (connectedWallet) {
+ disconnect()
+ }
+ if (window && !window?.shellwallet) {
+ alert('Please install Shell Wallet extension and refresh the page.')
+ return
+ }
+
+ try {
+ if (chainInfo !== undefined) {
+ await window.shellwallet?.experimentalSuggestChain(chainInfo)
+ await window.shellwallet.enable(currentWalletState.chainId)
+ const offlineSigner = await window.getOfflineSignerAutoShell(
+ currentWalletState.chainId
+ )
+
+ const wasmChainClient = await OfflineSigningWallet.connectWithSigner(
+ currentWalletState.chainId,
+ chainInfo.rpc,
+ offlineSigner,
+ currentWalletState.network,
+ {
+ gasPrice: GasPrice.fromString(
+ `${chainInfo?.gasPriceStep?.low}${chainInfo?.feeCurrencies?.[0].coinMinimalDenom}`
+ ),
+ },
+ 'shellwallet'
+ )
+ const [{ address }] = await offlineSigner.getAccounts()
+ const key = await window.shellwallet.getKey(currentWalletState.chainId)
+ /* successfully update the wallet state */
+ setCurrentWalletState({
+ key,
+ address: address,
+ client: wasmChainClient,
+ chainId: currentWalletState.chainId,
+ network: currentWalletState.network,
+ status: WalletStatusType.connected,
+ activeWallet: 'shellwallet',
+ })
+ }
+ } catch (e) {
+ throw e
+ }
+ }
+
+ const setShellAndConnect = () => {
+ setCurrentWalletState({
+ ...currentWalletState,
+ activeWallet: 'shellwallet',
+ })
+ localStorage.removeItem('__terra_extension_router_session__')
+ connectShell()
+ }
+
+ return { connectShell, setShellAndConnect }
+}
diff --git a/public/img/shell-icon.png b/public/img/shell-icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..6b4eef17767697cdf3c93aa2dcae8cf030100329
GIT binary patch
literal 1704
zcmV;Z23PrsP)f^@l$+nqY!PW8{xS
zG$uYm#7AOOjN&6`j94QGsI(}h7H9#XEhFu;Go8nov;6ix$H#Q`S?6^2UXO3BZ>=M4
zQ+pus8X%Ss#NsM(N-qZSVhYz2aXm^`APyifALXAw10V>X)e5BQLw&AFS+!CUluMLl
z$|5`}7sL~4jl>g>Sez>XV+5WDabp6<1)Ru$hBmD7psM0?U)2}!DrS!e_bH`u$avz>
za~S24uu%VF~^*Gejxz^z-hqAn4WmijdM22U7hV4`%y5f!lks=Wm2sYl$s
zm{`vV6<1^=glfkXr5XR)TH#O_18#eTPrTQbA!#5^_~V8oeIBU
zj;cf~@-*~1R6b`~3+`O88b~Ddcy#%n9Qsyr%)=4Uc$sct)=E4v|n5>~VwjSCqyH5|}y7?EP>r56S
z*)kSRpQ$H*F5}QoV^}zQ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