Skip to content

Commit

Permalink
Merge pull request #881 from trilitech/release-2.0.0
Browse files Browse the repository at this point in the history
Release 2.0.0
  • Loading branch information
serjonya-trili authored Feb 21, 2024
2 parents c1752bc + 3c62cfb commit 685db58
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 47 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "umami",
"productName": "umami",
"version": "2.0.0-beta1",
"private": true,
"version": "2.0.0",
"author": "Trilitech <[email protected]>",
"description": "Tezos Wallet",
"homepage": "./",
Expand Down
4 changes: 0 additions & 4 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ const process = require("process");
let mainWindow;
let deeplinkURL;

// TODO: remove once the repository is public
process.env["GH_TOKEN"] =
"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";

// Assure single instance
if (!app.requestSingleInstanceLock()) {
app.quit();
Expand Down
39 changes: 18 additions & 21 deletions src/utils/beacon/BeaconPeers.test.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
import { NetworkType } from "@airgap/beacon-wallet";
import { ExtendedPeerInfo, NetworkType } from "@airgap/beacon-wallet";

import * as beaconHelper from "./beacon";
import { BeaconPeers } from "./BeaconPeers";
import { ProvidedPeerInfo } from "./types";
import { mockMnemonicAccount } from "../../mocks/factories";
import { dispatchMockAccounts } from "../../mocks/helpers";
import { act, render, screen, userEvent, waitFor, within } from "../../mocks/testUtils";
import { formatPkh } from "../format";
import { beaconActions } from "../redux/slices/beaconSlice";
import { store } from "../redux/store";

const peersData: ProvidedPeerInfo[] = [
const peersData: ExtendedPeerInfo[] = [
{
name: "dApp-1",
publicKey: "edpkv2YM4m3B3X5hDBQUHXzjwSDuwn8yQBdwXk2QLpwTW7XMbJSunM",
publicKey: "e15835f5b7bb7fae5a3ddbe3c71b3cdd9ee0a5ea2586f04e7669e9040f61810c",
senderId: "2MqUhvyAJy3UY",
type: "p2p-pairing-request",
id: "test-id-1",
version: "v1",
},
{
name: "dApp-2",
publicKey: "edpkvWu5C4wjmwKvbZu726N4h7SvqfTRaiamB6z8dTvd1qUnE6YQcP",
publicKey: "e15835f5b7bb7fae5a3ddbe3c71b3cdd9ee0a5ea2586f04e7669e9040f61810b",
senderId: "2UJwaEUy23W3g",
type: "p2p-pairing-request",
id: "test-id-2",
version: "v1.5",
},
{
name: "dApp-3",
publicKey: "edpkvJ7tLYQXFK5hz1Avs3zgHteNqfhHgowMNgSbv7gk3LePxKvTm1",
publicKey: "e15835f5b7bb7fae5a3ddbe3c71b3cdd9ee0a5ea2586f04e7669e9040f61810a",
senderId: "3obHXJP1D8QrB",
type: "p2p-pairing-request",
id: "test-id-3",
version: "v2",
},
];
let senderIds: string[];

beforeEach(async () => {
beforeEach(() => {
dispatchMockAccounts([mockMnemonicAccount(1), mockMnemonicAccount(2)]);
jest.spyOn(beaconHelper, "usePeers").mockReturnValue({ data: peersData } as any);
senderIds = await Promise.all(peersData.map(peer => beaconHelper.getSenderId(peer.publicKey)));
});

describe("<BeaconPeers />", () => {
Expand Down Expand Up @@ -91,7 +91,7 @@ describe("<BeaconPeers />", () => {
it("displays address pill with acc label if connected acc is present", async () => {
store.dispatch(
beaconActions.addConnection({
dAppId: senderIds[1],
dAppId: peersData[1].senderId,
accountPkh: mockMnemonicAccount(1).address.pkh,
networkType: NetworkType.MAINNET,
})
Expand All @@ -106,7 +106,7 @@ describe("<BeaconPeers />", () => {
it("displays address pill with acc pkh if connected acc was removed", async () => {
store.dispatch(
beaconActions.addConnection({
dAppId: senderIds[1],
dAppId: peersData[1].senderId,
accountPkh: mockMnemonicAccount(5).address.pkh,
networkType: NetworkType.MAINNET,
})
Expand All @@ -121,7 +121,7 @@ describe("<BeaconPeers />", () => {
it("displays network type from beacon connection request", async () => {
store.dispatch(
beaconActions.addConnection({
dAppId: senderIds[2],
dAppId: peersData[2].senderId,
accountPkh: mockMnemonicAccount(1).address.pkh,
networkType: NetworkType.OXFORDNET,
})
Expand Down Expand Up @@ -163,27 +163,24 @@ describe("<BeaconPeers />", () => {
const deleteButton = within(peerRows[1]).getByRole("button", { name: "Remove Peer" });
await act(() => user.click(deleteButton));

expect(beaconHelper.walletClient.removePeer).toHaveBeenCalledWith({
...peersData[1],
senderId: senderIds[1],
});
expect(beaconHelper.walletClient.removePeer).toHaveBeenCalledWith(peersData[1]);
});

it("removes connection from beaconSlice", async () => {
const user = userEvent.setup();
[
{
dAppId: senderIds[0],
dAppId: peersData[0].senderId,
accountPkh: mockMnemonicAccount(1).address.pkh,
networkType: NetworkType.MAINNET,
},
{
dAppId: senderIds[1],
dAppId: peersData[1].senderId,
accountPkh: mockMnemonicAccount(1).address.pkh,
networkType: NetworkType.GHOSTNET,
},
{
dAppId: senderIds[2],
dAppId: peersData[2].senderId,
accountPkh: mockMnemonicAccount(2).address.pkh,
networkType: NetworkType.CUSTOM,
},
Expand All @@ -198,11 +195,11 @@ describe("<BeaconPeers />", () => {
await act(() => user.click(deleteButton));

expect(store.getState().beacon).toEqual({
[senderIds[0]]: {
[peersData[0].senderId]: {
accountPkh: mockMnemonicAccount(1).address.pkh,
networkType: NetworkType.MAINNET,
},
[senderIds[2]]: {
[peersData[2].senderId]: {
accountPkh: mockMnemonicAccount(2).address.pkh,
networkType: NetworkType.CUSTOM,
},
Expand Down
16 changes: 8 additions & 8 deletions src/utils/beacon/BeaconPeers.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ExtendedPeerInfo, getSenderId } from "@airgap/beacon-wallet";
import {
AspectRatio,
Box,
Expand All @@ -12,8 +13,7 @@ import {
import { capitalize, noop } from "lodash";
import { Fragment, useEffect, useState } from "react";

import { getSenderId, usePeers, useRemovePeer } from "./beacon";
import { PeerInfoWithId } from "./types";
import { usePeers, useRemovePeer } from "./beacon";
import { TrashIcon } from "../../assets/icons";
import { AddressPill } from "../../components/AddressPill/AddressPill";
import colors from "../../style/colors";
Expand All @@ -29,13 +29,13 @@ export const BeaconPeers = () => {
const { data } = usePeers();

const removePeer = useRemovePeer();
const [peersWithId, setPeersWithId] = useState<PeerInfoWithId[]>([]);
const [peersWithId, setPeersWithId] = useState<ExtendedPeerInfo[]>([]);

// senderId will always be set here, even if we haven't saved it in beaconSlice for a dApp.
useEffect(() => {
const peerIdPromises = (data || []).map(async peer => ({
...peer,
senderId: await getSenderId(peer.publicKey),
senderId: peer.senderId || (await getSenderId(peer.publicKey)),
}));

Promise.all(peerIdPromises).then(setPeersWithId).catch(noop);
Expand Down Expand Up @@ -67,8 +67,8 @@ const PeersDisplay = ({
peerInfos,
removePeer,
}: {
peerInfos: PeerInfoWithId[];
removePeer: (peer: PeerInfoWithId) => void;
peerInfos: ExtendedPeerInfo[];
removePeer: (peer: ExtendedPeerInfo) => void;
}) => {
return (
<Box>
Expand All @@ -88,7 +88,7 @@ const PeersDisplay = ({
* @param peerInfo - peerInfo provided by beacon Api + computed dAppId.
* @param onRemove - action for deleting dApp connection.
*/
const PeerRow = ({ peerInfo, onRemove }: { peerInfo: PeerInfoWithId; onRemove: () => void }) => {
const PeerRow = ({ peerInfo, onRemove }: { peerInfo: ExtendedPeerInfo; onRemove: () => void }) => {
return (
<Flex justifyContent="space-between" height="106px" data-testid="peer-row" paddingY="30px">
<Flex>
Expand Down Expand Up @@ -123,7 +123,7 @@ const PeerRow = ({ peerInfo, onRemove }: { peerInfo: PeerInfoWithId; onRemove: (
*
* @param peerInfo - peerInfo provided by beacon Api + computed dAppId.
*/
const StoredPeerInfo = ({ peerInfo }: { peerInfo: PeerInfoWithId }) => {
const StoredPeerInfo = ({ peerInfo }: { peerInfo: ExtendedPeerInfo }) => {
const connectionInfo = useGetConnectionInfo(peerInfo.senderId);

if (!connectionInfo) {
Expand Down
14 changes: 5 additions & 9 deletions src/utils/beacon/beacon.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import {
ExtendedP2PPairingResponse,
ExtendedPeerInfo,
Serializer,
WalletClient,
getSenderId as beaconGetSenderId,
toHex,
} from "@airgap/beacon-wallet";
import { useToast } from "@chakra-ui/react";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { useContext, useEffect } from "react";

import { BeaconNotification } from "./BeaconNotification";
import { PeerInfoWithId, ProvidedPeerInfo, makePeerInfo } from "./types";
import { makePeerInfo } from "./types";
import { DynamicModalContext } from "../../components/DynamicModal";
import { useRemoveConnection } from "../hooks/beaconHooks";

Expand All @@ -33,14 +32,15 @@ export const useRefreshPeers = () => {
export const usePeers = () =>
useQuery({
queryKey: [PEERS_QUERY_KEY],
queryFn: () => walletClient.getPeers() as Promise<Array<ProvidedPeerInfo>>,
// getPeers actually returns ExtendedPeerInfo (with the senderId)
queryFn: () => walletClient.getPeers() as Promise<ExtendedPeerInfo[]>,
});

export const useRemovePeer = () => {
const refresh = useRefreshPeers();
const removeConnectionFromBeaconSlice = useRemoveConnection();

return (peerInfo: PeerInfoWithId) =>
return (peerInfo: ExtendedPeerInfo) =>
walletClient
.removePeer(peerInfo as ExtendedP2PPairingResponse)
.then(() => removeConnectionFromBeaconSlice(peerInfo.senderId))
Expand Down Expand Up @@ -86,10 +86,6 @@ export const BeaconProvider: React.FC<{
return children;
};

// it's crucial that we convert the publicKey to hex before calling getSenderId
// otherwise it gives incorrect results with lots of collisions
export const getSenderId = (publicKey: string) => beaconGetSenderId(toHex(publicKey));

export const resetBeacon = async () => {
// Until walletClient.destroy is fixed
await walletClient.removeAllAccounts();
Expand Down
3 changes: 0 additions & 3 deletions src/utils/beacon/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,3 @@ const peerInfoSchema = z.object({
});

export const makePeerInfo = peerInfoSchema.parse;

export type ProvidedPeerInfo = ReturnType<typeof makePeerInfo>;
export type PeerInfoWithId = ReturnType<typeof makePeerInfo> & { senderId: string };

3 comments on commit 685db58

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.❔
Category Percentage Covered / Total
🟒 Statements 81.93% 2866/3498
🟑 Branches 75.17% 969/1289
🟒 Functions 80.88% 880/1088
🟒 Lines 81.58% 2719/3333

Test suite run success

1140 tests passing in 159 suites.

Report generated by πŸ§ͺjest coverage report action from 685db58

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.❔
Category Percentage Covered / Total
🟒 Statements 81.93% 2866/3498
🟑 Branches 75.17% 969/1289
🟒 Functions 80.88% 880/1088
🟒 Lines 81.58% 2719/3333

Test suite run success

1140 tests passing in 159 suites.

Report generated by πŸ§ͺjest coverage report action from 685db58

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.❔
Category Percentage Covered / Total
🟒 Statements 81.93% 2866/3498
🟑 Branches 75.17% 969/1289
🟒 Functions 80.88% 880/1088
🟒 Lines 81.58% 2719/3333

Test suite run success

1140 tests passing in 159 suites.

Report generated by πŸ§ͺjest coverage report action from 685db58

Please sign in to comment.