Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech: Routes refactoring #151

Open
wants to merge 17 commits into
base: dev
Choose a base branch
from
Open

Conversation

tuul-wq
Copy link
Contributor

@tuul-wq tuul-wq commented Jun 30, 2024

  • Moved screens into routes
  • Removed src folder, made it more canonical in Remix world - app
  • remix-routes generates types for routes in app/types, save it in project's repository
  • Use url params to determine selected asset
  • Other code style/types/simplification refactoring

@tuul-wq tuul-wq self-assigned this Jun 30, 2024
@tuul-wq tuul-wq marked this pull request as ready for review July 2, 2024 14:03
Copy link

github-actions bot commented Jul 3, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 5.71% 393 / 6872
🔵 Statements 5.71% 393 / 6872
🔵 Functions 3.37% 5 / 148
🔵 Branches 7.56% 9 / 119
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
tailwind.config.ts 0% 0% 0% 0% 1-34
app/common/telegram/BackButton.tsx 0% 0% 0% 0% 1-63
app/common/telegram/MainButton.tsx 0% 0% 0% 0% 1-86
app/components/Assets/AssetsList.tsx 0% 0% 0% 0% 1-36
app/components/CreatePasswordForm/CreatePasswordForm.tsx 0% 0% 0% 0% 1-91
app/routes/exchange/select.tsx 0% 0% 0% 0% 1-55
app/routes/exchange/widget.$chainId.$assetId.tsx 0% 0% 0% 0% 1-104
app/routes/gifts/details.tsx 0% 0% 0% 0% 1-68
app/routes/gifts/index.tsx 0% 0% 0% 0% 1-84
app/routes/onboarding/create-wallet.tsx 0% 0% 0% 0% 1-100
app/routes/onboarding/index.tsx 0% 0% 0% 0% 1-37
app/routes/onboarding/password.tsx 0% 0% 0% 0% 1-56
app/routes/onboarding/restore.$mnemonic.tsx 0% 0% 0% 0% 1-95
app/routes/receive/token-select.tsx 0% 0% 0% 0% 1-36
app/routes/settings/backup.tsx 0% 0% 0% 0% 1-53
app/routes/settings/index.tsx 0% 0% 0% 0% 1-146
app/routes/settings/recovery.tsx 0% 0% 0% 0% 1-28
app/routes/settings/password/confirmation.tsx 0% 0% 0% 0% 1-22
app/routes/settings/password/current.tsx 0% 0% 0% 0% 1-70
app/routes/settings/password/new.tsx 0% 0% 0% 0% 1-39
app/routes/transfer/direct/token-select.tsx 0% 0% 0% 0% 1-36
app/routes/transfer/direct/$chainId.$assetId/$address.amount.tsx 0% 0% 0% 0% 1-104
app/routes/transfer/direct/$chainId.$assetId/$address.confirmation.tsx 0% 0% 0% 0% 1-128
app/routes/transfer/direct/$chainId.$assetId/$address.result.tsx 0% 0% 0% 0% 1-51
app/routes/transfer/direct/$chainId.$assetId/address.tsx 0% 0% 0% 0% 1-80
app/routes/transfer/gift/token-select.tsx 0% 0% 0% 0% 1-36
app/routes/transfer/gift/$chainId.$assetId/create.tsx 0% 0% 0% 0% 1-128
server/index.js 0% 0% 0% 0% 1-32
server/static.js 0% 0% 0% 0% 1-39
Generated in workflow #145

remixRoutes({ strict: true }),
mode === 'production' && compression({ algorithm: 'gzip', compressionOptions: { level: 9 } }),
mode === 'production' && compression({ algorithm: 'brotliCompress' }),
isTest(mode) ? react() : remix({ routes: r => createRoutesFromFolders(r) }),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because src was eliminated, additional configuration is redundant

@@ -0,0 +1,241 @@
declare module "remix-routes" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

types for $path from remix-routes
According to the docs, it could be generated in watch mode but I didn't manage to make it run with correct types (nested types was skipped). Seems that in watch mode @remix-run/v1-route-convention doesn't provide correct routes that remix-routes expect to see.
During build process everything works just fine 🤷‍♂️

@johnthecat what to hear your thoughts

query: ExportedQuery<import('../routes/onboarding/password').SearchParams>,
};

"/onboarding/restore/:mnemonic": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to pass sensitive data in the path? Can it be the case that UI might show the path somewhere on the screen and thus compromising the mnemonic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be visible easily since it's an iframe, but if we go to a network tab and see the request, you will see a mnemonic. So, still kinda unsafe way

Comment on lines +24 to +25
if (hideButtonTimeout) {
clearTimeout(hideButtonTimeout);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need hideButtonTimeout?

switch (e) {
case 'frame':
if (lottie.currentFrame === 0) {
timeoutId = setTimeout(() => lottie && lottie.pause(), lottie.getDuration());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should pause the animation before the gift starts to open (it's shaking first for ~3s) and continue when a user clicks on Claim

})();
if (!gifts) return;

getGiftsState(getGifts()!).then(([unclaimed]) => setUnclaimed(unclaimed));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's less readable when we call on a function inside another function with a symbol in the end as well
maybe it's better to separate them

if (!mounted) return;

if (value) {
navigate($path('/onboarding/restore/:mnemonic', { mnemonic: value }), { replace: true });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if it's safe to pass it like this, we don't even give access to the mnemonic in localStarage only is SecretLocalStorage

const navigate = useNavigate();
const { assets } = useGlobalContext();

const selectedAsset = pickAsset(chainId, assetId, assets);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after we come up with a state manager it might be more convenient to have selectedAsset there, otherwise, we need to run through all list of chain and asset every time

};
}, [amount, isAmountValid, maxAmountToSend, isPending, isAccountTerminate]);
const checkBalanceDeposit = !transferAll && +maxAmountToSend - (+amount || 0) < deposit;
setIsAmountValid(!!Number(+amount) && (+amount || 0) <= +maxAmountToSend && !checkBalanceDeposit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need both Number() and +amount

Comment on lines +40 to +42
// onAmountChange: () => {
// setIsAmountValid(prev => prev && !!deposit && +amount >= deposit);
// },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part was needed to check for gifts that a transfer amount was bigger than a deposit. Otherwise, a gift account cannot be created.
You can move this condition to another place since we no longer have a dependence on mainbatton

query: ExportedQuery<import('../routes/onboarding/password').SearchParams>,
};

"/onboarding/restore/:mnemonic": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be visible easily since it's an iframe, but if we go to a network tab and see the request, you will see a mnemonic. So, still kinda unsafe way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants