diff --git a/src/pages/settings.tsx b/src/pages/settings.tsx index 5dd397da25..9f27c21cfd 100644 --- a/src/pages/settings.tsx +++ b/src/pages/settings.tsx @@ -1,6 +1,9 @@ import type { WalletSelector } from '@near-wallet-selector/core'; -import { useRouter } from 'next/router'; -import { useCallback, useEffect, useState } from 'react'; +import hereImage from '@near-wallet-selector/here-wallet/assets/here-wallet-icon.png'; +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 { openToast } from '@/components/lib/Toast'; import { ComponentWrapperPage } from '@/components/near-org/ComponentWrapperPage'; @@ -8,7 +11,7 @@ import { useBosComponents } from '@/hooks/useBosComponents'; import { useDefaultLayout } from '@/hooks/useLayout'; import { useAuthStore } from '@/stores/auth'; import { useIdosStore } from '@/stores/idosStore'; -import type { IdosUser, NextPageWithLayout } from '@/utils/types'; +import type { NextPageWithLayout } from '@/utils/types'; const SettingsPage: NextPageWithLayout = () => { const components = useBosComponents(); @@ -17,34 +20,20 @@ const SettingsPage: NextPageWithLayout = () => { const idOS = useIdosStore((state) => state.idOS); const idosProfileExist = useIdosStore((state) => state.hasProfile); const idosCredentials = useIdosStore((state) => state.credentials); + const connectedWallet = useIdosStore((state) => state.connectedWallet); const setIdosStore = useIdosStore((state) => state.set); const [error, setError] = useState(null); - // const [showTooltip, setShowTooltip] = useState(false); - const createAccountUrl = - 'https://app.fractal.id/authorize?client_id=PXAbBxPErSPMXiKmMYQ3ged8Qxwqg1Px7ymhsuhaGP4&redirect_uri=https%3A%2F%2Fnear.org%2Fsettings&response_type=code&scope=contact%3Aread%20verification.uniqueness%3Aread%20verification.uniqueness.details%3Aread%20verification.idos%3Aread%20verification.idos.details%3Aread%20verification.wallet-near%3Aread%20verification.wallet-near.details%3Aread'; - const router = useRouter(); const connectIdOS = useCallback(async () => { if (!near || !idOS || !accountId) return; - const wallet = (await (await near.selector).wallet()) as WalletSelector['wallet']; + const wallet = (await (await near.selector).wallet()) as WalletSelector['wallet'] | any; const hasProfile = await idOS.hasProfile(accountId); - setIdosStore({ hasProfile }); + setIdosStore({ hasProfile, connectedWallet: wallet.id }); try { if (hasProfile) { await idOS.setSigner('NEAR', wallet); - const credentials = idosCredentials ?? (await idOS.data.list('credentials')); setIdosStore({ credentials }); - } else { - openToast({ - type: 'INFO', - title: 'No idOS profile found.', - description: "Need an idOS profile? Now you'll be redirected to the idOS website to create one.", - }); - - setTimeout(() => { - router.push(createAccountUrl); - }, 3000); } } catch (error: any) { console.error('Failed to init wallet + idOS: ', error); @@ -59,23 +48,26 @@ const SettingsPage: NextPageWithLayout = () => { }); } } - }, [accountId, error, idOS, idosCredentials, near, router, setIdosStore]); + }, [near, idOS, accountId, setIdosStore, idosCredentials, error]); - // useEffect(() => { - // if (accountId && router && router.query && router.query.code) { - // setShowTooltip(true); - // } - // }, [router]); + const walletImages = [ + { name: 'meteor-wallet', ...meteorImage }, + { name: 'here-wallet', ...hereImage }, + { name: 'my-near-wallet', ...myNearImage }, + { name: 'nightly-wallet', ...nightlyImage }, + ]; return ( ); diff --git a/src/stores/idosStore.ts b/src/stores/idosStore.ts index e625b8bbbd..ca29450776 100644 --- a/src/stores/idosStore.ts +++ b/src/stores/idosStore.ts @@ -10,6 +10,7 @@ type IdosState = { idOS?: IdosTypeTemp; currentUser?: IdosUser; hasProfile?: boolean; + connectedWallet?: string; credentials?: object[]; wallets?: IdosWalletInfo[]; }; @@ -24,6 +25,7 @@ export const useIdosStore = create( idOS: undefined, currentUser: undefined, hasProfile: false, + connectedWallet: undefined, credentials: undefined, wallets: undefined, set: (state) => set((previousState) => ({ ...previousState, ...state })),