Skip to content

Commit

Permalink
feat: reload credits or wallet after create module (#1105)
Browse files Browse the repository at this point in the history
Signed-off-by: David Dal Busco <[email protected]>
  • Loading branch information
peterpeterparker authored Jan 17, 2025
1 parent 0d2b6fd commit d1132f8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/frontend/src/lib/components/guards/CreditsGuard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
interface Props {
detail: JunoModalDetail;
priceLabel: string;
withCredits: boolean;
insufficientFunds?: boolean;
children: Snippet;
onclose: () => void;
Expand All @@ -23,6 +24,7 @@
detail,
priceLabel,
insufficientFunds = $bindable(true),
withCredits = $bindable(false),
children,
onclose
}: Props = $props();
Expand All @@ -38,6 +40,10 @@
$effect(() => {
insufficientFunds = $balanceOrZero < fee && notEnoughCredits;
});
$effect(() => {
withCredits = !notEnoughCredits;
});
</script>

{#if notEnoughCredits}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
let { detail, onclose }: Props = $props();
let withCredits = $state(false);
let insufficientFunds = $state(true);
let step: 'init' | 'in_progress' | 'ready' | 'error' = $state('init');
Expand All @@ -46,6 +47,7 @@
missionControlId: $missionControlIdDerived,
subnetId,
monitoringStrategy,
withCredits,
onProgress
});
Expand Down Expand Up @@ -85,6 +87,7 @@
<CreditsGuard
{onclose}
bind:insufficientFunds
bind:withCredits
{detail}
priceLabel={$i18n.analytics.create_orbiter_price}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
let { detail, onclose }: Props = $props();
let withCredits = $state(false);
let insufficientFunds = $state(true);
let step: 'init' | 'in_progress' | 'ready' | 'error' = $state('init');
Expand All @@ -53,6 +54,7 @@
subnetId,
monitoringStrategy,
satelliteName,
withCredits,
onProgress
});
Expand Down Expand Up @@ -101,6 +103,7 @@

<CreditsGuard
{onclose}
bind:withCredits
bind:insufficientFunds
{detail}
priceLabel={$i18n.satellites.create_satellite_price}
Expand Down
20 changes: 17 additions & 3 deletions src/frontend/src/lib/services/wizard.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type { PrincipalText } from '$lib/types/principal';
import { type WizardCreateProgress, WizardCreateProgressStep } from '$lib/types/progress-wizard';
import type { Option } from '$lib/types/utils';
import { emit } from '$lib/utils/events.utils';
import { waitAndRestartWallet } from '$lib/utils/wallet.utils';
import type { Identity } from '@dfinity/agent';
import { Principal } from '@dfinity/principal';
import { assertNonNullish, isNullish, nonNullish, toNullable } from '@dfinity/utils';
Expand Down Expand Up @@ -190,6 +191,7 @@ interface CreateWizardParams {
identity: OptionIdentity;
subnetId: PrincipalText | undefined;
monitoringStrategy: CyclesMonitoringStrategy | undefined;
withCredits: boolean;
onProgress: (progress: WizardCreateProgress | undefined) => void;
}

Expand Down Expand Up @@ -351,7 +353,8 @@ const createWizard = async <T>({
createFn,
reloadFn,
monitoringFn,
onProgress
onProgress,
withCredits
}: Omit<CreateWizardParams, 'subnetId' | 'monitoringStrategy'> & {
errorLabel: keyof I18nErrors;
createFn: (params: { identity: Identity }) => Promise<T>;
Expand Down Expand Up @@ -382,11 +385,22 @@ const createWizard = async <T>({
});

const reload = async () => {
await reloadFn({ missionControlId, reload: true });
await Promise.allSettled([
...(withCredits
? [
loadCredits({
identity,
reload: true
})
]
: [waitAndRestartWallet()]),
reloadFn({ missionControlId, reload: true })
]);
};

if (nonNullish(monitoringFn)) {
const executeMonitoringFn = async () => {
await waitAndRestartWallet();
await monitoringFn({ identity, segment });
};

Expand All @@ -397,7 +411,7 @@ const createWizard = async <T>({
});
}

// Reload list of segments before navigation
// Reload list of segments and wallet or credits before navigation
await execute({
fn: reload,
onProgress,
Expand Down

0 comments on commit d1132f8

Please sign in to comment.