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

adding blockaid byline and feedback form #1767

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/deployFreighterApiBeta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Slack Notification
uses: rtCamp/action-slack-notify@4e5fb42d249be6a45a298f3c9543b111b02f7907 #v2.3.0
uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 #v2.3.2
env:
MSG_MINIMAL: true
SLACK_CHANNEL: team-wallet-eng
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deployFreighterApiProduction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
with:
title: Bump @stellar/freighter-api version to ${{ github.event.inputs.version }}
- name: Slack Notification
uses: rtCamp/action-slack-notify@4e5fb42d249be6a45a298f3c9543b111b02f7907 #v2.3.0
uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 #v2.3.2
env:
MSG_MINIMAL: true
SLACK_CHANNEL: release
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/runTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- run: yarn build:freighter-api
- run: yarn build:extension
- run: yarn test:ci
- run: yarn test:e2e
- run: ${{ github.base_ref == 'master' && 'IS_INTEGRATION_MODE=true' || '' }} yarn test:e2e
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/submitSafari.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Convert extension to Xcode project
run: xcrun safari-web-extension-converter ./extension/build --project-location $GYM_PROJECT --macos-only
- name: Set up ruby env
uses: ruby/setup-ruby@v1.203.0
uses: ruby/setup-ruby@v1.204.0
with:
ruby-version: 2.6.10
bundler-cache: true
Expand Down
2 changes: 2 additions & 0 deletions @shared/api/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const submitTransaction = async (

export const submitMessage = async (
blob: string,
version: string,
opts?: {
address?: string;
networkPassphrase?: string;
Expand All @@ -110,6 +111,7 @@ export const submitMessage = async (
response = await sendMessageToContentScript({
blob,
accountToSign,
apiVersion: version,
type: EXTERNAL_SERVICE_TYPES.SUBMIT_BLOB,
});
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion @shared/api/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ export const modifyAssetsList = async ({
export const simulateTokenTransfer = async (args: {
address: string;
publicKey: string;
memo: string;
memo?: string;
params: {
publicKey: string;
destination: string;
Expand Down
5 changes: 4 additions & 1 deletion @shared/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export interface ExternalRequestTx extends ExternalRequestBase {
}

export interface ExternalRequestBlob extends ExternalRequestBase {
apiVersion: string;
blob: string;
}

Expand Down Expand Up @@ -243,7 +244,9 @@ export interface Balance {
export type BlockAidScanAssetResult = Blockaid.TokenScanResponse;

export type BlockAidScanSiteResult = Blockaid.SiteScanResponse;
export type BlockAidScanTxResult = Blockaid.StellarTransactionScanResponse;
export type BlockAidScanTxResult = Blockaid.StellarTransactionScanResponse & {
request_id: string;
};
export type BlockAidBulkScanAssetResult = Blockaid.TokenBulkScanResponse;

export interface AssetBalance extends Balance {
Expand Down
5 changes: 4 additions & 1 deletion @stellar/freighter-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"start": "webpack --config webpack.dev.js --watch --mode development"
},
"types": "build/@stellar/freighter-api/src/index.d.ts",
"dependencies": {},
"dependencies": {
"buffer": "^6.0.3",
"semver": "^7.6.3"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^2.3.1"
}
Expand Down
25 changes: 19 additions & 6 deletions @stellar/freighter-api/src/signMessage.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
import packageJson from "../package.json";
import { Buffer } from "buffer";

import { submitMessage } from "@shared/api/external";
import { FreighterApiError } from "@shared/api/types";
import { FreighterApiNodeError } from "@shared/api/helpers/extensionMessaging";
import { isBrowser } from ".";

type SignMessageV3Response = {
signedMessage: Buffer | null;
signerAddress: string;
} & {
error?: FreighterApiError;
};

type SignMessageV4Response = {
signedMessage: string;
signerAddress: string;
} & {
error?: FreighterApiError;
};

export const signMessage = async (
message: string,
opts?: {
networkPassphrase?: string;
address?: string;
}
): Promise<
{ signedMessage: Buffer | null; signerAddress: string } & {
error?: FreighterApiError;
}
> => {
): Promise<SignMessageV3Response | SignMessageV4Response> => {
if (isBrowser) {
const req = await submitMessage(message, opts);
const req = await submitMessage(message, packageJson.version, opts);

if (req.error) {
return { signedMessage: null, signerAddress: "", error: req.error };
Expand Down
17 changes: 5 additions & 12 deletions extension/e2e-tests/addAsset.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { test, expect, expectPageToHaveScreenshot } from "./test-fixtures";
import { loginToTestAccount, PASSWORD } from "./helpers/login";
import { TEST_TOKEN_ADDRESS } from "./helpers/test-token";
import { TEST_TOKEN_ADDRESS, USDC_TOKEN_ADDRESS } from "./helpers/test-token";

test.skip("Adding unverified Soroban token", async ({ page, extensionId }) => {
test("Adding unverified Soroban token", async ({ page, extensionId }) => {
test.slow();
await loginToTestAccount({ page, extensionId });

await page.getByTestId("account-options-dropdown").click();
await page.getByText("Manage Assets").click({ force: true });
await page.getByText("Manage assets").click({ force: true });
await expect(page.getByText("Your assets")).toBeVisible();
await expectPageToHaveScreenshot({
page,
Expand All @@ -34,14 +34,6 @@ test.skip("Adding unverified Soroban token", async ({ page, extensionId }) => {
await expect(page.getByTestId("account-view")).toContainText("E2E");
});
test("Adding Soroban verified token", async ({ page, extensionId }) => {
const assetsList = await fetch(
"https://api.stellar.expert/explorer/testnet/asset-list/top50",
);
const assetsListData = await assetsList.json();
const verifiedToken =
assetsListData?.assets[0]?.contract ||
"CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA";

test.slow();
await loginToTestAccount({ page, extensionId });

Expand All @@ -51,7 +43,7 @@ test("Adding Soroban verified token", async ({ page, extensionId }) => {
await expect(page.getByText("Your assets")).toBeVisible();
await page.getByText("Add an asset").click({ force: true });
await page.getByText("Add manually").click({ force: true });
await page.getByTestId("search-token-input").fill(verifiedToken);
await page.getByTestId("search-token-input").fill(USDC_TOKEN_ADDRESS);
await expect(page.getByTestId("asset-notification")).toHaveText(
"On your listsFreighter uses asset lists to check assets you interact with. You can define your own assets lists in Settings.",
);
Expand Down Expand Up @@ -83,6 +75,7 @@ test("Adding Soroban verified token", async ({ page, extensionId }) => {
});
test.afterAll(async ({ page, extensionId }) => {
if (
process.env.IS_INTEGRATION_MODE &&
test.info().status !== test.info().expectedStatus &&
test.info().title === "Adding Soroban verified token"
) {
Expand Down
22 changes: 22 additions & 0 deletions extension/e2e-tests/helpers/stubs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { USDC_TOKEN_ADDRESS } from "./test-token";

export const STELLAR_EXPERT_ASSET_LIST_JSON = {
name: "StellarExpert Top 50",
provider: "StellarExpert",
description:
"Dynamically generated list based on technical asset metrics, including payments and trading volumes, interoperability, userbase, etc. Assets included in this list were not verified by StellarExpert team. StellarExpert is not affiliated with issuers, and does not endorse or advertise assets in the list. Assets reported for fraudulent activity removed from the list automatically.",
version: "1.0",
network: "testnet",
feedback: "https://stellar.expert",
assets: [
{
code: "USDC",
issuer: "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
contract: USDC_TOKEN_ADDRESS,
name: "USDC",
org: "unknown",
domain: "centre.io",
decimals: 7,
},
],
};
5 changes: 4 additions & 1 deletion extension/e2e-tests/helpers/test-token.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export const TEST_TOKEN_ADDRESS =
"CC7YMFMYZM2HE6O3JT5CNTFBHVXCZTV7CEYT56IGBHR4XFNTGTN62CPT";
"CB5IKHNEXCADYXZMCS75IDR4F6HJY4PYYAGL6LUPJHRLWFA4BWUYLWZE";

export const USDC_TOKEN_ADDRESS =
"CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA";
2 changes: 2 additions & 0 deletions extension/e2e-tests/sendPayment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PASSWORD,
} from "./helpers/login";
import { TEST_TOKEN_ADDRESS } from "./helpers/test-token";
import { toBeVisible } from "@testing-library/jest-dom/matchers";

test("Swap doesn't throw error when account is unfunded", async ({
page,
Expand Down Expand Up @@ -81,6 +82,7 @@ test("Send XLM payment to G address", async ({ page, extensionId }) => {
await page.getByText("Review Send").click({ force: true });

await expect(page.getByText("Confirm Send")).toBeVisible();
await expect(page.getByText("XDR")).toBeVisible();
await expectPageToHaveScreenshot({
page,
screenshot: "send-payment-confirm.png",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion extension/e2e-tests/test-fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { test as base, chromium, BrowserContext } from "@playwright/test";
import { test as base, chromium, BrowserContext, Page } from "@playwright/test";
import path from "path";

import { STELLAR_EXPERT_ASSET_LIST_JSON } from "./helpers/stubs.ts";

export const test = base.extend<{
context: BrowserContext;
extensionId: string;
page: Page;
}>({
context: async ({}, use) => {
const pathToExtension = path.join(__dirname, "../build");
Expand All @@ -15,6 +18,7 @@ export const test = base.extend<{
`--load-extension=${pathToExtension}`,
],
});

await use(context);
await context.close();
},
Expand All @@ -30,6 +34,15 @@ export const test = base.extend<{
const extensionId = background.url().split("/")[2];
await use(extensionId);
},
page: async ({ page }, use) => {
if (!process.env.IS_INTEGRATION_MODE) {
await page.route("*/**/testnet/asset-list/top50", async (route) => {
const json = STELLAR_EXPERT_ASSET_LIST_JSON;
await route.fulfill({ json });
});
}
use(page);
},
});

export const expectPageToHaveScreenshot = async (
Expand Down
2 changes: 1 addition & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@shared/api": "1.0.0",
"@shared/constants": "1.0.0",
"@shared/helpers": "1.0.0",
"@stellar/design-system": "2.0.0-beta.15",
"@stellar/design-system": "2.0.0-beta.17",
"@stellar/typescript-wallet-sdk-km": "^1.0.1",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^7.1.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as StellarSdk from "stellar-sdk";
import browser from "webextension-polyfill";
import { Store } from "redux";
import semver from "semver";

import {
ExternalRequestAuthEntry,
Expand Down Expand Up @@ -288,7 +289,7 @@ export const freighterApiMessageListener = (

const submitBlob = async () => {
try {
const { blob, accountToSign, address, networkPassphrase } =
const { apiVersion, blob, accountToSign, address, networkPassphrase } =
request as ExternalRequestBlob;

const { tab, url: tabUrl = "" } = sender;
Expand Down Expand Up @@ -339,6 +340,14 @@ export const freighterApiMessageListener = (
allowList.push(punycodedDomain);
localStore.setItem(ALLOWLIST_ID, allowList.join());
}

if (semver.gte(apiVersion, "4.0.0")) {
resolve({
signedBlob: Buffer.from(signedBlob).toString("base64"),
signerAddress,
});
return;
}
resolve({ signedBlob, signerAddress });
}

Expand Down
2 changes: 2 additions & 0 deletions extension/src/popup/__testHelpers__/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export const mockBalances = {
total: new BigNumber("100"),
available: new BigNumber("100"),
blockaidData: {
address:
"USDC-GCK3D3V2XNLLKRFGFFFDEJXA4O2J4X36HET2FE446AV3M4U7DPHO3PEM",
result_type: "Spam",
features: [{ feature_id: "METADATA", description: "baz" }],
},
Expand Down
Loading