pnpm install
pnpm run dev # runs application in dev mode
pnpm run storybook # runs storybook in dev mode-
uifolder should only contain reusable chunks of code responsible only for rendering, any data should be passed via props.atomsconsist fromradix-uiprimitives and html tags,moleculesconsist ofatoms,organismsconsist ofmolecules.layoutsdefines general page layouts and screens. Atomic Design. -
domainfolder contains domain logic. Functions, hooks, types etc. It should contain all the business logic and data fetching logic. If some chunks of code are reusable, consider putting it in thecommonsubfolder. -
featuresfolder is the place where the code specific for a given feature (like easy borrow flow) should be placed. It contains logic as well as pure feature specific visual components. It should export a single container (connected component) that should wire logic with components. If the chunk of code is reusable (or is generic enough to be reusable in the future), put it either inuiordomainfollowing all the rules. -
configfolder contains only static (defined during compile time) objects that define the behaviour of the app. -
utilsfolder contains reusable functions, hooks that are not domain specific. For domain specific stuff considerdomain/common. For strictly UI specific utils considerui/utils.
Feature flags need to be verified by using process.env.NEXT_PUBLIC_FEATURE_X (and not some helper functions). Only then
dead code elimination for production builds work and disabled features will be entirely deleted in production build.
Control feature flags via .env files:
NEXT_PUBLIC_FEATURE_X=1
All feature flags are listed in .env.example file.
Integration tests focus on testing integration between different components within the app and don't hit real (or forked) blockchain node. We mock networking on viem's transport layer.
pnpm test
pnpm run testE2E tests utilize Tenderly forks (because local nodes like anvil are too slow) to test real interactions with blockchain.
pnpm test-e2e
CI=true pnpm test-e2e # to check locally if E2E tests pass, it's fully parallel, will record trace and retry failed tests (we do the same on CI)
pnpm test-e2e:ui # to inspect in Playwright UI and debug in ephemeral chrome windowTo control, from E2E test, the way application loads web3 wallets we inject wallet info via global object. To enable
this mechanism you need to start the app with: pnpm run dev --mode playwright.
Forks are by default removed after tests, to persist it set TENDERLY_PERSIST_FORK env variable to 1.
To enable tracing for better CI debugging, set PLAYWRIGHT_TRACE env variable to 1. You will able to download
playwright report with traces. The easiest way to explore it is to unpack the contents of playwright-report artifact
into the local folder packages/app/playwright-report, go to the folder packages/app and run
pnpx playwright show-reportTo ensure deterministic outcomes in e2e tests, we utilize a hardcoded future simulationDate, in both the browser
environment and on the forked blockchain. This approach is vital for accurately testing time-sensitive features, such as
LTV checks or fluctuating aToken values. We've chosen an arbitrary future date due to the current lack of more dynamic
time control methods on tenderly forks with idea that in near future we'll refactor to more robust solution.
Savings page E2E tests require mocking requests to LiFi API. To do so, we use overrideLiFiRouteWithHAR utility function
that leverages playwright's HAR recording feature. To create new or modify existing E2E tests that require mocking LiFi API,
follow these steps:
- Get the latest block number on the appropriate network (e.g. mainnet, gnosis).
- Set test's tenderly fork block number to the fetched block number. This is necessary because LiFi supports only requests to the current block, not to the past blocks. It is generally safe to have a small discrepancy between the block number set in tests and block number that LiFi request is recorded for, although be aware that this might be a potential source of issues.
- In
overrideLiFiRouteWithHARutility function, setupdateparameter totrue. This will record requests to LiFi API and save them to HAR file. Whenupdateis set totrue, the network requests are always carried out even if the HAR file is present. If you want to add a new test, pass a new unique key to theoverrideLiFiRouteWithHARfunction. The key should be descriptive of the request that is being mocked. - Ensure that the test user address is fixed - pass
privateKeyoption in the account options object to thesetupfunction in the test file. We follow the convention to passLIFI_TEST_USER_PRIVATE_KEYconstant. - Run the test. The test might fail some assertions, but the requests will still be recorded.
- Now we can make the data used in the test fixed. Set
updateparameter tofalseinoverrideLiFiRouteWithHARutility function. This will stop recording requests and use the HAR file instead. - You can now run the test again and potentially fix assertions that failed in the previous run.
- If necessary, you can modify the HAR file manually. This might be useful when you need to test rare edge cases.
In development and staging environments, there is an option to inject custom rpc with chainId via url. It can be used for instrumenting the app to test fork environments etc.
This functionality is guarded by the feature flag NEXT_PUBLIC_FEATURE_RPC_INJECTION_VIA_URL. Injected network details will be lost after the app is reloaded.
https://spark-app-staging.vercel.app/?rpc=https://rpc.example.com&chainId=1
Storybook and e2e tests are visually tested. Every story is automatically tested. In E2E tests screenshots are made explicitly.
Read the Lingui guide to understand how we translate the app.
Note: right now we extract the strings right before building the app to ensure that production build works fine. Read this issue to learn more.
The IP in this repository was assigned to Mars SPC Limited in respect of the MarsOne SP
Images that are used in img tags should be put into directory packages/app/src/ui/assets and exported in the assetts object. Other static assets, for instance the ones that are used as background images, should be put into packages/app/public directory and the path to them should be hardcoded in the code.