@@ -5,14 +5,18 @@ import * as React from 'react';
55import { useTranslation } from 'react-i18next' ;
66import Copy from '@components/Copy' ;
77import Expand from '@components/Expand/Expand' ;
8+ import { useWeb3 } from '@containers' ;
89import { useCreateDeployment } from '@hooks' ;
9- import { Markdown , Modal , openNotification , TableTitle , Typography } from '@subql/components' ;
10- import { parseError } from '@utils' ;
10+ import { useWaitTransactionhandled } from '@hooks/useWaitTransactionHandled' ;
11+ import { Markdown , Modal , openNotification , Spinner , TableTitle , Typography } from '@subql/components' ;
12+ import { cidToBytes32 , parseError } from '@utils' ;
1113import { useUpdate } from 'ahooks' ;
12- import { Form , Radio , Table } from 'antd' ;
14+ import { Checkbox , Form , Radio , Table } from 'antd' ;
1315import { useForm } from 'antd/es/form/Form' ;
1416import dayjs from 'dayjs' ;
1517
18+ import { useWeb3Store } from 'src/stores' ;
19+
1620import { NewDeployment } from '../../models' ;
1721import styles from './ProjectDeployments.module.less' ;
1822
@@ -27,7 +31,10 @@ type Props = {
2731
2832const ProjectDeployments : React . FC < Props > = ( { deployments, projectId, currentDeploymentCid, onRefresh } ) => {
2933 const { t } = useTranslation ( ) ;
34+ const { contracts } = useWeb3Store ( ) ;
3035 const updateDeployment = useCreateDeployment ( projectId ) ;
36+ const [ loading , setLoading ] = React . useState < boolean > ( false ) ;
37+ const waitTransactionHandled = useWaitTransactionhandled ( ) ;
3138 const [ deploymentModal , setDeploymentModal ] = React . useState < boolean > ( false ) ;
3239 const [ form ] = useForm ( ) ;
3340 const [ currentDeployment , setCurrentDeployment ] = React . useState < Deployment > ( ) ;
@@ -80,7 +87,6 @@ const ProjectDeployments: React.FC<Props> = ({ deployments, projectId, currentDe
8087 rules = { [ { required : true } ] }
8188 required
8289 help = { ruleTips }
83- validateStatus = "error"
8490 >
8591 < div className = { styles . markdownWrapper } >
8692 < Markdown
@@ -116,11 +122,36 @@ const ProjectDeployments: React.FC<Props> = ({ deployments, projectId, currentDe
116122 dataIndex : 'deploymentId' ,
117123 key : 'deploymentId' ,
118124 title : < TableTitle > RECOMMENDED</ TableTitle > ,
119- render : ( val ) => (
120- < p className = { styles . value } >
121- { currentDeploymentCid === val ? < Radio checked = { currentDeploymentCid === val } > RECOMMENDED</ Radio > : '' }
122- </ p >
123- ) ,
125+ render : ( val ) =>
126+ loading ? (
127+ < Spinner size = { 10 } > </ Spinner >
128+ ) : (
129+ < p className = { styles . value } >
130+ < Radio
131+ checked = { currentDeploymentCid === val }
132+ onClick = { async ( ) => {
133+ if ( currentDeploymentCid !== val ) {
134+ try {
135+ const res = await contracts ?. projectRegistry . setProjectLatestDeployment (
136+ projectId ,
137+ cidToBytes32 ( val ) ,
138+ ) ;
139+ setLoading ( true ) ;
140+
141+ const receipt = await res ?. wait ( 10 ) ;
142+ await waitTransactionHandled ( receipt ?. blockNumber ) ;
143+
144+ await onRefresh ( ) ;
145+ } finally {
146+ setLoading ( false ) ;
147+ }
148+ }
149+ } }
150+ >
151+ RECOMMENDED
152+ </ Radio >
153+ </ p >
154+ ) ,
124155 } ,
125156 {
126157 dataIndex : 'deploymentId' ,
@@ -162,6 +193,7 @@ const ProjectDeployments: React.FC<Props> = ({ deployments, projectId, currentDe
162193 setCurrentDeployment ( record ) ;
163194 setDeploymentModal ( true ) ;
164195 form . setFieldValue ( 'description' , record . description ) ;
196+ form . setFieldValue ( 'recommended' , currentDeploymentCid === record . deploymentId ) ;
165197 } }
166198 >
167199 Edit
0 commit comments