Skip to content

Commit

Permalink
add clear button handling
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeRx committed Sep 17, 2024
1 parent 9320bb8 commit 8d48cdb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/examples/packages/send-flow/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "5JS4MeFhPgGu+XKGmUzPDgtSm36g+X/9qOsiTg/oo2k=",
"shasum": "gzJCMLpHGnluVixURDT1ED3ia6/iuQvkdOpA3hjvDRM=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ export const SendForm: SnapComponent<SendFormProps> = ({
<Box>
<Image src={jazzicon3} />
</Box>
<Input name="to" placeholder="Enter receiving address" />
<Input
name="to"
placeholder="Enter receiving address"
value={toAddress ?? undefined}
/>
{toAddress !== null && toAddress !== '' && (
<Box>
<Button name="clear">
Expand Down
52 changes: 38 additions & 14 deletions packages/examples/packages/send-flow/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,25 @@ export const onUserInput: OnUserInputHandler = async ({
}) => {
const { selectedCurrency, fees } = context as SendFlowContext;

const state = await snap.request({
method: 'snap_getInterfaceState',
params: { id },
});

const sendForm = state.sendForm as SendFormState;

const formErrors = formValidation(sendForm, context as SendFlowContext);

const total = {
amount: Number(sendForm.amount) + fees.amount,
fiat: 250 + fees.fiat,
};

if (event.type === UserInputEventType.InputChangeEvent) {
switch (event.name) {
case 'amount':
case 'to':
case 'accountSelector': {
const state = await snap.request({
method: 'snap_getInterfaceState',
params: { id },
});

const sendForm = state.sendForm as SendFormState;

const formErrors = formValidation(sendForm, context as SendFlowContext);

const total = {
amount: Number(sendForm.amount) + fees.amount,
fiat: 250 + fees.fiat,
};

await snap.request({
method: 'snap_updateInterface',
params: {
Expand All @@ -147,5 +147,29 @@ export const onUserInput: OnUserInputHandler = async ({
default:
break;
}
} else if (event.type === UserInputEventType.ButtonClickEvent) {
switch (event.name) {
case 'clear':
await snap.request({
method: 'snap_updateInterface',
params: {
id,
ui: (
<SendFlow
accounts={accountsArray}
selectedAccount={sendForm.accountSelector}
selectedCurrency={selectedCurrency}
total={total}
fees={fees}
toAddress={null}
errors={formErrors}
/>
),
},
});
break;
default:
break;
}
}
};

0 comments on commit 8d48cdb

Please sign in to comment.