@@ -19,7 +19,7 @@ import { FaRegCopy } from "react-icons/fa";
19
19
import { CopyToClipboard } from "react-copy-to-clipboard" ;
20
20
import OnrampComponent from "../Onramp/Onramp" ;
21
21
import { saveToLocalStorage } from "../../utils/saveToLocalstorage" ;
22
- import { ReactSearchAutocomplete } from ' react-search-autocomplete'
22
+ import { ReactSearchAutocomplete } from " react-search-autocomplete" ;
23
23
// import { AutoComplete } from "react-autocomplete";
24
24
25
25
const PromptComponent = ( ) => {
@@ -71,26 +71,27 @@ const PromptComponent = () => {
71
71
72
72
const [ fetch , { data : data , loading, pagination } ] =
73
73
useLazyQueryWithPagination ( ERC20TokensQueryPolygon ) ;
74
-
75
- const gateway = ( hash ) => `https://beige-yeasty-scorpion-513.mypinata.cloud/ipfs/${ hash } ` ;
74
+
75
+ const gateway = ( hash ) =>
76
+ `https://beige-yeasty-scorpion-513.mypinata.cloud/ipfs/${ hash } ` ;
76
77
const fetchIntents = async ( ) => {
77
78
let hashes = localStorage . getItem ( walletAddress ) ;
78
- if ( hashes ) {
79
+ if ( hashes ) {
79
80
hashes = JSON . parse ( hashes ) ;
80
- console . log ( hashes , hashes [ 0 ] )
81
- for ( let i = 0 ; i < hashes . length ; i ++ ) {
82
- const res = await Axios . get ( gateway ( hashes [ i ] ) )
83
- console . log ( res ) ;
84
- let pIntents = previosIntents ;
85
- pIntents . push ( {
86
- id : i ,
87
- name : res . data . intent
88
- } )
89
- setPreviousIntents ( pIntents )
90
- console . log ( "all intens " , previosIntents )
81
+ console . log ( hashes , hashes [ 0 ] ) ;
82
+ for ( let i = 0 ; i < hashes . length ; i ++ ) {
83
+ const res = await Axios . get ( gateway ( hashes [ i ] ) ) ;
84
+ console . log ( res ) ;
85
+ let pIntents = previosIntents ;
86
+ pIntents . push ( {
87
+ id : i ,
88
+ name : res . data . intent ,
89
+ } ) ;
90
+ setPreviousIntents ( pIntents ) ;
91
+ console . log ( "all intens " , previosIntents ) ;
91
92
}
92
93
}
93
- }
94
+ } ;
94
95
95
96
useEffect ( ( ) => {
96
97
// for now hardcoded the tokens
@@ -104,7 +105,7 @@ const PromptComponent = () => {
104
105
} ) ;
105
106
}
106
107
107
- fetchIntents ( )
108
+ fetchIntents ( ) ;
108
109
// initStripe()
109
110
} , [ fetch , walletAddress ] ) ;
110
111
@@ -211,42 +212,39 @@ const PromptComponent = () => {
211
212
setIsLoading ( false ) ;
212
213
} ;
213
214
214
- const getPinataMetaData = ( intent ) => (
215
+ const getPinataMetaData = ( intent ) =>
215
216
JSON . stringify ( {
216
- " pinataOptions" : {
217
- " cidVersion" : 1
217
+ pinataOptions : {
218
+ cidVersion : 1 ,
218
219
} ,
219
- " pinataMetadata" : {
220
- " name" : "testing" ,
221
- " keyvalues" : {
222
- " intent" : intent ,
223
- }
220
+ pinataMetadata : {
221
+ name : "testing" ,
222
+ keyvalues : {
223
+ intent : intent ,
224
+ } ,
224
225
} ,
225
- "pinataContent" : {
226
- "intent" : intent
227
- }
228
- } )
229
- ) ;
230
-
231
- const getPinataConfig = ( intent ) => (
232
- {
233
- method : 'post' ,
234
- url : 'https://api.pinata.cloud/pinning/pinJSONToIPFS' ,
235
- headers : {
236
- 'Content-Type' : 'application/json' ,
237
- 'Authorization' : `Bearer ${ process . env . REACT_APP_PINATA_JWT } `
226
+ pinataContent : {
227
+ intent : intent ,
238
228
} ,
239
- data : getPinataMetaData ( intent )
240
- }
241
- )
229
+ } ) ;
230
+
231
+ const getPinataConfig = ( intent ) => ( {
232
+ method : "post" ,
233
+ url : "https://api.pinata.cloud/pinning/pinJSONToIPFS" ,
234
+ headers : {
235
+ "Content-Type" : "application/json" ,
236
+ Authorization : `Bearer ${ process . env . REACT_APP_PINATA_JWT } ` ,
237
+ } ,
238
+ data : getPinataMetaData ( intent ) ,
239
+ } ) ;
242
240
243
241
const generateTransactions = async ( ) => {
244
242
setIsLoading ( true ) ;
245
243
const pinataAxiosConfig = getPinataConfig ( intent ) ;
246
- console . log ( ' this is pijnata axios config ' , pinataAxiosConfig )
244
+ console . log ( " this is pijnata axios config " , pinataAxiosConfig ) ;
247
245
// saving intents on ipfs for faster autocomplete
248
- const savingRes = await Axios ( pinataAxiosConfig )
249
- console . log ( ' resp' , savingRes ) ;
246
+ const savingRes = await Axios ( pinataAxiosConfig ) ;
247
+ console . log ( " resp" , savingRes ) ;
250
248
// resp.data.IpfsHash
251
249
saveToLocalStorage ( walletAddress , savingRes . data . IpfsHash ) ;
252
250
@@ -260,7 +258,12 @@ const PromptComponent = () => {
260
258
const transactions = JSON . parse ( res . data . transactions ) ;
261
259
setTransactions ( transactions . transaction ) ;
262
260
setTxnContext ( transactions . context ) ;
263
- setTxnType ( transactions . type ) ;
261
+
262
+ if ( transactions . type ) {
263
+ setTxnType ( transactions . type ) ;
264
+ } else {
265
+ setTxnType ( "none" ) ;
266
+ }
264
267
setConfirmModal ( true ) ;
265
268
} ;
266
269
// goerli = 5,
@@ -287,50 +290,52 @@ const PromptComponent = () => {
287
290
const itemss = [
288
291
{
289
292
id : 0 ,
290
- name : ' Cobol'
293
+ name : " Cobol" ,
291
294
} ,
292
295
{
293
296
id : 1 ,
294
- name : ' JavaScript'
297
+ name : " JavaScript" ,
295
298
} ,
296
299
{
297
300
id : 2 ,
298
- name : ' Basic'
301
+ name : " Basic" ,
299
302
} ,
300
303
{
301
304
id : 3 ,
302
- name : ' PHP'
305
+ name : " PHP" ,
303
306
} ,
304
307
{
305
308
id : 4 ,
306
- name : ' Java'
307
- }
308
- ]
309
+ name : " Java" ,
310
+ } ,
311
+ ] ;
309
312
310
313
const handleOnSearch = ( string , results ) => {
311
314
// onSearch will have as the first callback parameter
312
315
// the string searched and for the second the results.
313
- console . log ( string , results )
316
+ console . log ( string , results ) ;
314
317
setIntent ( string ) ;
315
- }
318
+ } ;
316
319
317
320
const handleOnSelect = ( item ) => {
318
321
// the item selected
319
- console . log ( item )
320
- }
322
+ console . log ( item ) ;
323
+ } ;
321
324
322
325
const handleOnFocus = ( ) => {
323
- console . log ( ' Focused' )
324
- }
326
+ console . log ( " Focused" ) ;
327
+ } ;
325
328
326
329
const formatResult = ( item ) => {
327
330
return (
328
331
< >
329
332
{ /* <span style={{ display: 'block', textAlign: 'left' }}>id: {item.id}</span> */ }
330
- < span style = { { display : 'block' , textAlign : 'left' } } > name: { item . name } </ span >
333
+ < span style = { { display : "block" , textAlign : "left" } } >
334
+ name: { item . name }
335
+ </ span >
331
336
</ >
332
- )
333
- }
337
+ ) ;
338
+ } ;
334
339
335
340
return (
336
341
< div >
@@ -375,7 +380,7 @@ const PromptComponent = () => {
375
380
</ div >
376
381
< div className = "prompt" >
377
382
< div className = "content" >
378
- { /* <ReactSearchAutocomplete
383
+ { /* <ReactSearchAutocomplete
379
384
items={previosIntents}
380
385
onSearch={handleOnSearch}
381
386
// onHover={handleOnHover}
0 commit comments