Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: account event change get starknet #484

Merged
Changes from 4 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
797861f
feat: add account service
stanleyyconsensys Jan 7, 2025
36358e1
chore: fix lint
stanleyyconsensys Jan 7, 2025
2dc68ae
chore: update account contract discovery logic
stanleyyconsensys Jan 8, 2025
17b25fc
fix: code comment
stanleyyconsensys Jan 8, 2025
cc1efa4
chore: add discovery logic description
stanleyyconsensys Jan 8, 2025
a31b9c0
fix: lint
stanleyyconsensys Jan 8, 2025
fa288a4
feat: add account service factory
stanleyyconsensys Jan 9, 2025
f216dfb
fix: rename deployPayload
stanleyyconsensys Jan 9, 2025
40d3113
Merge branch 'feat/add-account-service-factory' into refactor/adopt-a…
stanleyyconsensys Jan 9, 2025
871156b
chore: adopt account discovery in RPCs
stanleyyconsensys Jan 9, 2025
21952f3
chore: update execute txn test
stanleyyconsensys Jan 9, 2025
4ec0c4f
fix: execute test
stanleyyconsensys Jan 9, 2025
883a3e6
fix: account discovery bug
stanleyyconsensys Jan 9, 2025
c92750a
fix: discovery logic
stanleyyconsensys Jan 9, 2025
5bc7498
feat: add `AddAccount` RPC
stanleyyconsensys Jan 10, 2025
0ebb0fe
feat: add max account create limit
stanleyyconsensys Jan 10, 2025
d2274af
fix: add `isMaxAccountLimitExceeded` unit test
stanleyyconsensys Jan 10, 2025
5726d9f
feat: add account ui
stanleyyconsensys Jan 13, 2025
2cb0633
fix: account deploy require result
stanleyyconsensys Jan 13, 2025
f579332
Merge branch 'refactor/adopt-account-discovery' into feat/add-account…
stanleyyconsensys Jan 13, 2025
504b195
fix: lint
stanleyyconsensys Jan 13, 2025
1e48259
fix: lint
stanleyyconsensys Jan 13, 2025
29396ff
feat: add get current account RPC
stanleyyconsensys Jan 13, 2025
c6e4eaf
feat: add list accounts rpc
stanleyyconsensys Jan 13, 2025
391d197
fix: lint
stanleyyconsensys Jan 13, 2025
80af8c4
feat: add swtich account rpc
stanleyyconsensys Jan 13, 2025
8221ca5
fix: comments on add account icon
stanleyyconsensys Jan 14, 2025
220399f
Merge branch 'feat/add-account-ui' into feat/switch-account-rpc
stanleyyconsensys Jan 14, 2025
48c1f15
chore: set new account to current in snap
stanleyyconsensys Jan 14, 2025
5dee95d
fix: lint
stanleyyconsensys Jan 14, 2025
c43a18b
feat: add manage multi account hooks
stanleyyconsensys Jan 14, 2025
e3e7303
fix: remove non exist component
stanleyyconsensys Jan 14, 2025
52f7c4a
fix: var naming in UI
stanleyyconsensys Jan 14, 2025
418654d
Merge branch 'feat/enable-multiple-accounts' into chore/set-new-accou…
stanleyyconsensys Jan 15, 2025
d666b4c
chore: update logger mocking
stanleyyconsensys Jan 15, 2025
433abd4
Merge branch 'chore/set-new-account-to-current' into feat/manage-mult…
stanleyyconsensys Jan 15, 2025
2a1bc6b
chore: update setAccounts logic in UI
stanleyyconsensys Jan 15, 2025
d6a9eb8
chore: remove duplicate when set account from UI
stanleyyconsensys Jan 15, 2025
6ef3706
chore: remove non necessary account array in UI
stanleyyconsensys Jan 15, 2025
259303a
feat: account selection dropdown
khanti42 Jan 15, 2025
f6cc906
Merge branch 'feat/switch-account-ui' into feat/manage-multi-accounts…
khanti42 Jan 15, 2025
e8d9300
chore: connect ui to snap for switch account
khanti42 Jan 15, 2025
7f2080a
Merge branch 'feat/enable-multiple-accounts' into feat/switch-account-ui
stanleyyconsensys Jan 16, 2025
bdf830b
chore: update get current account rpc to return data from state only
stanleyyconsensys Jan 16, 2025
3054ed7
feat: get-starknet support for account change event
khanti42 Jan 16, 2025
132c967
Merge branch 'feat/switch-account-ui' into feat/account-event-change-…
khanti42 Jan 16, 2025
850178d
chore: lint + prettier
khanti42 Jan 16, 2025
b5dd6c4
chore: fix comments
khanti42 Jan 16, 2025
ed03eb2
Merge branch 'feat/enable-multiple-accounts' into feat/switch-account-ui
khanti42 Jan 16, 2025
95cc0e2
chore: lint + prettier
khanti42 Jan 16, 2025
8c99689
Merge branch 'feat/switch-account-ui' into feat/account-event-change-…
khanti42 Jan 16, 2025
f8678dd
Merge branch 'feat/account-event-change-get-starknet' into feat/get-c…
khanti42 Jan 16, 2025
d56bb91
fix: use fromState=true
khanti42 Jan 16, 2025
16aadba
Merge branch 'feat/enable-multiple-accounts' into feat/switch-account-ui
khanti42 Jan 16, 2025
8d9554e
chore: fix comments
khanti42 Jan 16, 2025
c2ff296
chore: fix tests
khanti42 Jan 16, 2025
a69ebbc
Merge branch 'feat/switch-account-ui' into feat/account-event-change-…
khanti42 Jan 16, 2025
e945f78
chore: fix comments
khanti42 Jan 20, 2025
280bbd7
Merge branch 'feat/enable-multiple-accounts' into feat/account-event-…
khanti42 Jan 20, 2025
e551a3f
chore: fix comments
khanti42 Jan 20, 2025
f13be25
chore: fix comments
khanti42 Jan 21, 2025
f400b9c
fix: rollback change
stanleyyconsensys Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Meta } from '@storybook/react';
import { AccountSwitchAddressView } from './AccountSwitchAddress.view';
import { AccountSwitchModalView } from './AccountSwitchModal.view';

