Skip to content

Commit

Permalink
feat: updated prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbulma committed Sep 4, 2023
1 parent 3e4fd1d commit 864c23a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"tabWidth": 2,
"printWidth": 100
"printWidth": 80
}
56 changes: 44 additions & 12 deletions src/hooks/vault/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import React, { ReactNode, useContext, useEffect, useMemo, useState, useCallback } from "react";
import React, {
ReactNode,
useContext,
useEffect,
useMemo,
useState,
useCallback,
} from "react";
import env from "../../environment";
import { createActiveSession, deleteActiveSession } from "./utils/createActiveSession";
import {
createActiveSession,
deleteActiveSession,
} from "./utils/createActiveSession";
import {
ImportedAccount,
Owner,
Expand Down Expand Up @@ -34,7 +44,10 @@ type ReactVault = {
commitmentMapper: CommitmentMapper;
synchronizing: boolean;
getVaultSecret: () => Promise<string>;
getVaultId: ({ appId, derivationKey }: VaultNamespaceInputs) => Promise<string>;
getVaultId: ({
appId,
derivationKey,
}: VaultNamespaceInputs) => Promise<string>;
disconnect: () => void;
connect: (owner: Owner) => Promise<boolean>;
isVaultExist: (owner: Owner) => Promise<boolean>;
Expand Down Expand Up @@ -104,7 +117,8 @@ export default function SismoVaultProvider({

if (isImpersonated) {
const impersonatedVaultCreator = services.getImpersonatedVaultCreator();
const { impersonationErrors } = await impersonatedVaultCreator.getImpersonationState();
const { impersonationErrors } =
await impersonatedVaultCreator.getImpersonationState();
if (impersonationErrors.length > 0) {
setImpersonationErrors(impersonationErrors);
}
Expand Down Expand Up @@ -132,7 +146,10 @@ export default function SismoVaultProvider({

// Add a loading state which trigger only the first time when the user don't have a VaultV2
setSynchronizing(true);
const res = await vaultSynchronizer.sync(ownerConnectedV1, ownerConnectedV2);
const res = await vaultSynchronizer.sync(
ownerConnectedV1,
ownerConnectedV2
);
if (res && res.vault && !Boolean(vaultState.connectedOwner)) {
await Promise.all([
vaultState.updateConnectedOwner(res.owner),
Expand Down Expand Up @@ -215,7 +232,10 @@ export default function SismoVaultProvider({
return await vaultClient.getVaultSecret();
}, [vaultClient]);

const getVaultId = async ({ appId, derivationKey }: VaultNamespaceInputs): Promise<string> => {
const getVaultId = async ({
appId,
derivationKey,
}: VaultNamespaceInputs): Promise<string> => {
return await vaultClient.getVaultId({ appId, derivationKey });
};

Expand All @@ -230,10 +250,12 @@ export default function SismoVaultProvider({
syncVaults();
await vaultState.updateVaultState(vault);
const mnemonic = vault.mnemonics[0];
const accountNumber = vault.recoveryKeys.filter((key) => key.mnemonic === mnemonic).length - 1;
const accountNumber =
vault.recoveryKeys.filter((key) => key.mnemonic === mnemonic).length - 1;
const recoveryKeyGenerated = vault.recoveryKeys.find(
(recoveryKey) =>
recoveryKey.mnemonic === mnemonic && recoveryKey.accountNumber === accountNumber
recoveryKey.mnemonic === mnemonic &&
recoveryKey.accountNumber === accountNumber
);

return recoveryKeyGenerated.key;
Expand All @@ -248,7 +270,9 @@ export default function SismoVaultProvider({
const importAccount = async (account: ImportedAccount): Promise<void> => {
const vault = await vaultClient.importAccount(account);
if (account.type === "ethereum" && vaultState.autoImportOwners) {
if (!vault.owners.find((owner) => owner.identifier === account.identifier)) {
if (
!vault.owners.find((owner) => owner.identifier === account.identifier)
) {
await addOwner(account);
return;
}
Expand All @@ -257,7 +281,10 @@ export default function SismoVaultProvider({
await vaultState.updateVaultState(vault);
};

const deleteImportedAccount = async (owner: Owner, account: ImportedAccount): Promise<void> => {
const deleteImportedAccount = async (
owner: Owner,
account: ImportedAccount
): Promise<void> => {
const vault = await vaultClient.deleteImportedAccount(account);
await vaultState.updateVaultState(vault);
};
Expand All @@ -274,12 +301,17 @@ export default function SismoVaultProvider({
await vaultState.updateVaultState(vault);
};

const setAutoImportOwners = async (autoImportOwners: boolean): Promise<void> => {
const setAutoImportOwners = async (
autoImportOwners: boolean
): Promise<void> => {
const vault = await vaultClient.setAutoImportOwners(autoImportOwners);
await vaultState.updateVaultState(vault);
};

const setKeepConnected = async (owner: Owner, keepConnected: boolean): Promise<void> => {
const setKeepConnected = async (
owner: Owner,
keepConnected: boolean
): Promise<void> => {
const vault = await vaultClient.setKeepConnected(keepConnected);
if (!keepConnected) {
deleteActiveSession();
Expand Down

0 comments on commit 864c23a

Please sign in to comment.