Skip to content

Commit

Permalink
feat: add gno faucet button
Browse files Browse the repository at this point in the history
Signed-off-by: Norman Meier <[email protected]>
  • Loading branch information
n0izn0iz committed Sep 26, 2023
1 parent 5da851e commit ecaa8ab
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@
"daoProposalSinglePkgPath": "gno.land/p/demo/teritori/dao_proposal_single_v4",
"daoInterfacesPkgPath": "gno.land/p/demo/teritori/dao_interfaces_v5",
"daoCorePkgPath": "gno.land/p/demo/teritori/dao_core_v4",
"gnowebURL": "https://testnet.gno.teritori.com"
"gnowebURL": "https://testnet.gno.teritori.com",
"faucetURL": "https://testnet.gno.teritori.com:5050/?toaddr=$addr"
}
]
46 changes: 46 additions & 0 deletions packages/components/hub/HubIntro.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import axios from "axios";
import React, { useState } from "react";
import { View } from "react-native";

import { ProfileButton } from "./ProfileButton";
import logoSVG from "../../../assets/logos/logo.svg";
import { useFeedbacks } from "../../context/FeedbacksProvider";
import { useAreThereWallets } from "../../hooks/useAreThereWallets";
import useSelectedWallet from "../../hooks/useSelectedWallet";
import { getNetwork, NetworkKind } from "../../networks";
import { MyNFTs } from "../../screens/WalletManager/MyNFTs";
import { WalletDashboardHeader } from "../../screens/WalletManager/WalletDashboardHeader";
import { Overview } from "../../screens/WalletManager/components/Overview";
Expand All @@ -14,8 +17,10 @@ import { FullWidthSeparator } from "../FullWidthSeparator";
import { Quests } from "../Quests";
import { SVG } from "../SVG";
import { Section } from "../Section";
import { PrimaryButton } from "../buttons/PrimaryButton";
import { MainConnectWalletButton } from "../connectWallet/MainConnectWalletButton";
import { UserAvatarWithFrame } from "../images/AvatarWithFrame";
import { SpacerColumn } from "../spacer";
import { Tabs } from "../tabs/Tabs";

const walletsManagerTabItems = {
Expand Down Expand Up @@ -45,6 +50,8 @@ const ConnectedIntro: React.FC = () => {

<ProfileButton style={{ marginTop: 40 }} />

<FaucetButton />

<Section title="Quests">
<FullWidthSeparator />
<View style={{ marginTop: 20 }}>
Expand All @@ -68,6 +75,45 @@ const ConnectedIntro: React.FC = () => {
);
};

const FaucetButton: React.FC = () => {
const selectedWallet = useSelectedWallet();
const network = getNetwork(selectedWallet?.networkId);
const { wrapWithFeedback } = useFeedbacks();
if (
network?.kind !== NetworkKind.Gno ||
!network.faucetURL ||
!selectedWallet
) {
return null;
}
return (
<>
<SpacerColumn size={4} />
<PrimaryButton
text="Get test tokens"
loader
onPress={wrapWithFeedback(
async () => {
if (!network.faucetURL) {
throw new Error("No faucet for this network");
}
const res = await axios.get(
network.faucetURL.replace("$addr", selectedWallet.address)
);
if (res.status !== 200 || res.data !== "faucet success") {
throw new Error(res.data || "Unexpected error");
}
},
{
title: "Success",
message: "500 GNOTs have been sent to your address",
}
)}
/>
</>
);
};

const DisconnectedIntro: React.FC = () => {
return (
<View
Expand Down
1 change: 1 addition & 0 deletions packages/networks/gno-teritori/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ export const gnoTeritoriNetwork: GnoNetworkInfo = {
daoInterfacesPkgPath: "gno.land/p/demo/teritori/dao_interfaces_v5",
daoCorePkgPath: "gno.land/p/demo/teritori/dao_core_v4",
gnowebURL: "https://testnet.gno.teritori.com",
faucetURL: "https://testnet.gno.teritori.com:5050/?toaddr=$addr",
};
1 change: 1 addition & 0 deletions packages/networks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export type GnoNetworkInfo = NetworkInfoBase & {
daoInterfacesPkgPath?: string;
daoCorePkgPath?: string;
groupsPkgPath?: string;
faucetURL?: string;
};

export type NetworkInfo =
Expand Down

0 comments on commit ecaa8ab

Please sign in to comment.