1
- import React , { ReactNode , useEffect , useState } from 'react' ;
1
+ import React , { useEffect , useState } from 'react' ;
2
2
3
3
import { ChainType } from '@/shared/constant' ;
4
4
import { BabylonPhaseState } from '@/shared/constant/babylon' ;
5
5
import { COSMOS_CHAINS_MAP } from '@/shared/constant/cosmosChain' ;
6
6
import { runesUtils } from '@/shared/lib/runes-utils' ;
7
7
import { BabylonAddressSummary , BabylonStakingStatusV2 } from '@/shared/types' ;
8
8
import { Button , Column , Content , Header , Icon , Image , Layout , Row , Text } from '@/ui/components' ;
9
+ import { useTools } from '@/ui/components/ActionComponent' ;
9
10
import { Loading } from '@/ui/components/ActionComponent/Loading' ;
10
11
import { CopyableAddress } from '@/ui/components/CopyableAddress' ;
11
12
import { Popover } from '@/ui/components/Popover' ;
12
13
import { useBabylonConfig , useChain , useChainType } from '@/ui/state/settings/hooks' ;
13
- import { fontSizes } from '@/ui/theme/font' ;
14
14
import { satoshisToAmount , useWallet } from '@/ui/utils' ;
15
15
16
16
import { useNavigate } from '../MainRoute' ;
@@ -79,9 +79,7 @@ function Section2(props: { icon: React.ReactElement; title?: string; value?: str
79
79
< Text text = { props . value } size = "sm" preset = "bold" color = "white" />
80
80
</ Column >
81
81
</ Row >
82
- < Row itemsCenter >
83
- { props . button }
84
- </ Row >
82
+ < Row itemsCenter > { props . button } </ Row >
85
83
</ Row >
86
84
) ;
87
85
}
@@ -119,39 +117,36 @@ function Section3(props: { onClick: () => void }) {
119
117
}
120
118
121
119
function EnableImportBabyPopover ( { onClose } : { onClose : ( ) => void } ) {
122
-
123
120
function StepIcon ( { step } : { step : number } ) {
124
- return < Row
125
- itemsCenter
126
- justifyCenter
127
- style = { {
128
- width : 26 ,
129
- minWidth : 26 ,
130
- height : 26 ,
131
- minHeight : 26 ,
132
- borderRadius : 13 ,
133
- backgroundColor : '#F4B62C33'
134
- } } >
135
- < Text text = { step } style = { { color : '#F4B62C' } } size = "sm" />
136
- </ Row > ;
121
+ return (
122
+ < Row
123
+ itemsCenter
124
+ justifyCenter
125
+ style = { {
126
+ width : 26 ,
127
+ minWidth : 26 ,
128
+ height : 26 ,
129
+ minHeight : 26 ,
130
+ borderRadius : 13 ,
131
+ backgroundColor : '#F4B62C33'
132
+ } } >
133
+ < Text text = { step } style = { { color : '#F4B62C' } } size = "sm" />
134
+ </ Row >
135
+ ) ;
137
136
}
138
137
139
- function StepItem ( { step, title, images } : {
140
- step : number ;
141
- title : string ;
142
- images : string [ ] ;
143
- } ) {
144
- return < Row style = { { alignSelf :'stretch' } } >
145
- < StepIcon step = { step } />
146
- < Column gap = { 'md' } >
147
- < Text size = { 'sm' } color = { 'light' } text = { title } />
148
- {
149
- images . map ( ( image , index ) => {
138
+ function StepItem ( { step, title, images } : { step : number ; title : string ; images : string [ ] } ) {
139
+ return (
140
+ < Row style = { { alignSelf : 'stretch' } } >
141
+ < StepIcon step = { step } />
142
+ < Column gap = { 'md' } >
143
+ < Text size = { 'sm' } color = { 'light' } text = { title } />
144
+ { images . map ( ( image , index ) => {
150
145
return < Image key = { index } src = { image } width = { '100%' } height = { 'unset' } /> ;
151
- } )
152
- }
153
- </ Column >
154
- </ Row > ;
146
+ } ) }
147
+ </ Column >
148
+ </ Row >
149
+ ) ;
155
150
}
156
151
157
152
return (
@@ -167,17 +162,15 @@ function EnableImportBabyPopover({ onClose }: { onClose: () => void }) {
167
162
< StepItem
168
163
step = { 2 }
169
164
title = { 'Tap the "More" menu, then select the "Export Private Key" option.' }
170
- images = { [
171
- './images/artifacts/how-to-import-baby-2.png' ,
172
- './images/artifacts/how-to-import-baby-3.png'
173
- ] }
165
+ images = { [ './images/artifacts/how-to-import-baby-2.png' , './images/artifacts/how-to-import-baby-3.png' ] }
174
166
/>
175
167
< StepItem
176
168
step = { 3 }
177
- title = { 'Once you have your Hex Private Key, you can import it into a COSMOS-compatible wallet to access your Babylon reward assets.' }
169
+ title = {
170
+ 'Once you have your Hex Private Key, you can import it into a COSMOS-compatible wallet to access your Babylon reward assets.'
171
+ }
178
172
images = { [ ] }
179
173
/>
180
-
181
174
</ Column >
182
175
</ Popover >
183
176
) ;
@@ -217,20 +210,29 @@ export default function BabylonStakingScreen() {
217
210
total_finality_providers : 0
218
211
} ) ;
219
212
213
+ const [ loading , setLoading ] = useState ( true ) ;
214
+
215
+ const tools = useTools ( ) ;
220
216
useEffect ( ( ) => {
221
217
const run = async ( ) => {
222
- if ( babylonConfig . phase2 . state === BabylonPhaseState . ACTIVE ) {
223
- wallet . getBabylonAddressSummary ( babylonConfig . chainId ) . then ( ( summary ) => {
218
+ try {
219
+ if ( babylonConfig . phase2 . state === BabylonPhaseState . ACTIVE ) {
220
+ const address = await wallet . getBabylonAddress ( babylonConfig . chainId ) ;
221
+ setBabylonAddressSummary ( Object . assign ( { } , babylonAddressSummary , { address } ) ) ;
222
+
223
+ const summary = await wallet . getBabylonAddressSummary ( babylonConfig . chainId ) ;
224
224
setBabylonAddressSummary ( summary ) ;
225
- } ) ;
226
225
227
- wallet . getBabylonStakingStatusV2 ( ) . then ( ( status ) => {
226
+ const status = await wallet . getBabylonStakingStatusV2 ( ) ;
228
227
setBabylonStakingStatus ( status ) ;
229
- } ) ;
230
- } else {
231
- wallet . getBabylonAddressSummary ( babylonConfig . chainId , false ) . then ( ( summary ) => {
232
- setBabylonAddressSummary ( summary ) ;
233
- } ) ;
228
+ } else {
229
+ const address = await wallet . getBabylonAddress ( babylonConfig . chainId ) ;
230
+ setBabylonAddressSummary ( Object . assign ( { } , babylonAddressSummary , { address } ) ) ;
231
+ }
232
+ } catch ( e ) {
233
+ tools . toastError ( ( e as any ) . message ) ;
234
+ } finally {
235
+ setLoading ( false ) ;
234
236
}
235
237
} ;
236
238
run ( ) ;
@@ -241,7 +243,7 @@ export default function BabylonStakingScreen() {
241
243
networkPrefix = 'Testnet' ;
242
244
}
243
245
244
- if ( ! babylonAddressSummary . address ) {
246
+ if ( loading ) {
245
247
return (
246
248
< Layout >
247
249
< Header
@@ -309,10 +311,18 @@ export default function BabylonStakingScreen() {
309
311
} } >
310
312
< svg
311
313
style = { { position : 'absolute' , right : 8 , top : 8 } }
312
- xmlns = "http://www.w3.org/2000/svg" width = "50" height = "47" viewBox = "0 0 50 47" fill = "none" >
313
- < path opacity = "0.12" fillRule = "evenodd" clipRule = "evenodd"
314
- d = "M0.11176 8.92619C-0.132219 8.28576 0.0306182 7.56665 0.528399 7.08357L7.30606 0.512419C7.80384 0.0298399 8.54611 -0.128013 9.2062 0.108015L23.6573 5.25499C24.0125 5.38127 24.2482 5.709 24.2482 6.07582V9.14317C24.2482 9.37519 24.1531 9.59769 23.9841 9.76155L20.4665 13.1717C20.2179 13.4127 19.8467 13.4919 19.5164 13.3736L15.6344 11.9855L11.3689 10.4596C11.0081 10.3303 10.6566 10.6711 10.79 11.0214L13.7953 18.9205C13.9173 19.2407 13.8361 19.6005 13.587 19.8416L10.4597 22.8723C10.1077 23.2141 10.1077 23.7678 10.4597 24.1091L13.6035 27.1569C13.8527 27.3979 13.9338 27.7577 13.8118 28.078L10.8065 35.9761C10.6732 36.3264 11.0247 36.6672 11.3855 36.5379L19.533 33.6239C19.8633 33.5056 20.2344 33.5848 20.483 33.8258L23.9841 37.2199C24.1531 37.3838 24.2482 37.6063 24.2482 37.8383V40.9066C24.2482 41.2729 24.013 41.6007 23.6584 41.727L9.22379 46.8895C8.56319 47.1256 7.82089 46.9682 7.32311 46.4851L0.54491 39.9139C0.0471294 39.4314 -0.115669 38.7117 0.12831 38.0713L5.43536 24.1246C5.58371 23.7338 5.58371 23.3043 5.43536 22.9139L0.11176 8.92619ZM49.8882 38.0738C50.1322 38.7142 49.9694 39.4334 49.4716 39.9164L42.694 46.4876C42.1962 46.9702 41.4544 47.128 40.7938 46.892L26.3427 41.745C25.9876 41.6188 25.7518 41.291 25.7518 40.9242V37.8568C25.7518 37.6248 25.8469 37.4023 26.016 37.2384L29.5335 33.8283C29.7822 33.5868 30.1533 33.5081 30.4836 33.6264L34.3656 35.0145L38.6311 36.5404C38.9919 36.6697 39.3434 36.3289 39.21 35.9786L36.2047 28.0795C36.0827 27.7593 36.1639 27.3994 36.413 27.1584L39.5403 24.1276C39.8923 23.7859 39.8923 23.2321 39.5403 22.8909L36.3965 19.8431C36.1474 19.6015 36.0662 19.2422 36.1882 18.922L39.1935 11.0239C39.3268 10.6736 38.9753 10.3328 38.6145 10.4621L30.4671 13.3761C30.1368 13.4944 29.7656 13.4152 29.517 13.1742L26.016 9.78009C25.8469 9.61623 25.7518 9.39373 25.7518 9.16171V6.09336C25.7518 5.72704 25.987 5.39981 26.3416 5.27303L40.7762 0.108516C41.4368 -0.127511 42.1786 0.02984 42.6769 0.512921L49.4546 7.08407C49.9529 7.56665 50.1157 8.28626 49.8717 8.92669L44.5647 22.8728C44.4158 23.2637 44.4158 23.6932 44.5647 24.0835L49.8882 38.0738Z"
315
- fill = "#CE6533" />
314
+ xmlns = "http://www.w3.org/2000/svg"
315
+ width = "50"
316
+ height = "47"
317
+ viewBox = "0 0 50 47"
318
+ fill = "none" >
319
+ < path
320
+ opacity = "0.12"
321
+ fillRule = "evenodd"
322
+ clipRule = "evenodd"
323
+ d = "M0.11176 8.92619C-0.132219 8.28576 0.0306182 7.56665 0.528399 7.08357L7.30606 0.512419C7.80384 0.0298399 8.54611 -0.128013 9.2062 0.108015L23.6573 5.25499C24.0125 5.38127 24.2482 5.709 24.2482 6.07582V9.14317C24.2482 9.37519 24.1531 9.59769 23.9841 9.76155L20.4665 13.1717C20.2179 13.4127 19.8467 13.4919 19.5164 13.3736L15.6344 11.9855L11.3689 10.4596C11.0081 10.3303 10.6566 10.6711 10.79 11.0214L13.7953 18.9205C13.9173 19.2407 13.8361 19.6005 13.587 19.8416L10.4597 22.8723C10.1077 23.2141 10.1077 23.7678 10.4597 24.1091L13.6035 27.1569C13.8527 27.3979 13.9338 27.7577 13.8118 28.078L10.8065 35.9761C10.6732 36.3264 11.0247 36.6672 11.3855 36.5379L19.533 33.6239C19.8633 33.5056 20.2344 33.5848 20.483 33.8258L23.9841 37.2199C24.1531 37.3838 24.2482 37.6063 24.2482 37.8383V40.9066C24.2482 41.2729 24.013 41.6007 23.6584 41.727L9.22379 46.8895C8.56319 47.1256 7.82089 46.9682 7.32311 46.4851L0.54491 39.9139C0.0471294 39.4314 -0.115669 38.7117 0.12831 38.0713L5.43536 24.1246C5.58371 23.7338 5.58371 23.3043 5.43536 22.9139L0.11176 8.92619ZM49.8882 38.0738C50.1322 38.7142 49.9694 39.4334 49.4716 39.9164L42.694 46.4876C42.1962 46.9702 41.4544 47.128 40.7938 46.892L26.3427 41.745C25.9876 41.6188 25.7518 41.291 25.7518 40.9242V37.8568C25.7518 37.6248 25.8469 37.4023 26.016 37.2384L29.5335 33.8283C29.7822 33.5868 30.1533 33.5081 30.4836 33.6264L34.3656 35.0145L38.6311 36.5404C38.9919 36.6697 39.3434 36.3289 39.21 35.9786L36.2047 28.0795C36.0827 27.7593 36.1639 27.3994 36.413 27.1584L39.5403 24.1276C39.8923 23.7859 39.8923 23.2321 39.5403 22.8909L36.3965 19.8431C36.1474 19.6015 36.0662 19.2422 36.1882 18.922L39.1935 11.0239C39.3268 10.6736 38.9753 10.3328 38.6145 10.4621L30.4671 13.3761C30.1368 13.4944 29.7656 13.4152 29.517 13.1742L26.016 9.78009C25.8469 9.61623 25.7518 9.39373 25.7518 9.16171V6.09336C25.7518 5.72704 25.987 5.39981 26.3416 5.27303L40.7762 0.108516C41.4368 -0.127511 42.1786 0.02984 42.6769 0.512921L49.4546 7.08407C49.9529 7.56665 50.1157 8.28626 49.8717 8.92669L44.5647 22.8728C44.4158 23.2637 44.4158 23.6932 44.5647 24.0835L49.8882 38.0738Z"
324
+ fill = "#CE6533"
325
+ />
316
326
</ svg >
317
327
< Text text = { 'Babylon Bitcoin Staking Stats' } preset = "bold" />
318
328
@@ -418,8 +428,6 @@ export default function BabylonStakingScreen() {
418
428
/>
419
429
}
420
430
/>
421
-
422
-
423
431
</ Content >
424
432
{ importBabyPopoverVisible ? (
425
433
< EnableImportBabyPopover
0 commit comments