File tree 4 files changed +46
-24
lines changed
4 files changed +46
-24
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,9 @@ function formatMoney(amount) {
43
43
}
44
44
45
45
const Stats = ( { stats } ) => {
46
+ if ( stats . transactions_volume === undefined ) {
47
+ return null
48
+ }
46
49
const [ balance , setBalance ] = useState ( 0 ) // A formatted balance string, split by decimal
47
50
48
51
useEffect ( ( ) => {
@@ -64,7 +67,6 @@ const Stats = ({ stats }) => {
64
67
65
68
return ( ) => observer . disconnect ( )
66
69
} , [ stats . transactions_volume ] )
67
-
68
70
return (
69
71
< Box id = "parent" >
70
72
< Flex sx = { { flexDirection : 'column' , alignItems : 'center' } } >
@@ -103,11 +105,20 @@ const Stats = ({ stats }) => {
103
105
104
106
export async function getStaticProps ( context ) {
105
107
const res = await fetch ( `https://hcb.hackclub.com/stats` )
106
- const stats = await res . json ( )
107
-
108
- return {
109
- props : {
110
- stats
108
+ try {
109
+ const stats = await res . json ( )
110
+ return {
111
+ props : {
112
+ stats
113
+ } ,
114
+ revalidate : 10
115
+ }
116
+ } catch ( e ) {
117
+ return {
118
+ props : {
119
+ stats : { }
120
+ } ,
121
+ revalidate : 10
111
122
}
112
123
}
113
124
}
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ export default function Bank({ data }) {
20
20
color : 'snow'
21
21
} }
22
22
badge
23
- text = { data [ 0 ] }
23
+ text = { data [ 0 ] === 'error' ? 'The coolest money thing' : data [ 0 ] }
24
24
>
25
25
< Heading
26
26
variant = "title"
Original file line number Diff line number Diff line change @@ -184,12 +184,20 @@ export default function First({ stats }) {
184
184
185
185
export async function getStaticProps ( context ) {
186
186
const res = await fetch ( `https://hcb.hackclub.com/stats` )
187
- const stats = await res . json ( )
188
-
189
- return {
190
- props : {
191
- stats
192
- } ,
193
- revalidate : 10
187
+ try {
188
+ const stats = await res . json ( )
189
+ return {
190
+ props : {
191
+ stats
192
+ } ,
193
+ revalidate : 60 * 60 // once an hour
194
+ }
195
+ } catch ( e ) {
196
+ return {
197
+ props : {
198
+ stats : { }
199
+ } ,
200
+ revalidate : 60 * 60 // once an hour
201
+ }
194
202
}
195
203
}
Original file line number Diff line number Diff line change @@ -1221,17 +1221,20 @@ export async function getStaticProps() {
1221
1221
1222
1222
// HCB: get total raised
1223
1223
let bankData = [ ]
1224
- let initialBankData = await fetch ( 'https://hcb.hackclub.com/stats' ) . then ( r =>
1225
- r . json ( )
1226
- )
1227
- let raised = initialBankData . raised / 100
1224
+ let initialBankData = await fetch ( 'https://hcb.hackclub.com/stats' )
1225
+ try {
1226
+ const bd = await initialBankData . json ( )
1227
+ let raised = bd . raised / 100
1228
1228
1229
- bankData . push (
1230
- `💰 ${ raised . toLocaleString ( 'en-US' , {
1231
- style : 'currency' ,
1232
- currency : 'USD'
1233
- } ) } raised`
1234
- )
1229
+ bankData . push (
1230
+ `💰 ${ raised . toLocaleString ( 'en-US' , {
1231
+ style : 'currency' ,
1232
+ currency : 'USD'
1233
+ } ) } raised`
1234
+ )
1235
+ } catch {
1236
+ bankData . push ( 'error' )
1237
+ }
1235
1238
1236
1239
// Slack: get total raised
1237
1240
const { Slack : Slacky } = require ( './api/slack' )
You can’t perform that action at this time.
0 commit comments