Skip to content

Commit

Permalink
fix: pass identity as data and not use store
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioVentilii committed Jun 21, 2024
1 parent 1377d89 commit 2e39a89
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { addTokenSteps } from '$lib/constants/steps.constants';
import InProgressWizard from '$lib/components/ui/InProgressWizard.svelte';
import IcAddTokenForm from '$icp/components/tokens/IcAddTokenForm.svelte';
import { authStore } from '$lib/stores/auth.store';
import { saveIcrcCustomToken } from '$icp/services/ic-custom-tokens.services';
import type { IcrcCustomToken } from '$icp/types/icrc-custom-token';
Expand Down Expand Up @@ -49,17 +50,18 @@
]);
};
const updateSaveProgressStep = (step: ProgressStepsAddToken) => (saveProgressStep = step);
const progress = (step: ProgressStepsAddToken) => (saveProgressStep = step);
const save = async (
tokens: Pick<IcrcCustomToken, 'enabled' | 'version' | 'ledgerCanisterId' | 'indexCanisterId'>[]
) => {
await saveIcrcCustomToken({
tokens,
updateSaveProgressStep,
progress,
modalNext: () => modal.set(3),
onSuccess: close,
onError: () => modal.set(0)
onError: () => modal.set(0),
identity: $authStore.identity
});
};
Expand Down
19 changes: 10 additions & 9 deletions src/frontend/src/icp/services/ic-custom-tokens.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { IcrcCustomToken } from '$icp/types/icrc-custom-token';
import { setManyCustomTokens } from '$lib/api/backend.api';
import { ProgressStepsAddToken } from '$lib/enums/progress-steps';
import { nullishSignOut } from '$lib/services/auth.services';
import { authStore } from '$lib/stores/auth.store';
import { i18n } from '$lib/stores/i18n.store';
import { toastsError } from '$lib/stores/toasts.store';
import type { OptionIdentity } from '$lib/types/identity';
import type { Identity } from '@dfinity/agent';
import { Principal } from '@dfinity/principal';
import { isNullish, toNullable } from '@dfinity/utils';
Expand Down Expand Up @@ -49,21 +49,22 @@ export const saveCustomTokens = async ({

export const saveIcrcCustomToken = async ({
tokens,
updateSaveProgressStep,
progress,
modalNext,
onSuccess,
onError
onError,
identity
}: {
tokens: Pick<IcrcCustomToken, 'enabled' | 'version' | 'ledgerCanisterId' | 'indexCanisterId'>[];
updateSaveProgressStep: (step: ProgressStepsAddToken) => void;
progress: (step: ProgressStepsAddToken) => void;
modalNext: () => void;
onSuccess: () => void;
onError: () => void;
identity: OptionIdentity;
}) => {
const $i18n = get(i18n);
const $authStore = get(authStore);

if (isNullish($authStore.identity)) {
if (isNullish(identity)) {
await nullishSignOut();
return;
}
Expand All @@ -79,12 +80,12 @@ export const saveIcrcCustomToken = async ({

try {
await saveCustomTokens({
identity: $authStore.identity,
identity,
tokens,
progress: updateSaveProgressStep
progress
});

updateSaveProgressStep(ProgressStepsAddToken.DONE);
progress(ProgressStepsAddToken.DONE);

setTimeout(() => onSuccess(), 750);
} catch (err: unknown) {
Expand Down

0 comments on commit 2e39a89

Please sign in to comment.