diff --git a/tauri-wallet/src/components/BalanceCard.tsx b/tauri-wallet/src/components/BalanceCard.tsx
index 39bbbb6cd1..7ced8d021b 100644
--- a/tauri-wallet/src/components/BalanceCard.tsx
+++ b/tauri-wallet/src/components/BalanceCard.tsx
@@ -1,6 +1,7 @@
-import React, { useContext } from 'react'
+import React, { useContext, useEffect } from 'react'
import {
CardContent,
+ CircularProgress,
IconButton,
Typography,
useTheme,
@@ -8,10 +9,16 @@ import {
import { ClientContext } from '../context/main'
import { FileCopy, Refresh } from '@material-ui/icons'
import { NymCard } from './NymCard'
+import { Alert } from '@material-ui/lab'
export const BalanceCard = () => {
const theme = useTheme()
- const { client } = useContext(ClientContext)
+ const { balance, balanceError, balanceLoading, getBalance } =
+ useContext(ClientContext)
+
+ useEffect(() => {
+ getBalance()
+ }, [])
return (
@@ -20,13 +27,23 @@ export const BalanceCard = () => {
subheader="Current wallet balance"
noPadding
Action={
-
+
}
>
- {client.balance}
+
+ {balanceLoading ? (
+
+ ) : balanceError ? (
+
+ {balanceError}
+
+ ) : (
+
{balance}
+ )}
+
@@ -35,7 +52,7 @@ export const BalanceCard = () => {
export const AddressCard = () => {
const theme = useTheme()
- const { client } = useContext(ClientContext)
+ const { address } = useContext(ClientContext)
return (
{
}
>
- {client.address}
+ {address}
)
diff --git a/tauri-wallet/src/components/Nav.tsx b/tauri-wallet/src/components/Nav.tsx
index 9c6678192c..a5c64ea151 100644
--- a/tauri-wallet/src/components/Nav.tsx
+++ b/tauri-wallet/src/components/Nav.tsx
@@ -1,4 +1,4 @@
-import React from 'react'
+import React, { useContext } from 'react'
import { Link, useLocation } from 'react-router-dom'
import {
List,
@@ -18,8 +18,7 @@ import {
MoneyOff,
} from '@material-ui/icons'
import { makeStyles } from '@material-ui/styles'
-import clsx from 'clsx'
-import { theme } from '../theme'
+import { ClientContext } from '../context/main'
const routesSchema = [
{
@@ -57,11 +56,6 @@ const routesSchema = [
route: '/undelegate',
Icon: ,
},
- {
- label: 'Log out',
- route: '/signin',
- Icon: ,
- },
]
const useStyles = makeStyles((theme: Theme) => ({
@@ -76,7 +70,7 @@ const useStyles = makeStyles((theme: Theme) => ({
export const Nav = () => {
const classes = useStyles()
- const location = useLocation()
+ const { logOut } = useContext(ClientContext)
return (
{
{routesSchema.map((r, i) => (
-
- {r.Icon}
-
+ {r.Icon}
))}
+
+
+
+
+
+
)
diff --git a/tauri-wallet/src/context/main.tsx b/tauri-wallet/src/context/main.tsx
index bc996a2a45..7107a037a3 100644
--- a/tauri-wallet/src/context/main.tsx
+++ b/tauri-wallet/src/context/main.tsx
@@ -1,7 +1,16 @@
-import React, { createContext } from 'react'
+import { invoke } from '@tauri-apps/api/tauri'
+import React, { createContext, useEffect, useState } from 'react'
+import { useHistory } from 'react-router-dom'
type TClientContext = {
- client: { address: string; balance: string }
+ isLoggedIn: boolean
+ address: string
+ balance?: string
+ balanceLoading: boolean
+ balanceError?: string
+ logIn: () => void
+ logOut: () => void
+ getBalance: () => void
}
export const ClientContext = createContext({} as TClientContext)
@@ -11,12 +20,44 @@ export const ClientContextProvider = ({
}: {
children: React.ReactNode
}) => {
- const client = {
- address: 'punk1s63y29jf8f3ft64z0vh80g3c76ty8lnyr74eur',
- balance: '2000 PUNKS',
+ const [isLoggedIn, setIsLoggedIn] = useState(false)
+ const [balance, setBalance] = useState()
+ const [balanceError, setBalanceError] = useState()
+ const [balanceLoading, setBalanceLoading] = useState(false)
+
+ const history = useHistory()
+
+ const getBalance = () => {
+ setBalanceLoading(true)
+ setBalanceError(undefined)
+ invoke('get_balance')
+ .then((balance) => {
+ setBalance(balance as string)
+ })
+ .catch((e) => setBalanceError(e))
+ setBalanceLoading(false)
}
+
+ const logIn = () => setIsLoggedIn(true)
+ const logOut = () => setIsLoggedIn(false)
+
+ useEffect(() => {
+ !isLoggedIn ? history.push('/signin') : history.push('/bond')
+ }, [isLoggedIn])
+
return (
-
+
{children}
)
diff --git a/tauri-wallet/src/index.tsx b/tauri-wallet/src/index.tsx
index 1399b3b150..8ede5a7d29 100644
--- a/tauri-wallet/src/index.tsx
+++ b/tauri-wallet/src/index.tsx
@@ -1,6 +1,7 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { CssBaseline, ThemeProvider } from '@material-ui/core'
+import { BrowserRouter as Router } from 'react-router-dom'
import { Routes } from './routes'
import { theme } from './theme'
import { ClientContextProvider } from './context/main'
@@ -8,9 +9,11 @@ import { ClientContextProvider } from './context/main'
const App = () => (
-
-
-
+
+
+
+
+
)
diff --git a/tauri-wallet/src/routes/balance.tsx b/tauri-wallet/src/routes/balance.tsx
index b0e1f7059b..d64343c600 100644
--- a/tauri-wallet/src/routes/balance.tsx
+++ b/tauri-wallet/src/routes/balance.tsx
@@ -9,47 +9,45 @@ import { Alert } from '@material-ui/lab'
import { theme } from '../theme'
export const Balance = () => {
- const { client } = useContext(ClientContext)
+ const { balance, balanceError, getBalance } = useContext(ClientContext)
+
+ const RefreshAction = () => (
+ }
+ >
+ Refresh
+
+ )
+
return (
- {client === null ? (
-
- ) : (
-
-
- {}}
- disabled={false}
- disableElevation
- startIcon={}
- >
- Refresh
-
- }
- >
- {'The current balance is ' + client.balance}
-
- }
- failureMessage="Failed to check the account balance!"
- />
-
+
+
+ {balanceError && (
+ }>
+ {balanceError}
+
+ )}
+ {!balanceError && (
+ }
+ >
+ {'The current balance is ' + balance}
+
+ )}
- )}
+
diff --git a/tauri-wallet/src/routes/index.tsx b/tauri-wallet/src/routes/index.tsx
index 8a523d1c7b..7e378cf2b1 100644
--- a/tauri-wallet/src/routes/index.tsx
+++ b/tauri-wallet/src/routes/index.tsx
@@ -1,6 +1,5 @@
import React from 'react'
import { Switch, Route } from 'react-router-dom'
-import { BrowserRouter as Router } from 'react-router-dom'
import { NotFound } from './404'
import { Balance } from './balance'
import { Bond } from './bond'
@@ -12,38 +11,36 @@ import { Unbond } from './unbond'
import { Undelegate } from './undelegate'
export const Routes = () => (
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
)
diff --git a/tauri-wallet/src/routes/receive.tsx b/tauri-wallet/src/routes/receive.tsx
index a28d60e0ac..f27e9cde83 100644
--- a/tauri-wallet/src/routes/receive.tsx
+++ b/tauri-wallet/src/routes/receive.tsx
@@ -7,43 +7,41 @@ import { theme } from '../theme'
import { ClientContext } from '../context/main'
export const Receive = () => {
- const { client } = useContext(ClientContext)
+ const { address } = useContext(ClientContext)
const matches = useMediaQuery('(min-width:769px)')
return (
- <>
-
-
-
-
- You can receive tokens by providing this address to the sender
-
-
-
-
-
- {client.address}
-
-
-
-
+
+
+
+
+ You can receive tokens by providing this address to the sender
+
-
- >
+
+
+
+ {address}
+
+
+
+
+
+
)
diff --git a/tauri-wallet/src/routes/send/SendForm.tsx b/tauri-wallet/src/routes/send/SendForm.tsx
index 4299787ec2..9aa9574106 100644
--- a/tauri-wallet/src/routes/send/SendForm.tsx
+++ b/tauri-wallet/src/routes/send/SendForm.tsx
@@ -11,7 +11,7 @@ export const SendForm = ({
updateRecipAddress: (address: string) => void
updateAmount: (amount: string) => void
}) => {
- const { client } = useContext(ClientContext)
+ const { address } = useContext(ClientContext)
return (
@@ -23,7 +23,7 @@ export const SendForm = ({
name="sender"
label="Sender address"
fullWidth
- value={client.address}
+ value={address}
disabled={true}
/>
diff --git a/tauri-wallet/src/routes/sign-in.tsx b/tauri-wallet/src/routes/sign-in.tsx
index 62fa64aaf4..4df452b163 100644
--- a/tauri-wallet/src/routes/sign-in.tsx
+++ b/tauri-wallet/src/routes/sign-in.tsx
@@ -1,4 +1,4 @@
-import React, { useState } from 'react'
+import React, { useContext, useState } from 'react'
import {
TextField,
CircularProgress,
@@ -14,12 +14,15 @@ import { useTheme } from '@material-ui/styles'
import logo from '../images/logo.png'
import { useHistory } from 'react-router-dom'
import { invoke } from '@tauri-apps/api'
+import { ClientContext } from '../context/main'
export const SignIn = () => {
const [mnemonic, setMnemonic] = useState('')
const [inputError, setInputError] = useState()
const [isLoading, setIsLoading] = useState(false)
+ const { logIn } = useContext(ClientContext)
+
const theme: Theme = useTheme()
const history = useHistory()
@@ -30,15 +33,14 @@ export const SignIn = () => {
setInputError(undefined)
invoke('connect_with_mnemonic', { mnemonic })
- .then((res) => {
- setIsLoading(false)
- console.log(res)
- history.push('/bond')
+ .then(() => {
+ logIn()
})
.catch((e) => {
- setIsLoading(false)
setInputError(e)
})
+
+ setIsLoading(false)
}
return (
diff --git a/tauri-wallet/src/theme.tsx b/tauri-wallet/src/theme.tsx
index 7a2e81435a..38e1257ea9 100644
--- a/tauri-wallet/src/theme.tsx
+++ b/tauri-wallet/src/theme.tsx
@@ -29,9 +29,6 @@ export const theme = createTheme({
containedPrimary: {
color: 'white',
},
- text: {
- padding: 'default',
- },
},
MuiStepIcon: {