1
- import { getStrategyList } from '@/api/strategy'
2
- import { useAsync } from '@/hooks/useAsync'
3
- import { useBacktestInfo } from '@/hooks/useBacktestInfo'
4
- import { getArray } from '@/utils'
5
1
import {
6
2
Button ,
7
- Col ,
8
3
Descriptions ,
9
4
Divider ,
5
+ message ,
6
+ Modal ,
10
7
Result ,
11
- Row ,
12
- Space ,
13
8
Spin ,
14
9
Typography ,
15
10
} from 'antd'
16
11
import React , { useMemo , useState } from 'react'
17
- import { useParams } from 'react-router'
18
- import { Contain , Iframe } from './index.style'
12
+ import { useNavigate , useParams } from 'react-router'
13
+
14
+ import { getStrategy , getStrategyList } from '@/api/strategy'
15
+ import { Code } from '@/components/code'
16
+ import { useAsync } from '@/hooks/useAsync'
17
+ import { useBacktestInfo } from '@/hooks/useBacktestInfo'
18
+ import { useIsLogined } from '@/hooks/useIsLogined'
19
+ import { getArray } from '@/utils'
20
+
21
+ import { CodeWrap , Contain , CopyBtn , Iframe } from './index.style'
22
+ import { createProductPayment } from '@/api/vip'
19
23
20
24
export interface StrategyInfoProps { }
21
25
@@ -26,6 +30,8 @@ const highStyle = {
26
30
export const StrategyInfo : React . FC < StrategyInfoProps > = ( { } ) => {
27
31
const { data : list , loading } = useAsync ( ( ) => getStrategyList ( ) , [ ] )
28
32
33
+ const navigate = useNavigate ( )
34
+
29
35
const params = useParams ( )
30
36
const [ frameLoading , setFrameLoading ] = useState ( true )
31
37
@@ -40,6 +46,50 @@ export const StrategyInfo: React.FC<StrategyInfoProps> = ({}) => {
40
46
currentItem ?. backtest_uri ,
41
47
)
42
48
49
+ const isLogined = useIsLogined ( )
50
+
51
+ const {
52
+ run : buy ,
53
+ loading : buyLoading ,
54
+ data : strategy ,
55
+ } = useAsync (
56
+ async ( ) => {
57
+ if ( ! isLogined ) {
58
+ navigate ( '/login' )
59
+ message . info ( 'Please login first' )
60
+ return
61
+ }
62
+ if ( currentItem ) {
63
+ const strategy = await getStrategy ( currentItem ?. id )
64
+ if ( strategy ?. code ) {
65
+ message . success ( 'Get success' )
66
+ return strategy
67
+ } else {
68
+ Modal . confirm ( {
69
+ title : 'Requirements' ,
70
+ content : `The current strategy needs to be purchased before it can be viewed` ,
71
+ async onOk ( ) {
72
+ const payment = await createProductPayment ( strategy ?. planId )
73
+ if ( payment ) {
74
+ const item = getArray ( payment ?. paymentLinks ) . find (
75
+ ( item ) => item . rel === 'approve' ,
76
+ )
77
+ location . href = item . href
78
+ } else {
79
+ message . error ( 'Product not found' )
80
+ }
81
+ } ,
82
+ okText : 'Go to buy' ,
83
+ } )
84
+ }
85
+ }
86
+ } ,
87
+ [ currentItem , isLogined ] ,
88
+ {
89
+ manual : true ,
90
+ } ,
91
+ )
92
+
43
93
if ( ! currentItem && ! loading ) {
44
94
return (
45
95
< Contain >
@@ -61,40 +111,44 @@ export const StrategyInfo: React.FC<StrategyInfoProps> = ({}) => {
61
111
} }
62
112
> </ Iframe >
63
113
</ Spin >
64
- < Row >
65
- < Col span = { 12 } >
66
- < Spin spinning = { backtestInfoLoading } >
67
- < Descriptions size = "small" bordered column = { 1 } >
68
- { getArray ( backtestInfo ) . map ( ( item ) => {
69
- let style = { }
70
- if (
71
- item . key . includes ( 'CAGR' ) ||
72
- item . key . includes ( 'Profit factor' ) ||
73
- item . key . includes ( 'Absolute Drawdown (Account)' )
74
- ) {
75
- style = highStyle
76
- }
77
- return (
78
- < Descriptions . Item
79
- labelStyle = { style }
80
- contentStyle = { style }
81
- label = { item . key }
82
- key = { item . key }
83
- >
84
- { item . value }
85
- </ Descriptions . Item >
86
- )
87
- } ) }
88
- </ Descriptions >
89
- </ Spin >
90
- </ Col >
91
- < Col span = { 12 } > </ Col >
92
- </ Row >
114
+ < Spin spinning = { backtestInfoLoading } >
115
+ < Descriptions size = "small" bordered column = { 2 } >
116
+ { getArray ( backtestInfo ) . map ( ( item ) => {
117
+ let style = { }
118
+ if (
119
+ item . key . includes ( 'CAGR' ) ||
120
+ item . key . includes ( 'Profit factor' ) ||
121
+ item . key . includes ( 'Absolute Drawdown (Account)' )
122
+ ) {
123
+ style = highStyle
124
+ }
125
+ return (
126
+ < Descriptions . Item
127
+ labelStyle = { style }
128
+ contentStyle = { style }
129
+ label = { item . key }
130
+ key = { item . key }
131
+ >
132
+ { item . value }
133
+ </ Descriptions . Item >
134
+ )
135
+ } ) }
136
+ </ Descriptions >
137
+ </ Spin >
93
138
{ /* code */ }
94
139
< Divider />
95
- < Space >
96
- < Button type = "primary" > Download StrategyCode</ Button >
97
- </ Space >
140
+ { strategy ?. code ? (
141
+ < CodeWrap >
142
+ < CopyBtn >
143
+ < Typography . Text copyable = { { text : strategy ?. code } } />
144
+ </ CopyBtn >
145
+ < Code > { strategy ?. code } </ Code >
146
+ </ CodeWrap >
147
+ ) : (
148
+ < Button loading = { buyLoading } type = "primary" onClick = { buy } >
149
+ Download StrategyCode
150
+ </ Button >
151
+ ) }
98
152
</ Contain >
99
153
)
100
154
}
0 commit comments