Skip to content

Commit 5bcc900

Browse files
authored
feat: show keys in claim burn (#879)
Description --- Show keys in the claim burn in wallet ui. If the key is associated with an account you will see the account name. The account name is editable only when you select key without an associated account. Fix adding keys in the wallet ui. Motivation and Context --- How Has This Been Tested? --- Burning funds into new account. What process can a PR reviewer use to test or verify this change? --- Same as above. Create a burn for a new key and then claim it for a new account for this key. Breaking Changes --- - [x] None - [ ] Requires data directory to be deleted - [ ] Other - Please specify
1 parent 6d30028 commit 5bcc900

File tree

3 files changed

+65
-18
lines changed

3 files changed

+65
-18
lines changed

applications/tari_dan_wallet_web_ui/src/api/hooks/useKeys.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const useKeysList = () => {
3838
};
3939

4040
export const useKeysCreate = () => {
41-
return useMutation(() => jsonRpc('keys.create', []), {
41+
return useMutation(() => jsonRpc('keys.create', {}), {
4242
onError: (error: apiError) => {
4343
error;
4444
},

applications/tari_dan_wallet_web_ui/src/routes/AssetVault/Components/ClaimBurn.tsx

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,45 @@ import { useAccountsList, useAccountsClaimBurn } from "../../../api/hooks/useAcc
3636
import { useTheme } from "@mui/material/styles";
3737
import { accountsClaimBurn } from "../../../utils/json_rpc";
3838
import useAccountStore from "../../../store/accountStore";
39+
import { useKeysList } from "../../../api/hooks/useKeys";
3940

4041
export default function ClaimBurn() {
4142
const [open, setOpen] = useState(false);
4243
const [claimBurnFormState, setClaimBurnFormState] = useState({
4344
account: "",
45+
key: "",
4446
claimProof: "",
4547
fee: "",
4648
is_valid_json: false,
49+
newAccount: false,
4750
filled: false,
4851
disabled: false,
4952
});
5053

5154
const { data: dataAccountsList } = useAccountsList(0, 10);
55+
const { data: dataKeysList } = useKeysList();
5256
const { setPopup } = useAccountStore();
5357

54-
const onClaimBurnAccountChange = (e: SelectChangeEvent<string>) => {
58+
const onClaimBurnKeyChange = (e: SelectChangeEvent<string>) => {
59+
let key = e.target.value;
60+
let key_index = dataKeysList.keys.indexOf(key);
61+
let account = claimBurnFormState.account;
62+
let selected_account = dataAccountsList.accounts.find((account: any) => account.account.key_index === key_index);
63+
let new_account_name;
64+
if (selected_account !== undefined) {
65+
account = selected_account.account.name;
66+
new_account_name = false;
67+
} else {
68+
if (claimBurnFormState.newAccount === false) {
69+
account = "";
70+
}
71+
new_account_name = true;
72+
}
5573
setClaimBurnFormState({
5674
...claimBurnFormState,
57-
[e.target.name]: e.target.value,
75+
"key": key,
76+
"account": account,
77+
"newAccount": new_account_name,
5878
filled: claimBurnFormState.is_valid_json && claimBurnFormState.fee !== "" && e.target.value !== "",
5979
});
6080
};
@@ -69,7 +89,7 @@ export default function ClaimBurn() {
6989
...claimBurnFormState,
7090
[e.target.name]: e.target.value,
7191
is_valid_json: true,
72-
filled: claimBurnFormState.account !== "" && claimBurnFormState.fee !== "" && e.target.value !== "",
92+
filled: claimBurnFormState.key !== "" && claimBurnFormState.fee !== "" && e.target.value !== "",
7393
});
7494
} catch {
7595
setClaimBurnFormState({
@@ -81,21 +101,32 @@ export default function ClaimBurn() {
81101
}
82102
};
83103

104+
const onClaimBurnAccountNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
105+
setClaimBurnFormState({
106+
...claimBurnFormState,
107+
[e.target.name]: e.target.value,
108+
filled: claimBurnFormState.key !== "" && claimBurnFormState.is_valid_json && e.target.value !== "",
109+
});
110+
}
111+
84112
const onClaimBurnFeeChange = (e: React.ChangeEvent<HTMLInputElement>) => {
85113
setClaimBurnFormState({
86114
...claimBurnFormState,
87115
[e.target.name]: e.target.value,
88-
filled: claimBurnFormState.account !== "" && claimBurnFormState.is_valid_json && e.target.value !== "",
116+
filled: claimBurnFormState.key !== "" && claimBurnFormState.is_valid_json && e.target.value !== "",
89117
});
90118
}
91119

92120
const onClaimBurn = async () => {
93121
try {
94122
setClaimBurnFormState({ ...claimBurnFormState, disabled: true });
95-
await accountsClaimBurn(claimBurnFormState.account, JSON.parse(claimBurnFormState.claimProof), +claimBurnFormState.fee);
123+
await accountsClaimBurn(claimBurnFormState.account, JSON.parse(claimBurnFormState.claimProof), +claimBurnFormState.fee, +claimBurnFormState.key[0]);
96124
setOpen(false);
97125
setPopup({ title: "Claimed", error: false });
98-
setClaimBurnFormState({ account: "", claimProof: "", fee: "", is_valid_json: false, filled: false, disabled: false });
126+
setClaimBurnFormState({
127+
key: "", account: "", claimProof: "", fee: "", is_valid_json: false, filled: false, disabled: false,
128+
newAccount: false,
129+
});
99130
} catch (e: any) {
100131
setClaimBurnFormState({ ...claimBurnFormState, disabled: false });
101132
setPopup({ title: "Claim burn failed: " + e.message, error: true });
@@ -111,6 +142,14 @@ export default function ClaimBurn() {
111142
setOpen(false);
112143
};
113144

145+
const formattedKey = (key: any[]) => {
146+
let account = dataAccountsList.accounts.find((account: any) => account.account.key_index === +key[0])
147+
if (account === undefined) {
148+
return <div><b>{key[0]}</b> {key[1]}</div>
149+
}
150+
return <div><b>{key[0]}</b> {key[1]}<br></br>Account <i>{account.account.name}</i></div>
151+
}
152+
114153
return (
115154
<div>
116155
<Button variant="outlined" onClick={handleClickOpen}>
@@ -121,23 +160,30 @@ export default function ClaimBurn() {
121160
<DialogContent className="dialog-content">
122161
<Form onSubmit={onClaimBurn} className="flex-container-vertical" style={{ paddingTop: theme.spacing(1) }}>
123162
<FormControl>
124-
<InputLabel id="account">Account</InputLabel>
163+
<InputLabel id="key">Key</InputLabel>
125164
<Select
126-
labelId="account"
127-
name="account"
128-
label="Account"
129-
value={claimBurnFormState.account}
130-
onChange={onClaimBurnAccountChange}
165+
labelId="key"
166+
name="key"
167+
label="Key"
168+
value={claimBurnFormState.key}
169+
onChange={onClaimBurnKeyChange}
131170
style={{ flexGrow: 1, minWidth: "200px" }}
132171
disabled={claimBurnFormState.disabled}
133172
>
134-
{dataAccountsList?.accounts.map((account: any) => (
135-
<MenuItem key={account.account.address.Component} value={account.account.address.Component}>
136-
{account.account.name}
173+
{dataKeysList?.keys?.map((key: any) => (
174+
<MenuItem key={key} value={key}>
175+
{formattedKey(key)}
137176
</MenuItem>
138177
))}
139178
</Select>
140179
</FormControl>
180+
<TextField name="account"
181+
label="Account Name"
182+
value={claimBurnFormState.account}
183+
onChange={onClaimBurnAccountNameChange}
184+
style={{ flexGrow: 1 }}
185+
disabled={claimBurnFormState.disabled || !claimBurnFormState.newAccount}>
186+
</TextField>
141187
<TextField
142188
name="claimProof"
143189
label="Claim Proof"

applications/tari_dan_wallet_web_ui/src/utils/json_rpc.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,13 @@ export const transactionsWaitResult = (hash: string, timeoutSecs: number | null)
128128
jsonRpc("transactions.wait_result", [hash, timeoutSecs]);
129129

130130
// accounts
131-
export const accountsClaimBurn = (account: string, claimProof: any, fee: number) =>
131+
export const accountsClaimBurn = (account: string, claimProof: any, fee: number, key_id: number) =>
132132
// Fees are passed as strings because Amount is tagged
133133
jsonRpc("accounts.claim_burn", {
134134
account,
135135
claim_proof: claimProof,
136-
fee: fee,
136+
fee,
137+
key_id,
137138
});
138139
export const accountsCreate = (
139140
accountName: string | undefined,

0 commit comments

Comments
 (0)