diff --git a/.changeset/giant-rings-allow.md b/.changeset/giant-rings-allow.md new file mode 100644 index 0000000000..a845151cc8 --- /dev/null +++ b/.changeset/giant-rings-allow.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/apps/rwa-demo/src/app/(app)/SideBar.tsx b/packages/apps/rwa-demo/src/app/(app)/SideBar.tsx index 567a1dee16..70fdb0ecd2 100644 --- a/packages/apps/rwa-demo/src/app/(app)/SideBar.tsx +++ b/packages/apps/rwa-demo/src/app/(app)/SideBar.tsx @@ -69,7 +69,9 @@ export const SideBar: FC = () => { context={ <> - Profile}> + {account?.alias}} + > } label="Logout" diff --git a/packages/apps/rwa-demo/src/app/(loggedout)/login/page.tsx b/packages/apps/rwa-demo/src/app/(loggedout)/login/page.tsx index a8a6161f52..8404d5d674 100644 --- a/packages/apps/rwa-demo/src/app/(loggedout)/login/page.tsx +++ b/packages/apps/rwa-demo/src/app/(loggedout)/login/page.tsx @@ -1,19 +1,28 @@ 'use client'; import { useAccount } from '@/hooks/account'; import { Button } from '@kadena/kode-ui'; -import { useRouter } from 'next/navigation'; const Home = () => { - const { login } = useAccount(); - const router = useRouter(); + const { login, accounts, selectAccount } = useAccount(); const handleConnect = async () => { await login(); - router.push('/'); }; return (
+ + {accounts && accounts.length > 1 && ( +
    + {accounts.map((account) => ( +
  • + +
  • + ))} +
+ )}
); }; diff --git a/packages/apps/rwa-demo/src/components/AccountProvider/AccountProvider.tsx b/packages/apps/rwa-demo/src/components/AccountProvider/AccountProvider.tsx index 49100c9c63..f895c7eaa9 100644 --- a/packages/apps/rwa-demo/src/components/AccountProvider/AccountProvider.tsx +++ b/packages/apps/rwa-demo/src/components/AccountProvider/AccountProvider.tsx @@ -14,25 +14,30 @@ interface IAccountError { export interface IAccountContext { account?: IWalletAccount; + accounts?: IWalletAccount[]; error?: IAccountError; isMounted: boolean; login: () => void; logout: () => void; sign: (tx: IUnsignedCommand) => Promise; isAgent: boolean; + selectAccount: (account: IWalletAccount) => void; } export const AccountContext = createContext({ account: undefined, + accounts: undefined, isMounted: false, login: () => {}, logout: () => {}, sign: async () => undefined, isAgent: false, + selectAccount: () => {}, }); export const AccountProvider: FC = ({ children }) => { const [account, setAccount] = useState(); + const [accounts, setAccounts] = useState(); const [isMounted, setIsMounted] = useState(false); const [isAgentState, setIsAgentState] = useState(false); @@ -43,6 +48,12 @@ export const AccountProvider: FC = ({ children }) => { setIsAgentState(!!resIsAgent); }; + const selectAccount = (account: IWalletAccount) => { + setAccount(account); + localStorage.setItem(getAccountCookieName(), JSON.stringify(account)!); + router.replace('/'); + }; + const login = useCallback(async () => { const { message, focus, close } = await getWalletConnection(); focus(); @@ -53,12 +64,18 @@ export const AccountProvider: FC = ({ children }) => { if ((response.payload as any).status !== 'accepted') { return; } - const { payload } = await message('GET_STATUS', { + const { payload } = (await message('GET_STATUS', { name: 'RWA-demo', - }); + })) as { payload: IState }; - const account = (payload as IState).accounts[0] as IWalletAccount; - localStorage.setItem(getAccountCookieName(), JSON.stringify(account)!); + if (payload.accounts.length > 1) { + setAccounts(payload.accounts); + close(); + return; + } + + setAccounts(undefined); + setAccount(payload.accounts[0]); close(); }, [router]); @@ -106,7 +123,16 @@ export const AccountProvider: FC = ({ children }) => { return ( {children}