Skip to content

Commit 176c5be

Browse files
committed
Merge branch 'main' of github.com:Panda-Wallet/panda-wallet
2 parents 6158c6c + c0f0c39 commit 176c5be

File tree

6 files changed

+62
-37
lines changed

6 files changed

+62
-37
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/ToggleSwitch.tsx

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import styled from "styled-components";
22
import { ChangeEvent } from "react";
3-
import { Theme } from "../theme";
3+
import { ColorThemeProps, Theme } from "../theme";
44

55
const Label = styled.label`
66
display: flex;
@@ -9,52 +9,58 @@ const Label = styled.label`
99
cursor: pointer;
1010
`;
1111

12-
const Switch = styled.div`
12+
const Switch = styled.div<ColorThemeProps>`
1313
position: relative;
14-
width: 60px;
15-
height: 28px;
16-
background: #b3b3b3;
17-
border-radius: 32px;
18-
padding: 4px;
14+
width: 2rem;
15+
height: 1rem;
16+
background: ${({ theme }) => theme.darkAccent + "70"};
17+
border-radius: 2rem;
18+
padding: 0.25rem;
1919
transition: 300ms all;
2020
2121
&:before {
2222
transition: 300ms all;
2323
content: "";
2424
position: absolute;
25-
width: 28px;
26-
height: 28px;
27-
border-radius: 35px;
25+
width: 1.25rem;
26+
height: 1.25rem;
27+
border-radius: 2.1875rem;
2828
top: 50%;
29-
left: 4px;
30-
background: white;
29+
left: 0rem;
30+
background: ${({ theme }) => theme.white};
3131
transform: translate(0, -50%);
3232
}
3333
`;
3434

35-
const Input = styled.input`
35+
const Input = styled.input<ColorThemeProps>`
3636
opacity: 0;
3737
position: absolute;
3838
3939
&:checked + ${Switch} {
40-
background: green;
40+
background: ${({ theme }) => theme.primaryButton + "95"};
4141
4242
&:before {
43-
transform: translate(32px, -50%);
43+
transform: translate(1.25rem, -50%);
4444
}
4545
}
4646
`;
4747

48+
const Text = styled.p<ColorThemeProps>`
49+
color: ${({ theme }) => theme.white};
50+
font-size: 0.85rem;
51+
`;
52+
4853
export type ToggleSwitchProps = {
4954
on: boolean;
50-
label: string;
5155
onLabel: string;
5256
offLabel: string;
5357
theme: Theme;
5458
onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
5559
};
5660

5761
export const ToggleSwitch = (props: ToggleSwitchProps) => {
62+
const { on, onLabel, offLabel, theme } = props;
63+
5864
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
5965
if (props.onChange) {
6066
props.onChange(e);
@@ -63,11 +69,14 @@ export const ToggleSwitch = (props: ToggleSwitchProps) => {
6369

6470
return (
6571
<Label>
66-
<span>
67-
{props.label}: {props.on ? props.onLabel : props.offLabel}
68-
</span>
69-
<Input checked={props.on} type="checkbox" onChange={handleChange} />
70-
<Switch />
72+
<Text theme={theme}>{on ? onLabel : offLabel}</Text>
73+
<Input
74+
checked={on}
75+
type="checkbox"
76+
onChange={handleChange}
77+
theme={theme}
78+
/>
79+
<Switch theme={theme} />
7180
</Label>
7281
);
7382
};

src/contexts/SnackbarContext.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ReactNode, createContext, useState } from "react";
22
import { Snackbar } from "../components/Snackbar";
33
import { useTheme } from "../hooks/useTheme";
4+
import { SNACKBAR_TIMEOUT } from "../utils/constants";
45

56
export type SnackbarType = "error" | "info" | "success";
67

@@ -29,7 +30,7 @@ export const SnackbarProvider = (props: SnackbarProviderProps) => {
2930
setTimeout(() => {
3031
setMessage(null);
3132
setSnackBarType(null);
32-
}, 2500);
33+
}, SNACKBAR_TIMEOUT);
3334
};
3435

3536
return (

src/contexts/WalletLockContext.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ export const WalletLockProvider = (props: WalletLockProviderProps) => {
3939
}
4040

4141
if (currentTime - lastActiveTime > INACTIVITY_LIMIT) {
42-
setIsLocked(true);
43-
storage.remove("appState");
42+
lockWallet();
4443
} else {
4544
setIsLocked(false);
4645
}

src/pages/Settings.tsx

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import { useTheme } from "../hooks/useTheme";
1111
import { useWalletLockState } from "../hooks/useWalletLockState";
1212
import { ToggleSwitch } from "../components/ToggleSwitch";
1313
import { NetWork, useNetwork } from "../hooks/useNetwork";
14+
import { useSnackbar } from "../hooks/useSnackbar";
15+
import { SNACKBAR_TIMEOUT } from "../utils/constants";
1416

1517
const Content = styled.div`
1618
display: flex;
1719
flex-direction: column;
1820
align-items: center;
1921
width: 100%;
20-
position: relative;
2122
`;
2223

2324
const TitleText = styled.h1<ColorThemeProps>`
@@ -29,12 +30,19 @@ const TitleText = styled.h1<ColorThemeProps>`
2930
text-align: center;
3031
`;
3132

