Skip to content

Commit d4e1aef

Browse files
KJES4j-mueller
andauthored
Kat/final UI updates (#74)
* add link to txId shown in Cardano scanner to alert banner * Add reason field to tx metadata * Nicer type for Reason * Add reason to seize endpoint * add reason to freeze and seize calls --------- Co-authored-by: Jann Müller <[email protected]>
1 parent 9adea8f commit d4e1aef

File tree

12 files changed

+143
-49
lines changed

12 files changed

+143
-49
lines changed

frontend/src/app/[username]/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default function Profile() {
4343
severity: 'error',
4444
message: 'Cannot send WST with frozen account.',
4545
open: true,
46+
link: ''
4647
});
4748
return;
4849
}
@@ -73,10 +74,10 @@ export default function Profile() {
7374
);
7475
console.log('Send response:', response.data);
7576
const tx = await lucid.fromTx(response.data.cborHex);
76-
await signAndSentTx(lucid, tx);
77+
const txId = await signAndSentTx(lucid, tx);
7778
await updateAccountBalance(sendRecipientAddress);
7879
await updateAccountBalance(accountInfo.address);
79-
changeAlertInfo({severity: 'success', message: 'Transaction sent successfully!', open: true,});
80+
changeAlertInfo({severity: 'success', message: 'Transaction sent successfully!', open: true, link: `https://preview.cardanoscan.io/transaction/${txId.inputs[0].transaction_id}`});
8081
} catch (error) {
8182
console.error('Send failed:', error);
8283
}

frontend/src/app/components/AlertBar.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,27 @@ const handleClose = () => {
1616
};
1717

1818
return (
19-
<Snackbar open={alertInfo.open} autoHideDuration={alertInfo.severity === 'success' ? 3000 : null} onClose={handleClose} anchorOrigin={{vertical: 'top', horizontal: 'center'}} >
19+
<Snackbar open={alertInfo.open} anchorOrigin={{vertical: 'top', horizontal: 'center'}} >
2020
<Alert
2121
severity={alertInfo.severity}
2222
variant="filled"
2323
sx={{ width: '100%' }}
2424
onClose={handleClose}
2525
>
2626
{alertInfo.message}
27+
{alertInfo.link && (
28+
<>
29+
{" "}
30+
<a
31+
href={alertInfo.link}
32+
target="_blank"
33+
rel="noopener noreferrer"
34+
>
35+
{alertInfo.link}
36+
</a>
37+
{" "}
38+
</>
39+
)}
2740
</Alert>
2841
</Snackbar>
2942
);

