Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces the Nimiq Wallet Playground.
The user will be able to enter
https://wallet-testnet.nimiq.com/?demo
and start playing with the Wallet with no account whatsoever.This will be useful for the coming new nimiq.com/wallet page. As soon this feature goes live, soon after the new page will be updated.
The user will be able to open the Wallet and do different actions such as:
Live preview
playground
branch.Development
Use the
playground
branch, install the new dependencies and openhttp://localhost:8081?demo
Tip
One good thing about this new feature is that we no longer have to run Keyguard and the Hub in parallel. Very useful if you are working on UI stuff.
Note
You need to enable
polygon
inconfig.local
to see USDC and USDT.Package Dependencies
vue-router
from3.1.6
to3.5.0
. See this commentDemo Mode Implementation
I've tried to touch as little code from the current application as possible, as we don't want to introduce any problems for current users. All demo related code can be found in
stores/Demo.ts
. I decided not to create multiple files on purpose, even though the code is a bit spaghetti in my opinion.main.ts
We don't want to write anything to the user's storage, so when the application is initialised, the first thing it does is check whether the
?demo
parameter exists or not. If it exists, we also "inject" the?demo
parameter after each route change.Hub API
We don't want to launch the Hub API when the demo is active. So a new "mock" implementation of the Hub API has been introduced:
This demo, will block any attempt to open the hub popup and instead handle the opening of the new "DemoModalFallback" which will let the user know that the playground functionality is limited and they have reached the end of the playground
Sometimes the HubAPI will not display this modal and will instead fake the operation. For example, if you are exchanging two currencies, the Hub API will create a fake exchange and you will see the whole process.
You can see the
DemoHubApi
in the./stores/Demo.ts
and the "Faked Flows" section in this PR.Fake accounts & transactions
To add some realism, we insert fake transactions in NIM, BTC, USDC and USDT. The transactions in NIM have customised messages using cultural references from around the world. Fun fact: the NIM amount is
140418
, which is a date:14th of april, 2018
.We are prioritizing realism, so instead of using a
Math.random
for the values of each transaction we do use a ratio of the total amount that the user has now. This allows us to confidently know that the balance shown in the overview matches the transaction history.Intercept fetch request
We rely on some HTTP APIs to fetch some data like the
/limits
for the swaps. In those cases, we intercept the fetch request and return the value we want.Faked flows
One of the reasons of the Nimiq Wallet Playground is to let the user play without an account. Therefore the most notorious and important flows have been faked.
These are the faked flows:
replaceBuyNimFlow
functionreplaceStakingFlow
functionCommunication with the host
Since this feature will be used as an
iframe
, we would like let the host and the app talk to each other. Therefore, we have the functionattachIframeListeners
.Basically, the user has the option to click: "Buy", "stake" or "swap" in the website. The selector has will have one of the options highlighted if the user is within that flow.
Therefore, this communication needs to be two-way, meaning that if the user changes the flow from the application, the application needs to communicate this to the host, or if the user changes the flow from the selector, the host needs a request to initialise to that flow.
Custom CSS + Visual cues
When the playground is enabled we add also some visual cues to the user to let them know where to click. This cues are added from
Demo.ts@setupVisualCues
function.We also inject some CSS to make some minor adjustments.
Further work
At the moment there are some things we can improve:
Translations
Should we translate the transactions messages and labels?
Error while redirecting
Is there a way to ignore it? It does not block the experience, but it is annoying.
Fallback modal
We could improve the current fallback modal. There are certain scenarios where the user has done something that triggers the Hub API. In those cases, this fallback modal is displayed. We need to make sure that the user understands that they are in a playground mode and that the functionality is limited.
See screenshot
Personal TODOs to make this PR ready for review