Skip to content

Commit 1878524

Browse files
authored
Merge pull request #111 from ChainSafe/irubido/onInstallDialog
onInstall dialog, build:local, manifest workflow
2 parents a4278e2 + 8465349 commit 1878524

File tree

7 files changed

+127
-4
lines changed

7 files changed

+127
-4
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Check Snap Manifest
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'packages/snap/snap.manifest.json'
7+
- '.github/workflows/check-snap-manifest.yml'
8+
push:
9+
branches:
10+
- main
11+
- master
12+
paths:
13+
- 'packages/snap/snap.manifest.json'
14+
- '.github/workflows/check-snap-manifest.yml'
15+
16+
jobs:
17+
check-manifest:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Check snap manifest allowedOrigins
25+
run: |
26+
cd packages/snap
27+
28+
# Check if jq is available
29+
if ! command -v jq &> /dev/null; then
30+
echo "jq is not installed. Installing..."
31+
sudo apt-get update && sudo apt-get install -y jq
32+
fi
33+
34+
# Extract allowedOrigins from the manifest
35+
ALLOWED_ORIGINS=$(jq -r '.initialPermissions."endowment:rpc".allowedOrigins[]' snap.manifest.json)
36+
37+
echo "Current allowedOrigins in snap.manifest.json:"
38+
echo "$ALLOWED_ORIGINS"
39+
40+
# Check if localhost is present
41+
if echo "$ALLOWED_ORIGINS" | grep -q "localhost"; then
42+
echo "❌ ERROR: localhost found in allowedOrigins. This should not be in production!"
43+
echo "Please ensure snap.manifest.json only contains production URLs."
44+
echo "Expected: [\"https://webzjs.chainsafe.dev\"]"
45+
exit 1
46+
fi
47+
48+
# Check if the production URL is present
49+
if ! echo "$ALLOWED_ORIGINS" | grep -q "https://webzjs.chainsafe.dev"; then
50+
echo "❌ ERROR: Production URL 'https://webzjs.chainsafe.dev' not found in allowedOrigins!"
51+
exit 1
52+
fi
53+
54+
# Check if there are any unexpected URLs
55+
UNEXPECTED_URLS=$(echo "$ALLOWED_ORIGINS" | grep -v "https://webzjs.chainsafe.dev" || true)
56+
if [ -n "$UNEXPECTED_URLS" ]; then
57+
echo "❌ ERROR: Unexpected URLs found in allowedOrigins:"
58+
echo "$UNEXPECTED_URLS"
59+
echo "Expected only: https://webzjs.chainsafe.dev"
60+
exit 1
61+
fi
62+
63+
echo "✅ SUCCESS: snap.manifest.json has correct allowedOrigins configuration"
64+
echo "Found: https://webzjs.chainsafe.dev"

packages/snap/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,27 @@ Snap uses a Rust library [WebZjs](https://github.com/ChainSafe/WebZjs) compiled
1818

1919
## 🔨 Development
2020

21-
For local development, you need to add `http://localhost:8080` to the `allowedOrigins` in `snap.manifest.json`. The `endowment:rpc` section should look like this:
21+
For local development, you need to add `http://localhost:3000` to the `allowedOrigins` in `snap.manifest.json`. The `endowment:rpc` section should look like this:
2222

2323
```json
2424
"endowment:rpc": {
2525
"allowedOrigins": ["https://webzjs.chainsafe.dev", "http://localhost:3000"]
2626
}
2727
```
2828

29+
### Build Scripts
30+
31+
- **`yarn build`** - Standard build for production (only allows production origins)
32+
- **`yarn build:local`** - Build for local development (automatically adds localhost:3000 to allowedOrigins)
33+
34+
The `build:local` script will:
35+
1. Create a backup of the original `snap.manifest.json`
36+
2. Modify the manifest to include `http://localhost:3000` in allowedOrigins
37+
3. Run the build process
38+
39+
### Development Steps
40+
2941
1. Install dependencies with `yarn install`
30-
2. Build the project with `yarn build`
31-
3. Host snap on localhost http://localhost:8080 `yarn serve`
42+
2. For local development: Build with `yarn build:local`
43+
3. For production: Build with `yarn build`
44+
4. Host snap on localhost http://localhost:8080 `yarn serve`

packages/snap/build_local.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Script to build the snap with localhost development origins
4+
5+
echo "Adding localhost:3000 to allowed origins in snap.manifest.json..."
6+
7+
# Use jq to modify the allowedOrigins array to include localhost:3000
8+
jq '.initialPermissions."endowment:rpc".allowedOrigins = ["https://webzjs.chainsafe.dev", "http://localhost:3000"]' snap.manifest.json > snap.manifest.json.tmp
9+
10+
# Replace the original file with the modified version
11+
mv snap.manifest.json.tmp snap.manifest.json
12+
13+
echo "Modified snap.manifest.json to include localhost:3000 for local development"
14+
15+
# Run the build command
16+
echo "Running build..."
17+
yarn build
18+
19+
echo "Build completed!"

packages/snap/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"allow-scripts": "yarn workspace root allow-scripts",
1818
"build": "mm-snap build",
1919
"build:clean": "yarn clean && yarn build",
20+
"build:local": "./build_local.sh",
2021
"clean": "rimraf dist",
2122
"lint": "eslint --color --ext .ts src/",
2223
"lint:fix": "yarn run lint --fix",

packages/snap/snap.manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/ChainSafe/WebZjs.git"
88
},
99
"source": {
10-
"shasum": "6xAVsbiI+vzYPOZ/f1+9GVEhLvYy9X/hhTuFXjQc1Sc=",
10+
"shasum": "iilrA+B7Wy4NObYvZCqTVbpN2iI14kqdCYCHGhqjnBM=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",
@@ -19,6 +19,7 @@
1919
},
2020
"initialPermissions": {
2121
"snap_dialog": {},
22+
"endowment:lifecycle-hooks": {},
2223
"endowment:webassembly": {},
2324
"endowment:rpc": {
2425
"allowedOrigins": ["https://webzjs.chainsafe.dev"]

packages/snap/src/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { signPczt } from './rpc/signPczt'
1414

1515
import { assert, object, number, optional, string } from 'superstruct';
1616
import { getSeedFingerprint } from './rpc/getSeedFingerprint';
17+
import type { OnInstallHandler } from "@metamask/snaps-sdk";
18+
import { installDialog } from './utils/dialogs';
1719

1820
let wasm: InitOutput;
1921

@@ -75,3 +77,7 @@ export const onUserInput: OnUserInputHandler = async ({ id, event }) => {
7577
}
7678
}
7779
};
80+
81+
export const onInstall: OnInstallHandler = async () => {
82+
await installDialog();
83+
};

packages/snap/src/utils/dialogs.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Box, Heading, Text } from "@metamask/snaps-sdk/jsx";
2+
3+
export const installDialog = async () => {
4+
await snap.request({
5+
method: "snap_dialog",
6+
params: {
7+
type: "alert",
8+
content: (
9+
<Box>
10+
<Heading>Thank you for installing Zcash Shielded Wallet snap</Heading>
11+
<Text>
12+
This snap utilizes Zcash Web Wallet.
13+
Visit Zcash Web Wallet at <a href="https://webzjs.chainsafe.dev/">webzjs.chainsafe.dev</a>.
14+
</Text>
15+
</Box>
16+
),
17+
},
18+
});
19+
};

0 commit comments

Comments
 (0)