@@ -13,6 +13,7 @@ import { nftaddress, nftmarketaddress } from "../config"
13
13
import NFT from "../artifacts/contracts/NFT.sol/NFT.json"
14
14
import Market from "../artifacts/contracts/Market.sol/NFTMarket.json"
15
15
import { InputFieldError } from "../components/InputFieldError"
16
+ import { useAccount } from "../hooks/useAccount"
16
17
17
18
18
19
let nft // TODO: use useState?
@@ -37,21 +38,16 @@ const schema = yup.object({
37
38
38
39
export default function EditItem ( ) {
39
40
const router = useRouter ( )
40
- // TODO: create useAccount Hook and listen account change
41
- const [ ethAccount , setEthAccount ] = useState < string > ( )
41
+ const account = useAccount ( )
42
42
const [ preview , setPreview ] = useState < string > ( )
43
43
const [ cid , setCid ] = useState < string > ( )
44
44
const [ loadingState , setLoadingState ] = useState ( "not-loaded" )
45
45
46
46
useEffect ( ( ) => {
47
- if ( typeof window !== "undefined" ) {
48
- const account = localStorage . getItem ( "ethAccount" )
49
- if ( ! account ) {
50
- alert ( "No ETH Account, Please login" )
51
- router . push ( "/articles-all" )
52
- return
53
- }
54
- setEthAccount ( account )
47
+ if ( ! account ) {
48
+ alert ( "No ETH Account, Please login" )
49
+ router . push ( "/articles-all" )
50
+ return
55
51
}
56
52
} , [ ] )
57
53
@@ -105,7 +101,7 @@ export default function EditItem() {
105
101
const authors = [ {
106
102
name : data . author ,
107
103
wallet : {
108
- eth : ethAccount ,
104
+ eth : account ,
109
105
} ,
110
106
} ]
111
107
const nftData = JSON . stringify ( {
@@ -135,7 +131,7 @@ export default function EditItem() {
135
131
// headers: {"Authorization" : `Bearer ${tokenStr}` },
136
132
previous_path : cid ,
137
133
path : addedNFT . path ,
138
- eth : ethAccount ,
134
+ eth : account ,
139
135
name : data . name ,
140
136
image : imageURL ,
141
137
tags : data . s_tags ,
@@ -187,16 +183,16 @@ export default function EditItem() {
187
183
</ div >
188
184
< div >
189
185
190
- < p > -- Markdown Tips:
191
- < a href = "https://anwen.cc/share/6" > 参考1</ a >
192
- < a href = "https://www.markdown.xyz/basic-syntax/" > 参考2</ a >
193
- </ p >
194
- < textarea
195
- placeholder = "Content of your article (you can use Markdown format)"
196
- className = "mt-2 border rounded p-4 h-80 w-full"
197
- defaultValue = { nft . description }
198
- { ...register ( "description" ) }
199
- />
186
+ < p > -- Markdown Tips:
187
+ < a href = "https://anwen.cc/share/6" > 参考1</ a >
188
+ < a href = "https://www.markdown.xyz/basic-syntax/" > 参考2</ a >
189
+ </ p >
190
+ < textarea
191
+ placeholder = "Content of your article (you can use Markdown format)"
192
+ className = "mt-2 border rounded p-4 h-80 w-full"
193
+ defaultValue = { nft . description }
194
+ { ...register ( "description" ) }
195
+ />
200
196
< InputFieldError message = { errors . description ?. message } />
201
197
</ div >
202
198
< div >
0 commit comments