frontend/src/app/mint-authority/page.tsx

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export default function Home() {
8585
console.error("Recipient Address not cleared.");
8686
return;
8787
}
88-
changeAlertInfo({severity: 'info', message: 'Processing Mint Request', open: true,});
88+
changeAlertInfo({severity: 'info', message: 'Processing Mint Request', open: true, link: ''});
8989
lucid.selectWallet.fromSeed(mintAccount.mnemonic);
9090
const requestData = {
9191
asset_name: Buffer.from('WST', 'utf8').toString('hex'), // Convert "WST" to hex
@@ -109,22 +109,26 @@ export default function Home() {
109109
// await signAndSentTx(lucid, tx);
110110
const txBuilder = await makeTxSignBuilder(lucid.wallet(), tx.toTransaction()).complete();
111111
const cmlTx = txBuilder.toTransaction()
112-
console.log("TxBody: " + cmlTx.body().to_json());
112+
// console.log("TxBody: " + cmlTx.body().to_json());
113113
const witnessSet = txBuilder.toTransaction().witness_set();
114114
const expectedScriptDataHash : CML.ScriptDataHash | undefined = CML.calc_script_data_hash(witnessSet.redeemers()!, CML.PlutusDataList.new(), lucid.config().costModels!, witnessSet.languages());
115-
console.log('Calculated Script Data Hash:', expectedScriptDataHash?.to_hex());
115+
// console.log('Calculated Script Data Hash:', expectedScriptDataHash?.to_hex());
116116
const cmlTxBodyClone = CML.TransactionBody.from_cbor_hex(cmlTx!.body().to_cbor_hex());
117-
console.log("TxBody: " + cmlTxBodyClone.to_json());
118-
console.log('Preclone script hash:', cmlTxBodyClone.script_data_hash()?.to_hex());
117+
// console.log("TxBody: " + cmlTxBodyClone.to_json());
118+
const txIDinAlert = await cmlTxBodyClone.to_json();
119+
const txIDObject = JSON.parse(txIDinAlert);
120+
// console.log('Preclone script hash:', cmlTxBodyClone.script_data_hash()?.to_hex());
119121
cmlTxBodyClone.set_script_data_hash(expectedScriptDataHash!);
120-
console.log('Postclone script hash:', cmlTxBodyClone.script_data_hash()?.to_hex());
122+
// console.log('Postclone script hash:', cmlTxBodyClone.script_data_hash()?.to_hex());
121123
const cmlClonedTx = CML.Transaction.new(cmlTxBodyClone, cmlTx!.witness_set(), true, cmlTx!.auxiliary_data());
122124
const cmlClonedSignedTx = await makeTxSignBuilder(lucid.wallet(), cmlClonedTx).sign.withWallet().complete();
123125

124126
const txId = await cmlClonedSignedTx.submit();
125127
await lucid.awaitTx(txId);
126128

127-
changeAlertInfo({severity: 'success', message: 'Successful new WST mint', open: true,});
129+
changeAlertInfo({severity: 'success', message: 'Successful new WST mint. View the transaction here:', open: true, link: `https://preview.cardanoscan.io/transaction/${txIDObject.inputs[0].transaction_id}`});
130+
131+
128132
await fetchUserDetails();
129133
} catch (error) {
130134
console.error('Minting failed:', error);
@@ -134,7 +138,7 @@ export default function Home() {
134138
const onSend = async () => {
135139
lucid.selectWallet.fromSeed(mintAccount.mnemonic);
136140
console.log('send tokens');
137-
changeAlertInfo({severity: 'info', message: 'Transaction processing', open: true,});
141+
changeAlertInfo({severity: 'info', message: 'Transaction processing', open: true, link: ''});
138142
const requestData = {
139143
asset_name: Buffer.from('WST', 'utf8').toString('hex'), // Convert "WST" to hex
140144
issuer: mintAccount.address,
@@ -154,7 +158,7 @@ export default function Home() {
154158
);
155159
console.log('Send response:', response.data);
156160
const tx = await lucid.fromTx(response.data.cborHex);
157-
await signAndSentTx(lucid, tx);
161+
const txId = await signAndSentTx(lucid, tx);
158162
const newAccountBalance = await getWalletBalance(sendRecipientAddress);
159163
const recipientWalletKey = (Object.keys(accounts) as (keyof Accounts)[]).find(
160164
(key) => accounts[key].address === sendRecipientAddress
@@ -165,7 +169,7 @@ export default function Home() {
165169
balance: newAccountBalance,
166170
});
167171
}
168-
changeAlertInfo({severity: 'success', message: 'Transaction sent successfully!', open: true,});
172+
changeAlertInfo({severity: 'success', message: 'Transaction sent successfully!', open: true, link: `https://preview.cardanoscan.io/transaction/${txId.inputs[0].transaction_id}`});
169173
await fetchUserDetails();
170174
} catch (error) {
171175
console.error('Send failed:', error);
@@ -175,10 +179,11 @@ export default function Home() {
175179
const onFreeze = async () => {
176180
console.log('freeze an account');
177181
lucid.selectWallet.fromSeed(mintAccount.mnemonic);
178-
changeAlertInfo({severity: 'info', message: 'Freeze request processing', open: true,});
182+
changeAlertInfo({severity: 'info', message: 'Freeze request processing', open: true, link: ''});
179183
const requestData = {
180184
issuer: mintAccount.address,
181185
blacklist_address: freezeAccountNumber,
186+
reason: freezeReason,
182187
};
183188
try {
184189
const response = await axios.post(
@@ -192,8 +197,8 @@ export default function Home() {
192197
);
193198
console.log('Freeze response:', response.data);
194199
const tx = await lucid.fromTx(response.data.cborHex);
195-
await signAndSentTx(lucid, tx);
196-
changeAlertInfo({severity: 'success', message: 'Account successfully frozen', open: true,});
200+
const txId = await signAndSentTx(lucid, tx);
201+
changeAlertInfo({severity: 'success', message: 'Account successfully frozen', open: true, link: `https://preview.cardanoscan.io/transaction/${txId.inputs[0].transaction_id}`});
197202
const frozenWalletKey = (Object.keys(accounts) as (keyof Accounts)[]).find(
198203
(key) => accounts[key].address === freezeAccountNumber
199204
);
@@ -220,7 +225,7 @@ export default function Home() {
220225
const onUnfreeze = async () => {
221226
console.log('unfreeze an account');
222227
lucid.selectWallet.fromSeed(mintAccount.mnemonic);
223-
changeAlertInfo({severity: 'info', message: 'Unfreeze request processing', open: true,});
228+
changeAlertInfo({severity: 'info', message: 'Unfreeze request processing', open: true, link: ''});
224229
const requestData = {
225230
issuer: mintAccount.address,
226231
blacklist_address: unfreezeAccountNumber,
@@ -237,8 +242,8 @@ export default function Home() {
237242
);
238243
console.log('Unfreeze response:', response.data);
239244
const tx = await lucid.fromTx(response.data.cborHex);
240-
await signAndSentTx(lucid, tx);
241-
changeAlertInfo({severity: 'success', message: 'Account successfully unfrozen', open: true,});
245+
const txId = await signAndSentTx(lucid, tx);
246+
changeAlertInfo({severity: 'success', message: 'Account successfully unfrozen', open: true, link: `https://preview.cardanoscan.io/transaction/${txId.inputs[0].transaction_id}`});
242247
const unfrozenWalletKey = (Object.keys(accounts) as (keyof Accounts)[]).find(
243248
(key) => accounts[key].address === freezeAccountNumber
244249
);
@@ -265,10 +270,11 @@ export default function Home() {
265270
const onSeize = async () => {
266271
console.log('seize account funds');
267272
lucid.selectWallet.fromSeed(mintAccount.mnemonic);
268-
changeAlertInfo({severity: 'info', message: 'WST seizure processing', open: true,});
273+
changeAlertInfo({severity: 'info', message: 'WST seizure processing', open: true, link: ''});
269274
const requestData = {
270275
issuer: mintAccount.address,
271276
target: seizeAccountNumber,
277+
reason: seizeReason,
272278
};
273279
try {
274280
const response = await axios.post(
@@ -282,7 +288,7 @@ export default function Home() {
282288
);
283289
console.log('Seize response:', response.data);
284290
const tx = await lucid.fromTx(response.data.cborHex);
285-
await signAndSentTx(lucid, tx);
291+
const txId = await signAndSentTx(lucid, tx);
286292
const newAccountBalance = await getWalletBalance(seizeAccountNumber);
287293
const seizeWalletKey = (Object.keys(accounts) as (keyof Accounts)[]).find(
288294
(key) => accounts[key].address === seizeAccountNumber
@@ -293,7 +299,7 @@ export default function Home() {
293299
balance: newAccountBalance,
294300
});
295301
}
296-
changeAlertInfo({severity: 'success', message: 'Funds successfully seized', open: true,});
302+
changeAlertInfo({severity: 'success', message: 'Funds successfully seized', open: true, link: `https://preview.cardanoscan.io/transaction/${txId.inputs[0].transaction_id}`});
297303
await fetchUserDetails();
298304
} catch (error) {
299305
console.error('Seize failed:', error);

frontend/src/app/store/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type Accounts = {
1515
export type Severity = 'success' | 'error' | 'info' | 'warning';
1616
export type AlertInfo = {
1717
open: boolean | undefined,
18-
message: string,
1918
severity: Severity,
19+
message: string,
20+
link?: string,
2021
};

frontend/src/app/styles/globals.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ main {
1212

1313
a {
1414
color: inherit;
15-
text-decoration: none;
15+
/* text-decoration: none; */
1616
}
1717

1818
.contentSection {

frontend/src/app/utils/walletUtils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,19 @@ export async function signAndSentTx(lucid: LucidEvolution, tx: TxSignBuilder) {
8787
const cmlTx = txBuilder.toTransaction();
8888
const witnessSet = txBuilder.toTransaction().witness_set();
8989
const expectedScriptDataHash : CML.ScriptDataHash | undefined = CML.calc_script_data_hash(witnessSet.redeemers()!, CML.PlutusDataList.new(), lucid.config().costModels!, witnessSet.languages());
90-
console.log('Calculated Script Data Hash:', expectedScriptDataHash?.to_hex());
90+
// console.log('Calculated Script Data Hash:', expectedScriptDataHash?.to_hex());
9191
const cmlTxBodyClone = CML.TransactionBody.from_cbor_hex(cmlTx!.body().to_cbor_hex());
92-
console.log('Preclone script hash:', cmlTxBodyClone.script_data_hash()?.to_hex());
92+
const txIDinAlert = await cmlTxBodyClone.to_json();
93+
const txIDObject = JSON.parse(txIDinAlert);
94+
// console.log('Preclone script hash:', cmlTxBodyClone.script_data_hash()?.to_hex());
9395
cmlTxBodyClone.set_script_data_hash(expectedScriptDataHash!);
94-
console.log('Postclone script hash:', cmlTxBodyClone.script_data_hash()?.to_hex());
96+
// console.log('Postclone script hash:', cmlTxBodyClone.script_data_hash()?.to_hex());
9597
const cmlClonedTx = CML.Transaction.new(cmlTxBodyClone, cmlTx!.witness_set(), true, cmlTx!.auxiliary_data());
9698
const cmlClonedSignedTx = await makeTxSignBuilder(lucid.wallet(), cmlClonedTx).sign.withWallet().complete();
9799
const txId = await cmlClonedSignedTx.submit();
98100
await lucid.awaitTx(txId);
101+
console.log(cmlClonedSignedTx);
102+
return txIDObject
99103
}
100104

101105
export type WalletType = "Lace" | "Eternl" | "Nami" | "Yoroi";

generated/openapi/schema.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,22 @@
3131
},
3232
"issuer": {
3333
"$ref": "#/components/schemas/Address"
34+
},
35+
"reason": {
36+
"$ref": "#/components/schemas/BlacklistReason"
3437
}
3538
},
3639
"required": [
3740
"issuer",
38-
"blacklist_address"
41+
"blacklist_address",
42+
"reason"
3943
],
4044
"type": "object"
4145
},
46+
"BlacklistReason": {
47+
"description": "Reason for adding an address to the blacklist",
48+
"type": "string"
49+
},
4250
"Hash PaymentKey": {
4351
"description": "Hash of a payment key",
4452
"example": "f6ac5676b58d8ce280c1f09af4a2e82dd58c1aa2fb075aa005afa1da",
@@ -96,16 +104,24 @@
96104
"issuer": {
97105
"$ref": "#/components/schemas/Address"
98106
},
107+
"reason": {
108+
"$ref": "#/components/schemas/SeizeReason"
109+
},
99110
"target": {
100111
"$ref": "#/components/schemas/Address"
101112
}
102113
},
103114
"required": [
104115
"issuer",
105-
"target"
116+
"target",
117+
"reason"
106118
],
107119
"type": "object"
108120
},
121+
"SeizeReason": {
122+
"description": "Reason for seizing funds",
123+
"type": "string"
124+
},
109125
"TextEnvelopeJSON": {
110126
"description": "Text envelope",
111127
"properties": {

0 commit comments

Comments
 (0)