@ututrust/utu-metamask-snap 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,13 +1,16 @@
1
1
  # UTU Trust MetaMask Snap
2
2
 
3
- The main README.md is at the root of the utu-metamask-snap repository and is more comprehensive than this one.
4
-
5
3
  UTU has built a Snap (a MetaMask plugin) that lets you get UTU trust signal inside your MetaMask wallet right at the moment when you're about to confirm a transaction or sign a message.
6
4
 
7
5
  [More information about UTU](https://app.utu.io)
8
6
 
9
7
  Find the [repository here](https://gitlab.com/ututrust/utu-metamask-snap.git)
10
8
 
9
+ ## Prerequisites
10
+
11
+ - [MetaMask](https://metamask.io/) browser extension installed
12
+ - A valid UTU API access token — fetch this from your backend or via the [UTU auth flow](https://app.utu.io)
13
+
11
14
  ## Install
12
15
 
13
16
  ```bash
@@ -19,21 +22,35 @@ npm i @ututrust/utu-metamask-snap
19
22
  ### Quickstart React
20
23
 
21
24
  The snippet below shows how to install and authorize the UTU Snap from your web3 app.
22
- You need a valid UTU API access token before calling `authorizeUTUSnap` fetch it from your backend or via the UTU auth flow.
23
25
 
24
26
  ```jsx
25
- import React from 'react';
27
+ import React, { useState } from 'react';
28
+
29
+ const SNAP_ID = 'npm:@ututrust/utu-metamask-snap';
26
30
 
27
31
  const Snap = () => {
32
+ const [loading, setLoading] = useState(false);
33
+ const [error, setError] = useState(null);
34
+ const [installed, setInstalled] = useState(false);
35
+
28
36
  const installSnap = async () => {
37
+ setError(null);
38
+ setLoading(true);
39
+
29
40
  try {
30
- const accessToken = await getUTUApiAccessToken(); // Replace with your logic for fetching the token
41
+ // Ensure MetaMask is available
42
+ if (!window.ethereum) {
43
+ throw new Error('MetaMask is not installed. Please install it and try again.');
44
+ }
45
+
46
+ // Fetch a UTU API access token from your backend or auth flow
47
+ const accessToken = await getUTUApiAccessToken();
31
48
 
32
49
  // Request to install the UTU Snap
33
50
  await window.ethereum.request({
34
51
  method: 'wallet_requestSnaps',
35
52
  params: {
36
- 'npm:@ututrust/utu-metamask-snap': {},
53
+ [SNAP_ID]: {},
37
54
  },
38
55
  });
39
56
 
@@ -41,7 +58,7 @@ const Snap = () => {
41
58
  await window.ethereum.request({
42
59
  method: 'wallet_invokeSnap',
43
60
  params: {
44
- snapId: 'npm:@ututrust/utu-metamask-snap',
61
+ snapId: SNAP_ID,
45
62
  request: {
46
63
  method: 'authorizeUTUSnap',
47
64
  params: { token: accessToken },
@@ -49,17 +66,20 @@ const Snap = () => {
49
66
  },
50
67
  });
51
68
 
52
- console.log('UTU Snap installed and authorized!');
53
- } catch (error) {
54
- console.error('Error installing or authorizing the UTU Snap:', error);
69
+ setInstalled(true);
70
+ } catch (err) {
71
+ setError(err.message || 'Failed to install the UTU Snap. Please try again.');
72
+ } finally {
73
+ setLoading(false);
55
74
  }
56
75
  };
57
76
 
58
77
  return (
59
78
  <div>
60
- <button onClick={installSnap}>
61
- Install UTU Trust Snap
79
+ <button onClick={installSnap} disabled={loading || installed}>
80
+ {loading ? 'Installing...' : installed ? 'Installed' : 'Install UTU Trust Snap'}
62
81
  </button>
82
+ {error && <p style={{ color: 'red' }}>{error}</p>}
63
83
  </div>
64
84
  );
65
85
  };
@@ -67,4 +87,6 @@ const Snap = () => {
67
87
  export default Snap;
68
88
  ```
69
89
 
90
+ > **Note:** `getUTUApiAccessToken()` is a placeholder. Replace it with a call to your own backend endpoint that returns a UTU API token. Never fetch the token by calling the UTU API directly from frontend code — doing so would require exposing API secrets in the browser, which can be stolen by anyone inspecting your app.
91
+
70
92
  Once authorized, the snap will automatically show UTU trust insights whenever the user confirms a transaction or signs a message in MetaMask.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ututrust/utu-metamask-snap",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "description": "UTU Trust MetaMask Snap",
5
5
  "homepage": "https://app.utu.io/dashboard?source=snap",
6
6
  "repository": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.11.0",
2
+ "version": "1.12.0",
3
3
  "description": "Snap giving UTU Trust!",
4
4
  "proposedName": "UTU Trust",
5
5
  "repository": {
@@ -7,7 +7,7 @@
7
7
  "url": "https://gitlab.com/ututrust/utu-metamask-snap.git"
8
8
  },
9
9
  "source": {
10
- "shasum": "zhszOBWrEkArDXMjSiYJqwkgbv3gJgt65J2JAFASzl0=",
10
+ "shasum": "Fq01AvnFikO6119+4a1jL/90SX21Eo8kEOmR4D6ddqI=",
11
11
  "location": {
12
12
  "npm": {
13
13
  "filePath": "dist/bundle.js",