5
5
ref =" DOMpopup"
6
6
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"
7
7
>
8
- <div ref =" DOMFaucetRequest" class =" p -12" >
8
+ <div ref =" DOMFaucetRequest" class =" py -12 px-20 w-full " >
9
9
<FaucetContentForm :name =" store.selectedFaucet.name ?? 'Faucet'" :options =" store.faucetAmount" v-show =" store.contentStep === 0" class =" js-faucetform opacity-100" :error =" error" @requestFaucet =" requestFaucet" />
10
10
<div >
11
11
<div ref =" gnoRequestLogo" v-show =" store.contentStep >= 1" class =" opacity-0" >
@@ -31,8 +31,7 @@ import GnoJSON from '@/assets/lottie/logo.json'
31
31
32
32
import { useFaucetDetail } from ' @/stores/faucetDetail'
33
33
34
- // import { req } from '@/data/mockedRequest'
35
- import { Status , Request , FaucetResponse } from ' @/types'
34
+ import { Request , FaucetResponse } from ' @/types'
36
35
37
36
const txLink = ref (' ' )
38
37
@@ -44,7 +43,7 @@ const DOMFaucetRequest = ref<HTMLElement | null>(null)
44
43
const gnoRequestLogo = ref <HTMLElement | null >(null )
45
44
46
45
const popupHeight = reactive ({ from: 0 , to: 0 })
47
- const error = ref <Status | null >(null )
46
+ const error = ref <string | null >(null )
48
47
49
48
const requestFaucet = async (address : string , amount : number , secret : string ) => {
50
49
popupHeight .from = DOMpopup .value ?.getBoundingClientRect ().height ?? 0
@@ -60,38 +59,36 @@ const requestFaucet = async (address: string, amount: number, secret: string) =>
60
59
})
61
60
gsap .to (gnoRequestLogo .value , { autoAlpha: 1 , delay: 0.5 })
62
61
63
- console .log (address )
64
- console .log (amount )
65
- console .log (secret )
66
-
67
- const opt: Request = {
68
- to: address ,
69
- amount: amount .toString (),
70
- captcha: secret ,
71
- }
62
+ // default
63
+ const minTimer = new Promise ((resolve ) => setTimeout (resolve , 2000 ))
72
64
73
65
try {
74
- const { data } : { data : FaucetResponse } = await axios . post (store .selectedFaucet .url , {
75
- opt ,
66
+ const response = await fetch (store .selectedFaucet .url , {
67
+ method: ' POST ' ,
76
68
headers: {
77
- Accept: ' application/json' ,
78
- ' Content-Type' : ' application/json;charset=UTF-8' ,
69
+ ' Content-Type' : ' application/json' ,
79
70
},
71
+ body: JSON .stringify ({
72
+ to: address ,
73
+ amount: amount .toString (),
74
+ captcha: secret ,
75
+ }),
80
76
})
81
77
82
- console .log (data )
78
+ await minTimer
79
+ const faucetResponse = await response .json ()
80
+
81
+ store .status = ! faucetResponse .result ? ' error' : ' success'
83
82
84
- // TODO: check types and error / result content
85
- if (data . error ) {
86
- error .value = data .error
83
+ // Check the faucet response
84
+ if (! response . ok || store . status === ' error' ) {
85
+ error .value = faucetResponse .error . message
87
86
store .contentStep = 0
88
- throw new Error (data .error )
89
87
} else {
90
- store .status = ' success'
91
- txLink .value = data .result ?? ' '
88
+ txLink .value = faucetResponse .result ?? ' '
92
89
}
93
90
} catch (e ) {
94
- console .error (' error ' + e )
91
+ console .log (' error : ' + e )
95
92
}
96
93
}
97
94
0 commit comments