emblem-vault-sdk 1.3.2 → 1.4.1

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/docs/index.html CHANGED
@@ -16,7 +16,8 @@
16
16
  <h1>Testing Emblem Vault SDK in the Browser</h1>
17
17
  <script src="./bundle.js"></script>
18
18
  <script>
19
- const sdk = new EmblemVaultSDK('demo');
19
+ const sdk = new EmblemVaultSDK('demo');
20
+
20
21
  sdk.fetchCuratedContracts(false).then(curatedContracts => {
21
22
  window.curatedContracts = curatedContracts;
22
23
  generateDropdown(curatedContracts);
@@ -160,6 +161,19 @@
160
161
  </script>
161
162
 
162
163
 
164
+ <button id="connectButton" onclick="connectWeb3()">Connect to Web3</button>
165
+
166
+ <script>
167
+ async function connectWeb3() {
168
+ sdk.loadWeb3().then(async (web3) => {
169
+ console.log('Web3 loaded');
170
+ let accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
171
+ document.getElementById('ethAddress').value = accounts[0];
172
+ }).catch(error => {
173
+ console.error('Failed to load Web3:', error);
174
+ });
175
+ }
176
+ </script>
163
177
  <input type="text" id="ethAddress" placeholder="Enter ETH Address" oninput="localStorage.setItem('ethAddress', this.value)" value="">
164
178
 
165
179
  <input type="checkbox" id="hideNotMintableCheckbox" checked onchange="generateDropdown(window.curatedContracts)">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emblem-vault-sdk",
3
- "version": "1.3.2",
3
+ "version": "1.4.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -24,13 +24,14 @@
24
24
  "browserify": "^17.0.0",
25
25
  "jest": "^29.7.0",
26
26
  "jest-environment-jsdom": "^29.7.0",
27
+ "jest-puppeteer": "^9.0.2",
28
+ "puppeteer": "^21.6.1",
27
29
  "ts-jest": "^29.1.1",
28
30
  "tsify": "^5.0.2",
29
- "typescript": "^5.3.3",
30
- "jest-puppeteer": "^9.0.2",
31
- "puppeteer": "^21.6.1"
31
+ "typescript": "^5.3.3"
32
32
  },
33
33
  "dependencies": {
34
- "node-fetch": "^2.6.6"
34
+ "node-fetch": "^2.6.6",
35
+ "web3": "^4.4.0"
35
36
  }
36
37
  }
package/src/index.ts CHANGED
@@ -37,10 +37,10 @@ class EmblemVaultSDK {
37
37
 
38
38
  // ** Curated **
39
39
  //
40
- async fetchCuratedContracts(hideUnMintable: boolean = false): Promise<CuratedCollectionsResponse> {
40
+ async fetchCuratedContracts(hideUnMintable: boolean = false, overrideFunc: Function | boolean = false): Promise<CuratedCollectionsResponse> {
41
41
  let url = `${this.baseUrl}/curated`;
42
- let data = await fetchData(url, this.apiKey);
43
-
42
+ // Fetch using URL or override function
43
+ let data = typeof overrideFunc === 'function' ? await overrideFunc() : await fetchData(url, this.apiKey);
44
44
  // Filter out collections that are not mintable
45
45
  data = hideUnMintable? data.filter((collection: Collection) => collection.mintable): data;
46
46
 
@@ -50,7 +50,7 @@ class EmblemVaultSDK {
50
50
  .map((item: any) => {
51
51
  const template = generateTemplate(item);
52
52
  // Return a new object that combines the properties of the item and the template
53
- return { ...item, ...template };
53
+ return { ...item, ...template };
54
54
  });
55
55
  return data
56
56
  }
@@ -77,11 +77,40 @@ class EmblemVaultSDK {
77
77
  return vaults;
78
78
  }
79
79
 
80
+ // ** Web3 **
81
+ //
82
+ // Function to load web3 dynamically and attach it to the window object
83
+ async loadWeb3() {
84
+ try {
85
+ // Dynamically import the Web3 module
86
+ const { default: Web3 } = await import('web3');
87
+
88
+ // Check if MetaMask (window.ethereum) is available
89
+ if (window.ethereum) {
90
+
91
+ // Initialize Web3 with MetaMask's provider
92
+ const web3 = new Web3(window.ethereum);
93
+
94
+ // Attach Web3 to the window object
95
+ window.web3 = web3;
96
+
97
+ return web3;
98
+ } else {
99
+ console.error('MetaMask is not installed!');
100
+ }
101
+ } catch (error) {
102
+ console.error('Error loading Web3 or connecting to MetaMask', error);
103
+ }
104
+ }
105
+
106
+
80
107
  }
81
108
 
82
109
  declare global {
83
110
  interface Window {
84
111
  EmblemVaultSDK: any;
112
+ web3: any;
113
+ ethereum: any
85
114
  }
86
115
  }
87
116