export default {
title: 'Molecule/AccountAddress',
component: AccountSwitchAddressView,
component: AccountSwitchModalView,
} as Meta;

const address =
@@ -20,38 +20,38 @@ const accounts = ['0x123...abcd', '0x456...efgh', '0x789...ijkl'];

export const Default = () => (
<div style={wrapperStyle}>
<AccountSwitchAddressView
address={address}
<AccountSwitchModalView
currentAddress={address}
accounts={accounts}
></AccountSwitchAddressView>
></AccountSwitchModalView>
</div>
);

export const TooltipTop = () => (
<div style={wrapperStyle}>
<AccountSwitchAddressView
address={address}
<AccountSwitchModalView
currentAddress={address}
accounts={accounts}
></AccountSwitchAddressView>
></AccountSwitchModalView>
</div>
);

export const Full = () => (
<div style={wrapperStyle}>
<AccountSwitchAddressView
address={address}
<AccountSwitchModalView
currentAddress={address}
accounts={accounts}
full
></AccountSwitchAddressView>
></AccountSwitchModalView>
</div>
);

export const DarkerBackground = () => (
<div style={{ ...wrapperStyle, backgroundColor: 'grey' }}>
<AccountSwitchAddressView
address={address}
<AccountSwitchModalView
currentAddress={address}
accounts={accounts}
full
></AccountSwitchAddressView>
></AccountSwitchModalView>
</div>
);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { shortenAddress, shortenDomain } from 'utils/utils';
import { Wrapper } from './AccountSwitchAddress.style';
import { Wrapper } from './AccountSwitchModal.style';
import { Menu } from '@headlessui/react';
import {
MenuItems,
@@ -14,26 +14,24 @@ import { useAppSelector } from 'hooks/redux';
import { useStarkNetSnap } from 'services';

interface Props {
address: string;
currentAddress: string;
accounts: string[];
full?: boolean;
starkName?: string;
}

export const AccountSwitchAddressView = ({
address,
export const AccountSwitchModalView = ({
currentAddress,
accounts,
full,
starkName,
}: Props) => {
const networks = useAppSelector((state) => state.networks);
const { switchAccount, initWalletData } = useStarkNetSnap();
const { switchAccount, initWalletData, addNewAccount } = useStarkNetSnap();
const chainId = networks?.items[networks.activeNetwork]?.chainId;

const { addNewAccount } = useStarkNetSnap();

const changeAccount = async (address: string) => {
const account = await switchAccount(chainId, address);
const changeAccount = async (currentAddress: string) => {
const account = await switchAccount(chainId, currentAddress);
await initWalletData({
account,
chainId,
@@ -45,10 +43,10 @@ export const AccountSwitchAddressView = ({
<Menu.Button style={{ background: 'none', border: 'none' }}>
<Wrapper backgroundTransparent iconRight="angle-down">
{full
? starkName ?? address
? starkName ?? currentAddress
: starkName
? shortenDomain(starkName)
: shortenAddress(address)}
: shortenAddress(currentAddress)}
</Wrapper>
</Menu.Button>

@@ -64,7 +62,7 @@ export const AccountSwitchAddressView = ({
<Menu.Item key={account}>
<NetworkMenuItem onClick={() => changeAccount(account)}>
<Radio
checked={account === address}
checked={account === currentAddress}
name="radio-buttons"
inputProps={{ 'aria-label': account }}
sx={{
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AccountSwitchModalView as AccountSwitchModal } from './AccountSwitchModal.view';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { useEffect, useRef, useState } from 'react';
import { RoundedIcon } from 'components/ui/atom/RoundedIcon';
import { AccountSwitchAddress } from 'components/ui/molecule/AccountSwitchAddress';
import { AccountSwitchModal } from 'components/ui/molecule/AccountSwitchModal';
import { AssetsList } from 'components/ui/molecule/AssetsList';
import { PopIn } from 'components/ui/molecule/PopIn';
import { AccountDetailsModal } from '../AccountDetailsModal';
@@ -116,8 +116,8 @@ export const SideBarView = ({ address }: Props) => {
<AccountLabel>My account</AccountLabel>
<RowDiv>
<InfoIcon onClick={() => setInfoModalOpen(true)}>i</InfoIcon>
<AccountSwitchAddress
address={address}
<AccountSwitchModal
currentAddress={address}
starkName={starkName}
accounts={accounts}
/>
35 changes: 29 additions & 6 deletions packages/wallet-ui/src/services/useStarkNetSnap.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ import {
isGTEMinVersion,
getTokenBalanceWithDetails,
isUserDenyError,
shortenAddress,
} from '../utils/utils';
import { setWalletConnection } from '../slices/walletSlice';
import { FeeToken, FeeTokenUnit, Network } from '../types';
@@ -800,13 +801,35 @@ export const useStarkNetSnap = () => {
};

const switchAccount = async (chainId: string, address: string) => {
return await invokeSnap<Account>({
method: 'starkNet_switchAccount',
params: {
dispatch(
enableLoadingWithMessage(
`Switching Account to ${shortenAddress(address)}`,
),
);
try {
const account = await invokeSnap<Account>({
method: 'starkNet_switchAccount',
params: {
chainId,
address,
},
});

await initWalletData({
account,
chainId,
address,
},
});
});

// push the current account into state
dispatch(setAccounts(account));

return account;
} catch (err: any) {
const toastr = new Toastr();
toastr.error(err.message as unknown as string);
} finally {
dispatch(disableLoading());
}
};

return {