User Experience
The user should be informed about any actions that may take place, especially when funds are on the line. To ensure this, we will overtly request their confirmation via pincode before anything is done. The application has no way of knowing a user’s pincode, so it can’t decrypt their keypair without their confirmation. The modal window we’ve implemented facilitates this confirmation flow whenever we need it.
Code implementation
Our modal function uses thesvelte-simple-modal package to give us a versatile starting point. If you need to, install it now.
Wrapping the rest of our app in the modal
On the Svelte side, this modal component will be a “wrapper” around the rest of our application, which allows us to trigger the modal from anywhere we need, and it should behave similarly no matter what./src/routes/+layout.svelte
Creating a reusable modal Svelte component
To avoid reinventing the wheel every time we need a modal, we will create a reusable component that can accomodate most of our needs. Then, when we need the confirmation modal, we can pass an object of props to customize the modal’s behavior.In our
*.svelte component files, we will not dive into the HTML markup outside of the <script> tags. The Svelte syntax used in HTML is primarily used for iterating and is quite understandable to read./src/lib/components/ConfirmationModal.svelte
Trigger the modal component at signup
We can now use this modal component whenever we need to confirm something from the user. For example, here is how the modal is triggered when someone signs up./src/routes/signup/+page.svelte
Customizing confirmation and rejection behavior
Now, as these components have been written so far, they don’t actually do anything when the user inputs their pincode or clicks on a button. Let’s change that! Since the confirmation behavior must vary depending on the circumstances (for example, different actions for signup, transaction submission, etc.), we need a way to pass that as a prop when we open the modal window. First, in our modal component, we declare a dummy function to act as a prop, as well as an “internal” function that will call the prop function during the course of execution./src/lib/components/ConfirmationModal.svelte
/src/routes/signup/+page.svelte
onReject function, so we didn’t pass one. No harm, no foul!