Skip to content

Commit

Permalink
Merge pull request #928 from near/develop
Browse files Browse the repository at this point in the history
develop -> main
  • Loading branch information
charleslavon authored Jan 16, 2024
2 parents dc23d5b + aef946d commit 4d9f1d1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"local-storage": "^2.0.0",
"lodash": "^4.17.21",
"near-fastauth-wallet": "^0.0.10",
"near-social-vm": "github:NearSocial/VM#1344e8650e8f9a1b5781271183536bcfc815493f",
"near-social-vm": "github:NearSocial/VM#use_attr_patch",
"next": "^13.5.6",
"react": "^18.2.0",
"react-bootstrap": "^2.5.0",
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/components/vm/VmInitializer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default function VmInitializer() {
const setVmStore = useVmStore((store) => store.set);
const { requestAuthentication, saveCurrentUrl } = useSignInRedirect();
const idOS = useIdOS();
const idosSDK = useIdosStore((state) => state.idOS);

useEffect(() => {
initNear &&
Expand Down Expand Up @@ -188,6 +189,7 @@ export default function VmInitializer() {
if (!near) {
return;
}
await idosSDK?.reset({ enclave: true });
useIdosStore.persist.clearStorage();
const wallet = await (await near.selector).wallet();
wallet.signOut();
Expand All @@ -196,7 +198,7 @@ export default function VmInitializer() {
setSignedAccountId(null);
resetAnalytics();
localStorage.removeItem('accountId');
}, [near]);
}, [idosSDK, near]);

const refreshAllowance = useCallback(async () => {
alert("You're out of access key allowance. Need sign in again to refresh it");
Expand Down
48 changes: 30 additions & 18 deletions src/pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import hereImage from '@near-wallet-selector/here-wallet/assets/here-wallet-icon
import meteorImage from '@near-wallet-selector/meteor-wallet/assets/meteor-icon.png';
import myNearImage from '@near-wallet-selector/my-near-wallet/assets/my-near-wallet-icon.png';
import nightlyImage from '@near-wallet-selector/nightly/assets/nightly.png';
import { useCallback, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';

import { openToast } from '@/components/lib/Toast';
import type { ToastType } from '@/components/lib/Toast/store';
import { ComponentWrapperPage } from '@/components/near-org/ComponentWrapperPage';
import { useBosComponents } from '@/hooks/useBosComponents';
import { useDefaultLayout } from '@/hooks/useLayout';
Expand All @@ -22,7 +23,14 @@ const SettingsPage: NextPageWithLayout = () => {
const idosCredentials = useIdosStore((state) => state.credentials);
const connectedWallet = useIdosStore((state) => state.connectedWallet);
const setIdosStore = useIdosStore((state) => state.set);
const [error, setError] = useState<string | null>(null);
const [error, setError] = useState<{ type: ToastType; title: string; description?: string } | null>(null);

const walletImages = [
{ name: 'meteor-wallet', ...meteorImage },
{ name: 'here-wallet', ...hereImage },
{ name: 'my-near-wallet', ...myNearImage },
{ name: 'nightly-wallet', ...nightlyImage },
];

const connectIdOS = useCallback(async () => {
if (!near || !idOS || !accountId) return;
Expand All @@ -34,28 +42,32 @@ const SettingsPage: NextPageWithLayout = () => {
await idOS.setSigner('NEAR', wallet);
const credentials = idosCredentials ?? (await idOS.data.list('credentials'));
setIdosStore({ credentials });
} else {
setError({
type: 'INFO',
title: `No idOS profile found for ${accountId}`,
});
}
} catch (error: any) {
console.error('Failed to init wallet + idOS: ', error);
const errorMessage = error.message ? error.message : 'unknown';
setError(errorMessage);
} finally {
if (!idosCredentials && error) {
openToast({
type: 'ERROR',
title: 'Failed to init wallet + idOS:',
description: `${error}`,
});
}
setError({
type: 'ERROR',
title: 'Falilure during idOS initialization:',
description: `${errorMessage}`,
});
}
}, [near, idOS, accountId, setIdosStore, idosCredentials, error]);
}, [near, idOS, accountId, setIdosStore, idosCredentials]);

const walletImages = [
{ name: 'meteor-wallet', ...meteorImage },
{ name: 'here-wallet', ...hereImage },
{ name: 'my-near-wallet', ...myNearImage },
{ name: 'nightly-wallet', ...nightlyImage },
];
useEffect(() => {
if (!idosCredentials && error) {
openToast({
type: error.type,
title: error.title,
description: error.description,
});
}
}, [error, idosCredentials]);

return (
<ComponentWrapperPage
Expand Down

2 comments on commit 4d9f1d1

@vercel
Copy link

@vercel vercel bot commented on 4d9f1d1 Jan 16, 2024

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 4d9f1d1 Jan 16, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.