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

fix(wallet): adding refresh after NEAR accounts switch #1027

Merged
merged 1 commit into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const WalletsList: React.FC<WalletsListProps> = ({
const {
currentWallet,
getAvailableAccounts,

availableWallets,
switchAccount,
switchWallet,
Expand Down Expand Up @@ -57,7 +56,7 @@ export const WalletsList: React.FC<WalletsListProps> = ({
<div className={styles.delimiter} />
<div className={styles.chooseWalletCaption}>Choose wallet</div>
{availableWallets.map(wallet =>
wallet.id === WalletType.NEAR && availableAccounts.length > 0 ? (
wallet.id === WalletType.NEAR && availableAccounts.length > 1 ? (
<WalletWithAccounts
key={wallet.id}
wallet={wallet}
Expand Down
14 changes: 13 additions & 1 deletion context/WalletContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ export const WrappedWalletContext: FC = ({ children }) => {

const { nearConfig } = configService.get();

if (currentWallet) {
CookieService.set(ACCOUNT_COOKIE, currentWallet.getAccountId(), {
path: '/',
});
} else {
CookieService.remove(ACCOUNT_COOKIE);
}

const selectedWalletContext: WalletContext = {
nearService: currentWallet ? new SputnikNearService(currentWallet) : null,
availableWallets: availableWallets.map(wallet => wallet.walletMeta()),
Expand Down Expand Up @@ -164,7 +172,11 @@ export const WrappedWalletContext: FC = ({ children }) => {
JSON.stringify(authData)
);

setPersistedWallet(WalletType.NEAR);
CookieService.set(ACCOUNT_COOKIE, accountId, {
path: '/',
});

router.reload();
},
async switchWallet(walletType: WalletType): Promise<void> {
const selectedWallet = availableWallets.find(
Expand Down