Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 53 additions & 31 deletions src/components/Faucet/Faucet.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,65 @@
import axios from 'axios';
import { TextInput, Text, Paper, Button, Divider, Anchor, Stack, Alert } from '@mantine/core';
import { useForm } from '@mantine/form';
import { notifications } from '@mantine/notifications';
import { IconAlertCircle, IconExternalLink, IconCheck, IconX } from '@tabler/icons-react';
import axios from "axios";
import {
TextInput,
Text,
Paper,
Button,
Divider,
Anchor,
Stack,
Alert,
} from "@mantine/core";
import { useForm } from "@mantine/form";
import { notifications } from "@mantine/notifications";
import {
IconAlertCircle,
IconExternalLink,
IconCheck,
IconX,
} from "@tabler/icons-react";

import { useConnection } from '@/contexts/TezosContext/TezosContext';
import { WalletButton } from '@/components/WalletButton/WalletButton';
import { TezosIcon } from '@/icons/TezosIcon/TezosIcon';
import { useConnection } from "@/contexts/TezosContext/TezosContext";
import { WalletButton } from "@/components/WalletButton/WalletButton";
import { TezosIcon } from "@/icons/TezosIcon/TezosIcon";

export function Faucet() {
const { address, connect } = useConnection();
const form = useForm({
initialValues: {
address: '',
address: "",
},
});

const getTokens = async (targetAddress: string) => {
try {
notifications.show({
id: 'faucet',
title: 'Sending...',
message: 'Your tokens are on the way! 🚀',
id: "faucet",
title: "Sending...",
message: "Your tokens are on the way! 🚀",
loading: true,
autoClose: false,
});

await axios.get(
`https://faucet-bot.marigold.dev/network/ghostnet/getmoney/CTEZ/${targetAddress}`
`https://faucet-bot.marigold.dev/network/ghostnet/getmoney/CTEZ/${targetAddress}`,
);

notifications.update({
id: 'faucet',
title: 'Success!',
message: 'Check your wallet !',
id: "faucet",
title: "Success!",
message: "Check your wallet !",
icon: <IconCheck size="1.1rem" />,
color: 'teal',
color: "teal",
});
} catch (err: any) {
} catch (error: unknown) {
notifications.update({
id: 'faucet',
title: 'Error!',
message: `Something went wrong: ${(err as Error).message}`,
id: "faucet",
title: "Error!",
message: `Something went wrong: ${
error instanceof Error ? error.message : "Unknown request error"
}`,
icon: <IconX size="1.1rem" />,
color: 'red',
color: "red",
});
}
};
Expand All @@ -53,7 +69,7 @@ export function Faucet() {
<Alert icon={<IconAlertCircle size="1rem" />} mb="1.5rem">
This faucet is provided by Marigold. <br />
<Anchor href="https://faucet.marigold.dev" target="_blank">
{' '}
{" "}
Check it out. <IconExternalLink size="0.8rem" />
</Anchor>
</Alert>
Expand All @@ -67,13 +83,19 @@ export function Faucet() {
<WalletButton
radius="xl"
size="lg"
// leftIcon={<TezosIcon />}
onClick={async () => getTokens(address)}
onClick={() => {
void getTokens(address);
}}
>
Request ctez tokens for {address}
</WalletButton>
) : (
<WalletButton radius="xl" size="lg" leftIcon={<TezosIcon />} onClick={connect}>
<WalletButton
radius="xl"
size="lg"
leftIcon={<TezosIcon />}
onClick={connect}
>
Connect
</WalletButton>
)}
Expand All @@ -86,9 +108,7 @@ export function Faucet() {

<form
onSubmit={form.onSubmit((values) => {
(async () => {
await getTokens(values.address);
})();
void getTokens(values.address);
})}
>
<Stack>
Expand All @@ -97,8 +117,10 @@ export function Faucet() {
label="Tezos address"
placeholder="tz1..."
value={form.values.address}
onChange={(event) => form.setFieldValue('address', event.currentTarget.value)}
error={form.errors.email && 'Invalid address'}
onChange={(event) =>
form.setFieldValue("address", event.currentTarget.value)
}
error={form.errors.address && "Invalid address"}
radius="xl"
size="lg"
/>
Expand Down
91 changes: 64 additions & 27 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,61 @@ import {
Button,
useMantineColorScheme,
Badge,
} from '@mantine/core';
} from "@mantine/core";
import {
IconSun,
IconMoonStars,
IconPlugConnectedX,
IconChevronDown,
IconSwitchHorizontal,
IconNetwork,
} from '@tabler/icons-react';
import { NetworkType } from '@airgap/beacon-types';
} from "@tabler/icons-react";
import { NetworkType } from "@airgap/beacon-types";
import { notifications } from "@mantine/notifications";

import { useConnection } from '@/contexts/TezosContext/TezosContext';
import { TezosIcon } from '@/icons/TezosIcon/TezosIcon';
import { WalletButton } from '@/components/WalletButton/WalletButton';
import { shortAddress } from '@/lib/utils/utils';
import { useConnection } from "@/contexts/TezosContext/TezosContext";
import { TezosIcon } from "@/icons/TezosIcon/TezosIcon";
import { WalletButton } from "@/components/WalletButton/WalletButton";
import { shortAddress } from "@/lib/utils/utils";

const useStyles = createStyles((theme) => ({
inner: {
height: rem(56),
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
display: "flex",
justifyContent: "space-between",
alignItems: "center",
},

links: {
[theme.fn.smallerThan('sm')]: {
display: 'none',
[theme.fn.smallerThan("sm")]: {
display: "none",
},
},

burger: {
[theme.fn.largerThan('sm')]: {
display: 'none',
[theme.fn.largerThan("sm")]: {
display: "none",
},
},

link: {
display: 'block',
display: "block",
lineHeight: 1,
padding: `${rem(8)} ${rem(12)}`,
borderRadius: theme.radius.sm,
textDecoration: 'none',
color: theme.colorScheme === 'dark' ? theme.colors.dark[0] : theme.colors.gray[7],
textDecoration: "none",
color:
theme.colorScheme === "dark"
? theme.colors.dark[0]
: theme.colors.gray[7],
fontSize: theme.fontSizes.sm,
fontWeight: 500,

'&:hover': {
backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[0],
"&:hover": {
backgroundColor:
theme.colorScheme === "dark"
? theme.colors.dark[6]
: theme.colors.gray[0],
},
},

Expand All @@ -71,14 +78,26 @@ export function Header() {
const { classes } = useStyles();
const { address, connect, disconnect, network } = useConnection();

const runWalletAction = (action: () => Promise<void>): void => {
void action().catch((error: unknown) => {
notifications.show({
id: "wallet-action-error",
title: "Wallet action failed",
message:
error instanceof Error ? error.message : "Unknown wallet error",
color: "red",
});
});
};

return (
<MantineHeader height={56} mb={120}>
<Container>
<div className={classes.inner}>
<Group>
<Text fw={700}>Etherlink Bridge</Text>
<Badge variant="outline" color="red">
{network === NetworkType.MAINNET ? 'Mainnet' : 'Testnet'}
{network === NetworkType.MAINNET ? "Mainnet" : "Testnet"}
</Badge>
</Group>
<Group position="center" my="xl">
Expand All @@ -88,7 +107,9 @@ export function Header() {
variant="default"
color="gray"
radius="xl"
leftIcon={<IconNetwork style={{ width: '80%', height: '80%' }} />}
leftIcon={
<IconNetwork style={{ width: "80%", height: "80%" }} />
}
rightIcon={<IconChevronDown size="1.2rem" />}
disabled
>
Expand All @@ -110,20 +131,27 @@ export function Header() {
</Button>
</Menu.Target>
<Menu.Dropdown>
<Menu.Item icon={<IconSwitchHorizontal size={14} />} onClick={connect}>
<Menu.Item
icon={<IconSwitchHorizontal size={14} />}
onClick={() => runWalletAction(connect)}
>
Switch Account
</Menu.Item>
<Menu.Item
color="red"
icon={<IconPlugConnectedX size={14} />}
onClick={disconnect}
onClick={() => runWalletAction(disconnect)}
>
Disconnect
</Menu.Item>
</Menu.Dropdown>
</Menu>
) : (
<WalletButton radius="xl" leftIcon={<TezosIcon />} onClick={connect}>
<WalletButton
radius="xl"
leftIcon={<TezosIcon />}
onClick={() => runWalletAction(connect)}
>
Connect
</WalletButton>
)}
Expand All @@ -133,11 +161,20 @@ export function Header() {
radius="xl"
sx={(theme) => ({
backgroundColor:
theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[0],
color: theme.colorScheme === 'dark' ? theme.colors.yellow[4] : theme.colors.blue[6],
theme.colorScheme === "dark"
? theme.colors.dark[6]
: theme.colors.gray[0],
color:
theme.colorScheme === "dark"
? theme.colors.yellow[4]
: theme.colors.blue[6],
})}
>
{colorScheme === 'dark' ? <IconSun size="1.2rem" /> : <IconMoonStars size="1.2rem" />}
{colorScheme === "dark" ? (
<IconSun size="1.2rem" />
) : (
<IconMoonStars size="1.2rem" />
)}
</ActionIcon>
</Group>
</div>
Expand Down
Loading