33+
const SwitchWrapper = styled.div`
34+
position: absolute;
35+
top: 1rem;
36+
right: 2rem;
37+
`;
38+
3239
export const Settings = () => {
3340
const { theme } = useTheme();
3441
const { setSelected } = useBottomMenu();
3542
const { lockWallet } = useWalletLockState();
3643
const [showSpeedBump, setShowSpeedBump] = useState(false);
3744
const { network, updateNetwork } = useNetwork();
45+
const { addSnackbar } = useSnackbar();
3846

3947
const handleSignOut = async () => {
4048
await storage.clear();
@@ -51,15 +59,31 @@ export const Settings = () => {
5159

5260
const handleLock = () => {
5361
lockWallet();
54-
setSelected("bsv");
62+
// setSelected("bsv");
5563
};
5664

5765
const handleNetworkChange = (e: any) => {
58-
updateNetwork(e.target.checked ? NetWork.Mainnet : NetWork.Testnet)
66+
const network = e.target.checked ? NetWork.Mainnet : NetWork.Testnet;
67+
updateNetwork(network);
68+
69+
// The provider relies on appState in local storage to accurately return addresses. This is an easy way to handle making sure the state is always up to date.
70+
addSnackbar(`Switching to ${network}`, "info");
71+
setTimeout(() => {
72+
window.location.reload();
73+
}, SNACKBAR_TIMEOUT - 500);
5974
};
6075

6176
return (
6277
<Content>
78+
<SwitchWrapper>
79+
<ToggleSwitch
80+
theme={theme}
81+
on={network === NetWork.Mainnet}
82+
onChange={handleNetworkChange}
83+
onLabel="Mainnet"
84+
offLabel="Testnet"
85+
/>
86+
</SwitchWrapper>
6387
<Show
6488
when={!showSpeedBump}
6589
whenFalseContent={
@@ -75,15 +99,6 @@ export const Settings = () => {
7599
<TitleText theme={theme}>⚙️</TitleText>
76100
<TitleText theme={theme}>My Settings</TitleText>
77101
<Text theme={theme}>Page is under active development.</Text>
78-
79-
<ToggleSwitch
80-
theme={theme}
81-
on={network === NetWork.Mainnet}
82-
onChange={handleNetworkChange}
83-
label="Network"
84-
onLabel="Mainnet"
85-
offLabel="Testnet"
86-
/>
87102
<Button
88103
theme={theme}
89104
label="Sign Out"

src/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export const GORILLA_POOL_ARC_URL = "https://arc.gorillapool.io/v1";
99
export const BSV_DECIMAL_CONVERSION = 100000000;
1010
export const FEE_PER_BYTE = 0.02;
1111
export const INACTIVITY_LIMIT = 10 * 60 * 1000; // 10 minutes
12+
export const SNACKBAR_TIMEOUT = 2.5 * 1000; // 2.5 seconds

0 commit comments

Comments
 (0)