Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
feat: add facuet button in testnet mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Sep 25, 2020
1 parent 2127681 commit 5768896
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
5 changes: 5 additions & 0 deletions app/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ async function getTxDetails(txid: string) {
return axios.get<Transaction | MempoolTransaction>(api + `/v1/tx/${txid}`);
}

async function getFaucetStx(address: string) {
return axios.post(api + `/v1/debug/faucet?address=${address}`, { address });
}

export const Api = {
getAddressBalance,
getAddressTransactions,
getTxDetails,
getFaucetStx,
};
24 changes: 20 additions & 4 deletions app/components/home/balance-card.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import React, { FC } from 'react';
import React, { FC, useState } from 'react';
import { Box, Button, Text, ArrowIcon } from '@blockstack/ui';
import { toHumanReadableStx } from '../../utils/unit-convert';
import { safeAwait } from '../../utils/safe-await';
import { delay } from '../../utils/delay';

interface BalanceCardProps {
balance: string | null;
onSelectSend: () => void;
onSelectReceive: () => void;
onSelectSend(): void;
onSelectReceive(): void;
onRequestTestnetStx(): Promise<any>;
}

export const BalanceCard: FC<BalanceCardProps> = ({ balance, onSelectReceive, onSelectSend }) => {
export const BalanceCard: FC<BalanceCardProps> = args => {
const { balance, onSelectReceive, onSelectSend, onRequestTestnetStx } = args;
const [requestingTestnetStx, setRequestingTestnetStx] = useState(false);
const requestTestnetStacks = async () => {
setRequestingTestnetStx(true);
await safeAwait(Promise.allSettled([onRequestTestnetStx(), delay(1500)]));
setRequestingTestnetStx(false);
};
return (
<Box>
<Text textStyle="body.large.medium" display="block">
Expand All @@ -26,6 +36,12 @@ export const BalanceCard: FC<BalanceCardProps> = ({ balance, onSelectReceive, on
<ArrowIcon direction="down" mr="base-tight" />
Receive
</Button>
<Button mode="secondary" size="md" ml="tight" onClick={requestTestnetStacks}>
<Box mr="extra-tight" fontSize="18px" left="-4px" position="relative">
🚰
</Box>
{requestingTestnetStx ? 'Requesting faucet' : 'Get testnet STX'}
</Button>
</Box>
</Box>
);
Expand Down
12 changes: 9 additions & 3 deletions app/modals/transaction/decrypt-wallet-form.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC } from 'react';
import { Box, Input, Text, Button } from '@blockstack/ui';
import { Box, Input, Text } from '@blockstack/ui';
import { ErrorLabel } from '../../components/error-label';
import { ErrorText } from '../../components/error-text';

Expand Down Expand Up @@ -31,9 +31,15 @@ export const DecryptWalletForm: Props = args => {
)}
<Text textStyle="body.small" mt="base-tight" mb="base-loose" display="block">
Forgot password?{' '}
<Button variant="link" onClick={onForgottenPassword}>
<Text
as="button"
color="blue"
fontWeight={500}
onClick={onForgottenPassword}
_focus={{ textDecoration: 'underline', outline: 0 }}
>
Reset your wallet
</Button>{' '}
</Text>{' '}
to set a new password.
</Text>
</Box>
Expand Down
7 changes: 5 additions & 2 deletions app/modals/transaction/transaction-form.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC } from 'react';
import { Flex, Text, Input, Box } from '@blockstack/ui';
import { Flex, Text, Input, Box, Button } from '@blockstack/ui';
import { ErrorLabel } from '../../components/error-label';
import { ErrorText } from '../../components/error-text';
import { FormikProps } from 'formik';
Expand All @@ -9,9 +9,12 @@ import { toHumanReadableStx } from '../../utils/unit-convert';
interface TxModalFormProps {
balance: string;
form: FormikProps<{ recipient: string; amount: string; memo: string }>;
isCalculatingMaxSpend: boolean;
onSendEntireBalance(): void;
}

export const TxModalForm: FC<TxModalFormProps> = ({ balance, form }) => {
export const TxModalForm: FC<TxModalFormProps> = args => {
const { balance, form, isCalculatingMaxSpend, onSendEntireBalance } = args;
return (
<Box mb="extra-loose">
<Flex flexDirection="column" alignItems="center" mt="48px">
Expand Down
2 changes: 1 addition & 1 deletion app/pages/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function App(props: Props) {
justifyContent="space-between"
pl="90px"
height="100%"
backgroundColor={winState === 'focused' ? null : '#FAFAFC'}
backgroundColor={winState === 'focused' ? 'white' : '#FAFAFC'}
>
<BackButton
backUrl={backUrl}
Expand Down
1 change: 1 addition & 0 deletions app/pages/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const Home: FC = () => {
balance={balance}
onSelectSend={() => dispatch(homeActions.openTxModal())}
onSelectReceive={() => dispatch(homeActions.openReceiveModal())}
onRequestTestnetStx={async () => Api.getFaucetStx(address)}
/>
);
const stackingPromoCard = <StackingPromoCard />;
Expand Down

0 comments on commit 5768896

Please sign in to comment.