Skip to content

Commit c96aafa

Browse files
committed
fix: fetch
2 parents 4ac232d + 676fa6d commit c96aafa

File tree

9 files changed

+61
-54
lines changed

9 files changed

+61
-54
lines changed

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ onMounted(() => {
4545
<main class="js-main flex flex-col justify-between min-h-screen">
4646
<Header />
4747
<section class="px-4 md:px-14 lg:px-20 mx-auto max-w-[110rem] w-full grid grid-cols-12">
48-
<h1 class="col-span-12 lg:col-span-5 font-termina text-600 md:text-700 text-center md:text-left" ref="DOMTitle">Welcome to Faucet Hub</h1>
48+
<h1 class="col-span-12 lg:col-span-5 font-termina text-600 md:text-700 text-center md:text-left" ref="DOMTitle">Welcome to the Faucet Hub</h1>
4949
<FaucetsList />
5050
</section>
5151

src/components/faucet/FaucetAvailability.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const props = defineProps<Props>()
1212
:class="props.available ? 'bg-green-900 before:bg-green-200' : 'bg-red-900 before:bg-red-200'"
1313
>
1414
<span :class="props.available ? 'text-green-200' : 'text-red-200'">{{
15-
props.available ? 'Enough faucet' : 'Empty. Try Later'
16-
}}</span>
15+
props.available ? 'Available' : 'Unavailable'
16+
}}</span>
1717
</div>
1818
</template>

src/components/faucet/FaucetCard.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
22
<Card :tracker="tracker">
3-
<FaucetAvailability :available="availability" class="self-end" />
3+
<FaucetAvailability :available="true" class="self-end" />
44
<div class="mt-28">
5-
<span class="mb-2 text-grey-100 text-50 uppercase" v-if="faucet.Network">{{ faucet.Network }}</span>
6-
<h2 class="text-500 text-grey-50">{{ faucet.Name }}</h2>
5+
<span class="mb-2 text-grey-100 text-50 uppercase">{{ faucet.chain_id }}</span>
6+
<h2 class="text-500 text-grey-50">{{ faucet.name }}</h2>
77
</div>
88
</Card>
99
</template>

src/components/faucet/FaucetDetail.vue

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class="popup fixed flex flex-col items-center rounded w-[90vw] max-w-[36rem] bg-grey-300 top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[1000] justify-center text-grey-50 before:absolute before:top-0 before:bottom-0 before:left-0 before:right-0 before:rounded before:bg-500 before:z-min after:absolute after:top-px after:left-px after:bottom-px after:right-px after:bg-grey-500 after:rounded after:z-min"
77
>
88
<div ref="DOMFaucetRequest" class="p-12">
9-
<FaucetContentForm :name="store.selectedFaucet.Name ?? 'Faucet'" :options="store.faucetAmount" v-show="store.contentStep === 0" class="js-faucetform opacity-100" :error="error" @requestFaucet="requestFaucet" />
9+
<FaucetContentForm :name="store.selectedFaucet.name ?? 'Faucet'" :options="store.faucetAmount" v-show="store.contentStep === 0" class="js-faucetform opacity-100" :error="error" @requestFaucet="requestFaucet" />
1010
<div>
1111
<div ref="gnoRequestLogo" v-show="store.contentStep >= 1" class="opacity-0">
1212
<Vue3Lottie :animationData="GnoJSON" :loop="true" :height="200" :width="200" :autoPlay="true" />
@@ -32,7 +32,7 @@ import GnoJSON from '@/assets/lottie/logo.json'
3232
import { useFaucetDetail } from '@/stores/faucetDetail'
3333
3434
// import { req } from '@/data/mockedRequest'
35-
import { Status, Request } from '@/types'
35+
import { Status, Request, FaucetResponse } from '@/types'
3636
3737
const txLink = ref('')
3838
@@ -60,26 +60,38 @@ const requestFaucet = async (address: string, amount: number, secret: string) =>
6060
})
6161
gsap.to(gnoRequestLogo.value, { autoAlpha: 1, delay: 0.5 })
6262
63-
const data: Request = {
64-
To: address,
65-
Amount: amount.toString(),
66-
Captcha: secret,
67-
}
68-
6963
console.log(address)
7064
console.log(amount)
7165
console.log(secret)
7266
73-
await axios.get(store.selectedFaucet.URL, { data })
67+
const opt: Request = {
68+
to: address,
69+
amount: amount.toString(),
70+
captcha: secret,
71+
}
7472
75-
const res = await req('success')
76-
store.status = res.code
73+
try {
74+
const { data }: { data: FaucetResponse } = await axios.post(store.selectedFaucet.url, {
75+
opt,
76+
headers: {
77+
Accept: 'application/json',
78+
'Content-Type': 'application/json;charset=UTF-8',
79+
},
80+
})
7781
78-
if (store.status === 'error') {
79-
error.value = res.status
80-
store.contentStep = 0
81-
} else {
82-
txLink.value = res.txLink ?? ''
82+
console.log(data)
83+
84+
//TODO: check types and error / result content
85+
if (data.error) {
86+
error.value = data.error
87+
store.contentStep = 0
88+
throw new Error(data.error)
89+
} else {
90+
store.status = 'success'
91+
txLink.value = data.result ?? ''
92+
}
93+
} catch (e) {
94+
console.error('error ' + e)
8395
}
8496
}
8597

