-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b99fa9
commit 8c93131
Showing
14 changed files
with
290 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ | |
"cSpell.words": [ | ||
"dethcrypto", | ||
"esnext", | ||
"Numberish", | ||
"rainbowkit", | ||
"tailwindcss", | ||
"typechain", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
optimizeFonts: false, | ||
reactStrictMode: true, | ||
swcMinify: true, | ||
swcMinify: true | ||
} | ||
|
||
module.exports = nextConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { RequestProps } from 'pages/request' | ||
|
||
export default function Step1(props: RequestProps) { | ||
const options = ['5', '10', '20', '50', '100'] | ||
|
||
return ( | ||
<div> | ||
<h2 className="font-secondary">Choose your bill denomination</h2> | ||
<div> | ||
{options.map((option, i) => ( | ||
<div | ||
key={`opt_${i}`} | ||
className="cursor-pointer" | ||
onClick={() => { | ||
props.setData({ ...props.data, amountPerBill: option }) | ||
props.setStep(props.step + 1) | ||
}} | ||
> | ||
${option} | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Button from 'components/ui/Button' | ||
import Input from 'components/ui/Input' | ||
import { BigNumber } from 'ethers' | ||
import { RequestProps } from 'pages/request' | ||
|
||
export default function Step2(props: RequestProps) { | ||
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const { value } = e.target | ||
if (value === '' || value.includes('.')) return | ||
|
||
const totalAmount = BigNumber.from(value).mul(props.data.amountPerBill).toString() | ||
props.setData({ ...props.data, numberOfBills: value, totalAmount }) | ||
} | ||
|
||
return ( | ||
<div> | ||
<h2>Enter amount of bills</h2> | ||
<div> | ||
<Input onChange={onChange} value={props.data.numberOfBills} /> | ||
<p>{`Total amount to issue: $${props.data.totalAmount || '0'}`}</p> | ||
</div> | ||
<Button | ||
onClick={() => props.setStep(props.step + 1)} | ||
disabled={props.data.totalAmount.length === 0} | ||
> | ||
Next | ||
</Button> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Button from 'components/ui/Button' | ||
import { BigNumber } from 'ethers' | ||
import useEthereum from 'hooks/useEthereum' | ||
import { RequestProps } from 'pages/request' | ||
import { useState } from 'react' | ||
import { useSigner } from 'wagmi' | ||
|
||
export default function Step3(props: RequestProps) { | ||
const { allyu } = useEthereum() | ||
const { amountPerBill, numberOfBills, totalAmount } = props.data | ||
const [error, setError] = useState<string | null>(null) | ||
const [isLoading, setIsLoading] = useState(false) | ||
|
||
const onClick = async () => { | ||
if (isLoading) return | ||
|
||
try { | ||
if (!props.fee) { | ||
setError('Failed to estimate request fee') | ||
return | ||
} | ||
|
||
setIsLoading(true) | ||
const amountToSend = BigNumber.from(numberOfBills).add(props.fee) | ||
const response = await allyu.requestBills(amountPerBill, numberOfBills, { | ||
value: amountToSend | ||
}) | ||
|
||
await response.wait() | ||
props.setStep(props.step + 1) | ||
} catch (e) { | ||
console.error(e) | ||
setError('Something went wrong') | ||
setIsLoading(false) | ||
} | ||
} | ||
|
||
return ( | ||
<div> | ||
<h2>Confirm your request</h2> | ||
<div> | ||
<div>${totalAmount}</div> | ||
<div>{`${numberOfBills} bills of $${amountPerBill}`}</div> | ||
</div> | ||
<div> | ||
<Button onClick={onClick}>Confirm request</Button> | ||
{error && <div>{error}</div>} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Button from 'components/ui/Button' | ||
import Link from 'next/link' | ||
import { RequestProps } from 'pages/request' | ||
|
||
export default function Step4(props: RequestProps) { | ||
return ( | ||
<div> | ||
<h2>You are all set!</h2> | ||
<div>Your bills will be sent to Agora Bogota</div> | ||
<Link href="/"> | ||
<a> | ||
<Button>Go home</Button> | ||
</a> | ||
</Link> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import { ReactNode } from "react"; | ||
import { ReactNode } from 'react' | ||
export default function Button({ | ||
onClick, | ||
disabled, | ||
children, | ||
children | ||
}: { | ||
onClick?: () => void; | ||
disabled?: boolean; | ||
children: ReactNode; | ||
onClick?: (e: React.MouseEvent<HTMLButtonElement> | undefined) => void | ||
disabled?: boolean | ||
children: ReactNode | ||
}) { | ||
return ( | ||
<button disabled={disabled} onClick={onClick}> | ||
{children} | ||
</button> | ||
); | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
export default function Input() { | ||
return <input /> | ||
export default function Input({ | ||
onChange, | ||
value | ||
}: { | ||
value: string | ||
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void | ||
}) { | ||
return <input onChange={onChange} value={value} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Head, Html, Main, NextScript } from 'next/document' | ||
|
||
export default function Document() { | ||
return ( | ||
<Html lang="en"> | ||
<Head> | ||
<link rel="icon" href="/favicon.ico" /> | ||
<link rel="preconnect" href="https://fonts.googleapis.com" /> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="true" /> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Londrina+Solid&family=Mulish:wght@400;500;700&display=swap" | ||
rel="stylesheet" | ||
/> | ||
<meta property="og:title" content="Allyu" /> | ||
<meta property="og:type" content="website" /> | ||
<meta property="og:description" content="Allyu is the first crypto-backed cash" /> | ||
<meta property="og:url" content="https://www.allyu.xyz" /> | ||
</Head> | ||
<body> | ||
<Main /> | ||
<NextScript /> | ||
</body> | ||
</Html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,79 @@ | ||
import type { NextPage } from "next"; | ||
import Head from "next/head"; | ||
import Step1 from 'components/request/Step1' | ||
import Step2 from 'components/request/Step2' | ||
import Step3 from 'components/request/Step3' | ||
import Step4 from 'components/request/Step4' | ||
import { BigNumberish } from 'ethers' | ||
import useEthereum from 'hooks/useEthereum' | ||
import type { NextPage } from 'next' | ||
import Head from 'next/head' | ||
import { useEffect, useState } from 'react' | ||
|
||
export enum Steps { | ||
Step1 = 1, | ||
Step2 = 2, | ||
Step3 = 3, | ||
Step4 = 4 | ||
} | ||
|
||
export interface RequestData { | ||
amountPerBill: string | ||
numberOfBills: string | ||
totalAmount: string | ||
} | ||
|
||
export interface RequestProps { | ||
fee: BigNumberish | undefined | ||
step: Steps | ||
setStep: (step: Steps) => void | ||
data: RequestData | ||
setData: (data: RequestData) => void | ||
} | ||
|
||
const Request: NextPage = () => { | ||
const { allyu, isConnected } = useEthereum() | ||
const [fee, setFee] = useState<BigNumberish | undefined>() | ||
const [step, setStep] = useState(Steps.Step1) | ||
const [data, setData] = useState<RequestData>({ | ||
amountPerBill: '', | ||
numberOfBills: '', | ||
totalAmount: '' | ||
}) | ||
|
||
useEffect(() => { | ||
const getFee = async () => { | ||
const feePerBill = await allyu.getFeePerBill() | ||
setFee(feePerBill.toString()) | ||
} | ||
|
||
if (isConnected) getFee() | ||
}, [isConnected]) | ||
|
||
const stepsComponents = { | ||
[Steps.Step1]: Step1, | ||
[Steps.Step2]: Step2, | ||
[Steps.Step3]: Step3, | ||
[Steps.Step4]: Step4 | ||
} | ||
|
||
const props: RequestProps = { fee, data, setData, step, setStep } | ||
const Component = stepsComponents[step] | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>Request bills</title> | ||
<meta name="description" content="Request crypto cash" /> | ||
</Head> | ||
<main>Request money</main> | ||
<main> | ||
{step > 1 && ( | ||
<div onClick={() => setStep(step - 1)} className="cursor-pointer"> | ||
{'Go back'} | ||
</div> | ||
)} | ||
<Component {...props} /> | ||
</main> | ||
</> | ||
); | ||
}; | ||
) | ||
} | ||
|
||
export default Request; | ||
export default Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters