-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b21a4f5
commit b28a7a8
Showing
5 changed files
with
112 additions
and
0 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,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 ( | ||
<Button variant="wallet" onClick={() => setShellMemo()} colorScheme="black"> | ||
<HStack justify="space-between" width="full"> | ||
<Text>Shell Wallet</Text> | ||
<img src="/img/shell-icon.png" width={'24px'} /> | ||
</HStack> | ||
</Button> | ||
) | ||
} | ||
|
||
export default ShellConnectButton |
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,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 } | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.