src/components/faucet/FaucetsList.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<template>
22
<div ref="projectCarouselEL" class="col-span-12 my-20">
33
<Carousel name="Carousel">
4-
<li v-for="(faucet, idx) in faucets" :key="idx" class="js-card p-4 flex-none w-full" role="group" aria-roledescription="slide">
4+
<li v-for="(faucet, idx) in faucets" :key="idx" class="js-card p-4 flex-none w-full" role="group"
5+
aria-roledescription="slide">
56
<div ref="cards" class="translate-x-12 opacity-0 h-full" @click.prevent="openFaucet(faucet)">
6-
<FaucetCard :data-ref="motions[idx].value.id" :motion="width >= 768 ? motions[idx] : undefined" :data-index="idx" :faucet="faucet" :is-loading="isLoading" />
7+
<FaucetCard :data-ref="motions[idx].value.id" :motion="width >= 768 ? motions[idx] : undefined"
8+
:data-index="idx" :faucet="faucet" :is-loading="isLoading" />
79
</div>
810
</li>
911
</Carousel>

src/components/faucet/content/FaucetContentForm.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
<h2 class="text-600 mb-12">{{ name }}</h2>
44
<form class="w-full space-y-12" @submit.prevent="requestFaucet">
55
<Input :label="'Enter your wallet address'" :placeholder="'e.g. g1juwee0ynsdvaukvxk3j5s4cl6nn24uxwlydxrl'" v-model="bindAddress" />
6-
<Select v-if="store.selectedFaucet.Amounts" :label="'Select faucet amount'" :options="options" @update="(option) => SelectAmount(option)" />
6+
<Select v-if="store.selectedFaucet.amounts" :label="'Select faucet amount'" :options="options" @update="(option) => SelectAmount(option)" />
77
<Recaptcha @validation="captchaValidation" />
88
<div>
99
<div class="flex gap-4">
10+
<Button text="Request drip" class="w-full" type="submit" />
1011
<Button text="Cancel" variant="outline" @click.prevent="() => closePopup()" class="w-full" />
11-
<Button text="Request Faucet" class="w-full" type="submit" />
1212
</div>
1313
<div v-if="error" class="text-center text-red-200 mt-6">{{ errorDetail[error] }}</div>
1414
</div>
@@ -30,7 +30,7 @@ import { SelectOption } from '@/components/ui/Select.vue'
3030
import { Status, Faucet } from '@/types'
3131
3232
type Props = {
33-
name: Faucet['Name']
33+
name: Faucet['name']
3434
options: SelectOption[]
3535
error?: Status | null
3636
}
@@ -63,6 +63,6 @@ const errorDetail = {
6363
6464
const requestFaucet = () => {
6565
if (captchaValid.value === false) return
66-
emit('requestFaucet', bindAddress.value, store.selectedFaucet.Amounts && amount.value?.value, captchaSecret.value)
66+
emit('requestFaucet', bindAddress.value, store.selectedFaucet.amounts && amount.value?.value, captchaSecret.value)
6767
}
6868
</script>

src/data/faucets.json

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
{
22
"faucets": [
33
{
4-
"Name": "Very long network name 1",
5-
"Network": "network name",
6-
"Amounts": [5, 10, 20],
7-
"URL": "",
8-
"ReCaptcha": ""
9-
},
10-
{
11-
"Name": "Very long network name 2",
12-
"Network": "network name",
13-
"Token": "$GNOT",
14-
"URL": "",
15-
"ReCaptcha": ""
4+
"name": "Gno Portal Loop",
5+
"chain_id": "portal-loop",
6+
"amounts": [1, 5, 10],
7+
"url": "https://rpc.gno.land:443",
8+
"recaptcha": "6Lc245EpAAAAAJHI6WezI7VSsy6NiKTq1I7OLlUy"
169
}
1710
]
1811
}

src/stores/faucetDetail.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export const useFaucetDetail = defineStore('faucetDetail', {
2020
}),
2121
getters: {
2222
faucetAmount: (state) =>
23-
state.selectedFaucet.Amounts?.map((amount: number) => ({
24-
content: `${amount} ${state.selectedFaucet.Token ?? '$GNOT'}`,
23+
state.selectedFaucet.amounts?.map((amount: number) => ({
24+
content: `${amount} ${state.selectedFaucet?.token ?? '$GNOT'}`,
2525
value: amount,
2626
})) ?? [{ content: '', value: 0 }],
2727
},

src/types/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ export type Status = 'FAIL' | 'EMPTY' | 'INVALID_ADDRESS' | 'BUSY_FAUCET' | unde
44
export type Code = 'success' | 'error'
55

66
export interface Faucet {
7-
Name: string // name of the testnet
8-
Amounts?: number[] // faucet serve amounts (UI)
9-
URL: string // the faucet URL
10-
ReCaptcha: string // the recaptcha site key, if any
11-
Network?: string // name of the network if any
12-
Token?: string // token name - $GNOT by default
7+
name: string // name of the testnet
8+
chain_id: string // name of the testnet
9+
amounts: number[] // faucet serve amounts (UI)
10+
url: string // the faucet URL
11+
recaptcha: string // the recaptcha site key, if any
12+
token?: string // token name: default $GNOT
1313
}
1414

1515
export interface Request {
16-
To: string // recipient address
17-
Amount: string // <AMOUNT>ugnot
18-
Captcha: string
16+
to: string // recipient address
17+
amount: string // <AMOUNT>ugnot
18+
captcha: string
1919
}
2020

21-
export interface Response {
22-
Result: string //json: "result
23-
Error: string //json: error,omitempty
21+
export interface FaucetResponse {
22+
result: string //json: "result
23+
error: Status //json: error,omitempty
2424
}

0 commit comments

Comments
 (0)