-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from lindlof/keplr-wallet
Keplr wallet
- Loading branch information
Showing
15 changed files
with
1,256 additions
and
870 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
REACT_APP_LCD_URL=https://bootstrap.secrettestnet.io/ | ||
REACT_APP_CHAIN_ID=holodeck-2 | ||
REACT_APP_CHAIN_NAME=Secret Holodeck 2 | ||
REACT_APP_LCD_URL=https://bootstrap.secrettestnet.io | ||
REACT_APP_RPC_URL=http://bootstrap.secrettestnet.io:26657 | ||
REACT_APP_CONTRACT=secret17c7j5xgylhty8jq5lqnuaqd68ndazs022mqcuu | ||
REACT_APP_FAUCET=https://faucet.secrettestnet.io/ |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM node:15 | ||
FROM node:15.2.1 | ||
WORKDIR /app | ||
COPY package.json package-lock.json /app/ | ||
RUN npm install | ||
|
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,27 +1,28 @@ | ||
interface Config { | ||
readonly chainId: string; | ||
readonly chainName: string; | ||
readonly lcdUrl: string; | ||
readonly rpcUrl: string; | ||
readonly contract: string; | ||
readonly faucetUrl: string | undefined; | ||
} | ||
|
||
export default (): Config => { | ||
const lcdUrl: string = lcdUrlFromEnv(); | ||
const contract: string = contractFromEnv(); | ||
const envConfig = (): Config => { | ||
return { | ||
lcdUrl, | ||
contract, | ||
chainId: requiredEnv('REACT_APP_CHAIN_ID'), | ||
chainName: requiredEnv('REACT_APP_CHAIN_NAME'), | ||
lcdUrl: requiredEnv('REACT_APP_LCD_URL'), | ||
rpcUrl: requiredEnv('REACT_APP_RPC_URL'), | ||
contract: requiredEnv('REACT_APP_CONTRACT'), | ||
faucetUrl: process.env.REACT_APP_FAUCET, | ||
}; | ||
}; | ||
|
||
const lcdUrlFromEnv = (): string => { | ||
const reactAppContract = process.env.REACT_APP_LCD_URL; | ||
if (!reactAppContract) throw new Error('REACT_APP_LCD_URL not configured'); | ||
return reactAppContract; | ||
const requiredEnv = (key: string): string => { | ||
const val = process.env[key]; | ||
if (!val) throw new Error(`${key} not configured`); | ||
return val; | ||
}; | ||
|
||
const contractFromEnv = (): string => { | ||
const reactAppContract = process.env.REACT_APP_CONTRACT; | ||
if (!reactAppContract) throw new Error('REACT_APP_CONTRACT not configured'); | ||
return reactAppContract; | ||
}; | ||
export type { Config }; | ||
export { envConfig }; |
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,56 @@ | ||
import React, { useEffect } from 'react'; | ||
import { Button } from '@material-ui/core'; | ||
import { Config } from '../config'; | ||
import CircularProgress from '@material-ui/core/CircularProgress'; | ||
import Grid from '@material-ui/core/Grid'; | ||
import localWallet from './localWallet'; | ||
import keplr from './keplrWallet'; | ||
import { WalletType, walletTypeName } from './model'; | ||
|
||
interface Props { | ||
walletType: WalletType; | ||
config: Config; | ||
setClient: Function; | ||
cancel: Function; | ||
} | ||
|
||
export default (props: React.PropsWithChildren<Props>) => { | ||
const { walletType, config, setClient, cancel } = props; | ||
|
||
useEffect(() => { | ||
const timer = setInterval(async () => { | ||
switch (walletType) { | ||
case WalletType.Keplr: | ||
keplr(config.chainId, config.chainName, config.lcdUrl, config.rpcUrl, setClient); | ||
break; | ||
case WalletType.LocalWallet: | ||
localWallet(config.lcdUrl, setClient); | ||
} | ||
}, 1000); | ||
return () => clearInterval(timer); | ||
}, [walletType, config.chainId, config.chainName, config.lcdUrl, config.rpcUrl, setClient]); | ||
|
||
return ( | ||
<div> | ||
<h2>Loading wallet</h2> | ||
<p> | ||
{walletType === WalletType.LocalWallet && | ||
`${walletTypeName[walletType]} should be ready shortly`} | ||
{walletType === WalletType.Keplr && | ||
`Make sure you have ${walletTypeName[walletType]} extension installed`} | ||
</p> | ||
<div> | ||
<Grid container spacing={3} alignItems="flex-end"> | ||
<Grid item xs={4} sm={6}> | ||
<CircularProgress /> | ||
</Grid> | ||
<Grid item xs={8} sm={6}> | ||
<Button variant="contained" color="primary" onClick={() => cancel()}> | ||
Cancel | ||
</Button> | ||
</Grid> | ||
</Grid> | ||
</div> | ||
</div> | ||
); | ||
}; |
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,80 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import * as SecretJS from 'secretjs'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import { Button } from '@material-ui/core'; | ||
import Paper from '@material-ui/core/Paper'; | ||
import Modal from '@material-ui/core/Modal'; | ||
import { envConfig } from '../config'; | ||
import ClientLoader from './ClientLoader'; | ||
import { WalletType } from './model'; | ||
|
||
const config = envConfig(); | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
paper: { | ||
position: 'absolute', | ||
width: 270, | ||
backgroundColor: theme.palette.background.paper, | ||
border: '2px solid #000', | ||
boxShadow: theme.shadows[5], | ||
padding: theme.spacing(1, 1, 4), | ||
textAlign: 'center', | ||
top: '50%', | ||
left: '50%', | ||
transform: 'translate(-50%, -50%)', | ||
}, | ||
})); | ||
|
||
interface Props { | ||
client: SecretJS.SigningCosmWasmClient | undefined; | ||
setClient: (client: SecretJS.SigningCosmWasmClient) => void; | ||
} | ||
|
||
export default (props: React.PropsWithChildren<Props>) => { | ||
const classes = useStyles(); | ||
const { client, setClient } = props; | ||
const [loadWallet, setLoadWallet] = useState<WalletType | undefined>(); | ||
|
||
useEffect(() => { | ||
if (client) setLoadWallet(undefined); | ||
}, [client]); | ||
|
||
return ( | ||
<div> | ||
{!client && ( | ||
<Modal | ||
open={true} | ||
aria-labelledby="simple-modal-title" | ||
aria-describedby="simple-modal-description" | ||
> | ||
<Paper className={classes.paper}> | ||
{!loadWallet && ( | ||
<div> | ||
<h2>Select wallet</h2> | ||
<Button | ||
variant="contained" | ||
color="primary" | ||
onClick={() => setLoadWallet(WalletType.Keplr)} | ||
> | ||
Use Keplr | ||
</Button> | ||
<Button variant="contained" onClick={() => setLoadWallet(WalletType.LocalWallet)}> | ||
Local wallet | ||
</Button> | ||
</div> | ||
)} | ||
{loadWallet && ( | ||
<ClientLoader | ||
walletType={loadWallet} | ||
config={config} | ||
setClient={setClient} | ||
cancel={() => setLoadWallet(undefined)} | ||
/> | ||
)} | ||
</Paper> | ||
</Modal> | ||
)} | ||
{props.children} | ||
</div> | ||
); | ||
}; |
File renamed without changes.
Oops, something went wrong.