Skip to content

Commit

Permalink
fix(State): Deleting peers on wallet deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesGuesnon committed Nov 22, 2023
1 parent 14da13f commit 719daf8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions context/state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountInfo } from "@airgap/beacon-sdk";
import { AccountInfo, getSenderId } from "@airgap/beacon-sdk";
import { BeaconWallet } from "@taquito/beacon-wallet";
import { PollingSubscribeProvider, TezosToolkit } from "@taquito/taquito";
import {
Expand Down Expand Up @@ -304,7 +304,21 @@ function reducer(state: tezosState, action: action): tezosState {
}
case "removeContract": {
const { [action.address]: _, ...contracts } = state.contracts;
const { [action.address]: __, ...aliases } = { ...state.aliases };
const { [action.address]: __, ...aliases } = state.aliases;
const { [action.address]: contractDapps, ...connectedDapps } =
state.connectedDapps;

Object.values(contractDapps).forEach(async dapp => {
const senderId = await getSenderId(dapp.publicKey);
state.p2pClient?.removePeer(
{
...dapp,
type: "p2p-pairing-response",
senderId,
},
true
);
});

const fav =
(state.favouriteContract || "") === action.address
Expand All @@ -320,6 +334,7 @@ function reducer(state: tezosState, action: action): tezosState {
favouriteContract: fav,
currentContract,
aliases,
connectedDapps,
};

saveState(newState);
Expand Down

0 comments on commit 719daf8

Please sign in to comment.