Skip to content

feat(frontend): integrate pow into loader and guard logic #5890

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

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/frontend/src/lib/components/guard/AddressGuard.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { validateBtcAddressMainnet } from '$btc/services/btc-address.services';
import { POW_ENABLED } from '$env/pow.env';
import { validateEthAddress } from '$eth/services/eth-address.services';
import {
networkBitcoinMainnetEnabled,
Expand All @@ -18,11 +19,13 @@
let signerAllowanceLoaded = false;

const loadSignerAllowanceAndValidateAddresses = async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe now can be renamed?

Copy link
Collaborator Author

@DecentAgeCoder DecentAgeCoder Apr 30, 2025

Choose a reason for hiding this comment

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

Yes the pow environment naming has been fixed

Copy link
Collaborator

Choose a reason for hiding this comment

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

i mean, if you are going to remove the signer allowance, you can rename this function no?

My understanding is that once the feature is complete, the feature flag is gone, so that part inside the IF condition disappear. Or not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I recommend to leave the Feature flag, so that we can disable it quickly if there are issues with the PoW in production (e.g. to much CPU overhead, or not enough Cycles per time period are allowance (fine-tuning of settings)).

const { success: initSignerAllowanceSuccess } = await initSignerAllowance();
if (!POW_ENABLED) {
const { success: initSignerAllowanceSuccess } = await initSignerAllowance();

if (!initSignerAllowanceSuccess) {
// Sign-out is handled within the service.
return;
if (!initSignerAllowanceSuccess) {
// Sign-out is handled within the service.
return;
}
}

signerAllowanceLoaded = true;
Expand Down
41 changes: 22 additions & 19 deletions src/frontend/src/lib/components/loaders/Loaders.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,32 @@
import LoaderMetamask from '$lib/components/loaders/LoaderMetamask.svelte';
import LoaderUserProfile from '$lib/components/loaders/LoaderUserProfile.svelte';
import LoaderWallets from '$lib/components/loaders/LoaderWallets.svelte';
import PowProtector from '$lib/components/pow/PowProtector.svelte';
import UserSnapshotWorker from '$lib/components/rewards/UserSnapshotWorker.svelte';
</script>

<LoaderUserProfile>
<AddressGuard>
<Loader>
<UrlGuard>
<RewardGuard>
<LoaderEthBalances>
<LoaderWallets>
<ExchangeWorker>
<LoaderMetamask>
<UserSnapshotWorker>
<slot />
</UserSnapshotWorker>
</LoaderMetamask>
</ExchangeWorker>
</LoaderWallets>
</LoaderEthBalances>
</RewardGuard>
</UrlGuard>
</Loader>
</AddressGuard>
<PowProtector>
<AddressGuard>
<Loader>
<UrlGuard>
<RewardGuard>
<LoaderEthBalances>
<LoaderWallets>
<ExchangeWorker>
<LoaderMetamask>
<UserSnapshotWorker>
<slot />
</UserSnapshotWorker>
</LoaderMetamask>
</ExchangeWorker>
</LoaderWallets>
</LoaderEthBalances>
</RewardGuard>
</UrlGuard>
</Loader>
</AddressGuard>
</PowProtector>
</LoaderUserProfile>

<!-- This listener is kept outside of the Loaders tree to prevent slow page loading on localhost/e2e -->
Expand Down
16 changes: 10 additions & 6 deletions src/frontend/src/lib/services/loader.services.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BTC_MAINNET_NETWORK_ID } from '$env/networks/networks.btc.env';
import { ETHEREUM_NETWORK_ID } from '$env/networks/networks.eth.env';
import { SOLANA_MAINNET_NETWORK_ID } from '$env/networks/networks.sol.env';
import { POW_FEATURE_ENABLED } from '$env/pow.env';
import { allowSigning } from '$lib/api/backend.api';
import {
networkBitcoinMainnetEnabled,
Expand Down Expand Up @@ -40,7 +41,9 @@ export const initSignerAllowance = async (): Promise<ResultSuccess> => {
try {
const { identity } = get(authStore);

await allowSigning({ identity });
await allowSigning({
identity
});
} catch (_err: unknown) {
// In the event of any error, we sign the user out, as we assume that the Oisy Wallet cannot function without ETH or Bitcoin addresses.
await errorSignOut(get(i18n).init.error.allow_signing);
Expand Down Expand Up @@ -110,12 +113,13 @@ export const initLoader = async ({

// We are loading the addresses from the backend. Consequently, we aim to animate this operation and offer the user an explanation of what is happening. To achieve this, we will present this information within a modal.
setProgressModal(true);
if (!POW_FEATURE_ENABLED) {
const { success: initSignerAllowanceSuccess } = await initSignerAllowance();

const { success: initSignerAllowanceSuccess } = await initSignerAllowance();

if (!initSignerAllowanceSuccess) {
// Sign-out is handled within the service.
return;
if (!initSignerAllowanceSuccess) {
// Sign-out is handled within the service.
return;
}
}

const errorNetworkIds: NetworkId[] = err?.map(({ networkId }) => networkId) ?? [];
Expand Down
Loading