Skip to content

Commit

Permalink
chore: better check for getVCStore error
Browse files Browse the repository at this point in the history
  • Loading branch information
martines3000 committed Jun 19, 2023
1 parent 7de2baa commit 44c145d
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions packages/connector/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isError, isSuccess } from '@blockchain-lab-um/utils';
import { isError } from '@blockchain-lab-um/utils';
import { EthereumWebAuth, getAccountId } from '@didtools/pkh-ethereum';
import { DIDSession } from 'did-session';

Expand All @@ -10,32 +10,32 @@ export async function validateAndSetCeramicSession(
// Check if there is valid session in Masca
const api = masca.getMascaApi();

const enabledVCStoresResult = await api.getVCStore();
if (isError(enabledVCStoresResult)) {
throw new Error('Failed to get enabled VC stores.');
}

// Check if ceramic is enabled
const enabledVCStores = await api.getVCStore();
if (isSuccess(enabledVCStores)) {
if (enabledVCStores.data.ceramic === false) {
return;
}
if (enabledVCStoresResult.data.ceramic === false) {
return;
}

const session = await api.validateStoredCeramicSession();
if (!isError(session)) {
return;
}

const addresses = await window.ethereum.request({
const addresses: string[] = await window.ethereum.request({
method: 'eth_requestAccounts',
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const accountId = await getAccountId(
window.ethereum,
(addresses as string[])[0]
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call

const accountId = await getAccountId(window.ethereum, addresses[0]);

const authMethod = await EthereumWebAuth.getAuthMethod(
window.ethereum,
accountId
);

let newSession;
try {
newSession = await DIDSession.authorize(authMethod, {
Expand Down

0 comments on commit 44c145d

Please sign in to comment.