1
1
'use client' ;
2
2
//React imports
3
- import React , { useEffect , useState } from 'react' ;
3
+ import React , { useContext , useEffect , useState } from 'react' ;
4
4
5
5
//Axios imports
6
6
import axios from 'axios' ;
@@ -22,6 +22,7 @@ import WSTTextField from '../components/WSTTextField';
22
22
import CopyTextField from '../components/CopyTextField' ;
23
23
import WSTTable from '../components/WSTTable' ;
24
24
import { getWalletBalance , signAndSentTx , getBlacklist } from '../utils/walletUtils' ;
25
+ import DemoEnvironmentContext from '../context/demoEnvironmentContext' ;
25
26
26
27
27
28
@@ -38,19 +39,21 @@ export default function Home() {
38
39
const [ freezeReason , setFreezeReason ] = useState ( 'Enter reason here' ) ;
39
40
const [ seizeAccountNumber , setSeizeAccountNumber ] = useState ( 'address to seize' ) ;
40
41
const [ seizeReason , setSeizeReason ] = useState ( 'Enter reason here' ) ;
42
+
43
+ const demoEnv = useContext ( DemoEnvironmentContext ) ;
41
44
42
45
useEffect ( ( ) => {
43
46
const initialize = async ( ) => {
44
47
await fetchUserDetails ( ) ;
45
48
await fetchBlacklistStatus ( ) ;
46
49
} ;
47
50
initialize ( ) ;
48
- } , [ ] ) ;
51
+ } , [ demoEnv ] ) ;
49
52
50
53
const fetchUserDetails = async ( ) => {
51
- const mintBalance = await getWalletBalance ( mintAccount . address ) ;
52
- const userABalance = await getWalletBalance ( accounts . alice . address ) ;
53
- const userBBalance = await getWalletBalance ( accounts . bob . address ) ;
54
+ const mintBalance = await getWalletBalance ( demoEnv , mintAccount . address ) ;
55
+ const userABalance = await getWalletBalance ( demoEnv , accounts . alice . address ) ;
56
+ const userBBalance = await getWalletBalance ( demoEnv , accounts . bob . address ) ;
54
57
55
58
// Update Zustand store with the initialized wallet information
56
59
await changeMintAccountDetails ( { ...mintAccount , balance : mintBalance } ) ;
@@ -59,7 +62,7 @@ export default function Home() {
59
62
} ;
60
63
61
64
const fetchBlacklistStatus = async ( ) => {
62
- const blacklist = await getBlacklist ( ) ;
65
+ const blacklist = await getBlacklist ( demoEnv ) ;
63
66
const { accounts, changeWalletAccountDetails } = useStore . getState ( ) ;
64
67
65
68
Object . entries ( accounts ) . map ( async ( [ key , account ] ) => {
@@ -86,7 +89,7 @@ export default function Home() {
86
89
return ;
87
90
}
88
91
changeAlertInfo ( { severity : 'info' , message : 'Processing Mint Request' , open : true , link : '' } ) ;
89
- lucid . selectWallet . fromSeed ( mintAccount . mnemonic ) ;
92
+ lucid . selectWallet . fromSeed ( demoEnv . mint_authority ) ;
90
93
const requestData = {
91
94
asset_name : Buffer . from ( 'WST' , 'utf8' ) . toString ( 'hex' ) , // Convert "WST" to hex
92
95
issuer : mintAccount . address ,
@@ -108,7 +111,7 @@ export default function Home() {
108
111
const tx = await lucid . fromTx ( response . data . cborHex ) ;
109
112
const txId = await signAndSentTx ( lucid , tx ) ;
110
113
111
- changeAlertInfo ( { severity : 'success' , message : 'Successful new WST mint. View the transaction here:' , open : true , link : `https://preview.cexplorer.io/tx /${ txId } ` } ) ;
114
+ changeAlertInfo ( { severity : 'success' , message : 'Successful new WST mint. View the transaction here:' , open : true , link : `${ demoEnv . explorer_url } /${ txId } ` } ) ;
112
115
113
116
await fetchUserDetails ( ) ;
114
117
} catch ( error ) {
@@ -117,7 +120,7 @@ export default function Home() {
117
120
} ;
118
121
119
122
const onSend = async ( ) => {
120
- lucid . selectWallet . fromSeed ( mintAccount . mnemonic ) ;
123
+ lucid . selectWallet . fromSeed ( demoEnv . mint_authority ) ;
121
124
console . log ( 'send tokens' ) ;
122
125
changeAlertInfo ( { severity : 'info' , message : 'Transaction processing' , open : true , link : '' } ) ;
123
126
const requestData = {
@@ -140,7 +143,7 @@ export default function Home() {
140
143
console . log ( 'Send response:' , response . data ) ;
141
144
const tx = await lucid . fromTx ( response . data . cborHex ) ;
142
145
const txId = await signAndSentTx ( lucid , tx ) ;
143
- const newAccountBalance = await getWalletBalance ( sendRecipientAddress ) ;
146
+ const newAccountBalance = await getWalletBalance ( demoEnv , sendRecipientAddress ) ;
144
147
const recipientWalletKey = ( Object . keys ( accounts ) as ( keyof Accounts ) [ ] ) . find (
145
148
( key ) => accounts [ key ] . address === sendRecipientAddress
146
149
) ;
@@ -150,7 +153,7 @@ export default function Home() {
150
153
balance : newAccountBalance ,
151
154
} ) ;
152
155
}
153
- changeAlertInfo ( { severity : 'success' , message : 'Transaction sent successfully!' , open : true , link : `https://preview.cexplorer.io/tx /${ txId } ` } ) ;
156
+ changeAlertInfo ( { severity : 'success' , message : 'Transaction sent successfully!' , open : true , link : `${ demoEnv . explorer_url } /${ txId } ` } ) ;
154
157
await fetchUserDetails ( ) ;
155
158
} catch ( error ) {
156
159
console . error ( 'Send failed:' , error ) ;
@@ -159,7 +162,7 @@ export default function Home() {
159
162
160
163
const onFreeze = async ( ) => {
161
164
console . log ( 'freeze an address' ) ;
162
- lucid . selectWallet . fromSeed ( mintAccount . mnemonic ) ;
165
+ lucid . selectWallet . fromSeed ( demoEnv . mint_authority ) ;
163
166
changeAlertInfo ( { severity : 'info' , message : 'Freeze request processing' , open : true , link : '' } ) ;
164
167
const requestData = {
165
168
issuer : mintAccount . address ,
@@ -180,7 +183,7 @@ export default function Home() {
180
183
const tx = await lucid . fromTx ( response . data . cborHex ) ;
181
184
const txId = await signAndSentTx ( lucid , tx ) ;
182
185
console . log ( txId ) ;
183
- changeAlertInfo ( { severity : 'success' , message : 'Address successfully frozen' , open : true , link : `https://preview.cexplorer.io/tx /${ txId } ` } ) ;
186
+ changeAlertInfo ( { severity : 'success' , message : 'Address successfully frozen' , open : true , link : `${ demoEnv . explorer_url } /${ txId } ` } ) ;
184
187
const frozenWalletKey = ( Object . keys ( accounts ) as ( keyof Accounts ) [ ] ) . find (
185
188
( key ) => accounts [ key ] . address === freezeAccountNumber
186
189
) ;
@@ -206,7 +209,7 @@ export default function Home() {
206
209
207
210
const onUnfreeze = async ( ) => {
208
211
console . log ( 'unfreeze an account' ) ;
209
- lucid . selectWallet . fromSeed ( mintAccount . mnemonic ) ;
212
+ lucid . selectWallet . fromSeed ( demoEnv . mint_authority ) ;
210
213
changeAlertInfo ( { severity : 'info' , message : 'Unfreeze request processing' , open : true , link : '' } ) ;
211
214
const requestData = {
212
215
issuer : mintAccount . address ,
@@ -226,7 +229,7 @@ export default function Home() {
226
229
console . log ( 'Unfreeze response:' , response . data ) ;
227
230
const tx = await lucid . fromTx ( response . data . cborHex ) ;
228
231
const txId = await signAndSentTx ( lucid , tx ) ;
229
- changeAlertInfo ( { severity : 'success' , message : 'Address successfully unfrozen' , open : true , link : `https://preview.cexplorer.io/tx /${ txId } ` } ) ;
232
+ changeAlertInfo ( { severity : 'success' , message : 'Address successfully unfrozen' , open : true , link : `${ demoEnv . explorer_url } /${ txId } ` } ) ;
230
233
const unfrozenWalletKey = ( Object . keys ( accounts ) as ( keyof Accounts ) [ ] ) . find (
231
234
( key ) => accounts [ key ] . address === freezeAccountNumber
232
235
) ;
@@ -252,7 +255,7 @@ export default function Home() {
252
255
253
256
const onSeize = async ( ) => {
254
257
console . log ( 'seize account funds' ) ;
255
- lucid . selectWallet . fromSeed ( mintAccount . mnemonic ) ;
258
+ lucid . selectWallet . fromSeed ( demoEnv . mint_authority ) ;
256
259
changeAlertInfo ( { severity : 'info' , message : 'WST seizure processing' , open : true , link : '' } ) ;
257
260
const requestData = {
258
261
issuer : mintAccount . address ,
@@ -272,7 +275,7 @@ export default function Home() {
272
275
console . log ( 'Seize response:' , response . data ) ;
273
276
const tx = await lucid . fromTx ( response . data . cborHex ) ;
274
277
const txId = await signAndSentTx ( lucid , tx ) ;
275
- const newAccountBalance = await getWalletBalance ( seizeAccountNumber ) ;
278
+ const newAccountBalance = await getWalletBalance ( demoEnv , seizeAccountNumber ) ;
276
279
const seizeWalletKey = ( Object . keys ( accounts ) as ( keyof Accounts ) [ ] ) . find (
277
280
( key ) => accounts [ key ] . address === seizeAccountNumber
278
281
) ;
@@ -282,7 +285,7 @@ export default function Home() {
282
285
balance : newAccountBalance ,
283
286
} ) ;
284
287
}
285
- changeAlertInfo ( { severity : 'success' , message : 'Funds successfully seized' , open : true , link : `https://preview.cexplorer.io/tx /${ txId } ` } ) ;
288
+ changeAlertInfo ( { severity : 'success' , message : 'Funds successfully seized' , open : true , link : `${ demoEnv . explorer_url } /${ txId } ` } ) ;
286
289
await fetchUserDetails ( ) ;
287
290
} catch ( error ) {
288
291
console . error ( 'Seize failed:' , error ) ;
0 commit comments