-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: appkit packages cdn workaround (#3046)
- Loading branch information
1 parent
30e2ee5
commit 3b3b124
Showing
14 changed files
with
297 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
'@reown/appkit-scaffold-ui': patch | ||
'@reown/appkit-cdn': patch | ||
'@apps/demo': patch | ||
'@apps/gallery': patch | ||
'@apps/laboratory': patch | ||
'@reown/appkit-adapter-ethers': patch | ||
'@reown/appkit-adapter-ethers5': patch | ||
'@reown/appkit-adapter-polkadot': patch | ||
'@reown/appkit-adapter-solana': patch | ||
'@reown/appkit-adapter-wagmi': patch | ||
'@reown/appkit': patch | ||
'@reown/appkit-utils': patch | ||
'@reown/appkit-common': patch | ||
'@reown/appkit-core': patch | ||
'@reown/appkit-experimental': patch | ||
'@reown/appkit-polyfills': patch | ||
'@reown/appkit-siwe': patch | ||
'@reown/appkit-ui': patch | ||
'@reown/appkit-wallet': patch | ||
--- | ||
|
||
Refactor CDN package to properly export our modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>AppKit CDN Example</title> | ||
</head> | ||
|
||
<body> | ||
<h1>AppKit CDN Example</h1> | ||
<div style="display: flex; gap: 16px; margin-bottom: 16px"> | ||
<w3m-button></w3m-button> | ||
<w3m-network-button></w3m-network-button> | ||
</div> | ||
<div style="display: flex; gap: 16px"> | ||
<button id="open-appkit">Open AppKit</button> | ||
<button id="open-appkit-networks">Open AppKit Networks</button> | ||
</div> | ||
|
||
<!-- Load the CDN scripts --> | ||
<script src="https://cdn.jsdelivr.net/npm/@reown/appkit-cdn@1.1.0/dist/appkit.js"></script> | ||
<script> | ||
window.onerror = function (message, source, lineno, colno, error) { | ||
console.error('Error while loading document:', error, message, source, lineno, colno) | ||
} | ||
// Check if AppKit is loaded | ||
console.info('AppKit loaded') | ||
</script> | ||
<!-- Load our main script --> | ||
<script src="./main.js" type="module"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Since we're using the CDN, we can access AppKit globals directly | ||
const createAppKit = window.AppKit.createAppKit | ||
const appKitNetworks = window.AppKit.networks | ||
const WagmiAdapter = window.AppKit.WagmiAdapter | ||
const SolanaAdapter = window.AppKit.SolanaAdapter | ||
|
||
if (!AppKit || !AppKit.createAppKit) { | ||
throw new Error('AppKit or createAppKit not found on window object') | ||
} else { | ||
const projectId = '3bdbc796b351092d40d5d08e987f4eca' // Replace with your actual project ID | ||
const networks = [appKitNetworks.mainnet, appKitNetworks.polygon, appKitNetworks.base] | ||
|
||
try { | ||
const wagmiAdapter = new AppKit.WagmiAdapter({ | ||
projectId, | ||
networks | ||
}) | ||
|
||
// 3. Create modal | ||
const modal = AppKit.createAppKit({ | ||
adapters: [wagmiAdapter], | ||
networks, | ||
projectId, | ||
metadata: { | ||
name: 'Html CDN Example', | ||
description: 'Html CDN Example using local server', | ||
url: 'https://reown.com/appkit', | ||
icons: ['https://avatars.githubusercontent.com/u/37784886'] | ||
}, | ||
networks: [], | ||
themeMode: 'light' | ||
}) | ||
|
||
// 4. Trigger modal programmatically | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const openConnectModalBtn = document.getElementById('open-appkit') | ||
const openNetworkModalBtn = document.getElementById('open-appkit-networks') | ||
|
||
if (openConnectModalBtn && openNetworkModalBtn) { | ||
openConnectModalBtn.addEventListener('click', () => { | ||
modal.open() | ||
}) | ||
openNetworkModalBtn.addEventListener('click', () => { | ||
modal.open({ view: 'Networks' }) | ||
}) | ||
} | ||
}) | ||
} catch (error) { | ||
console.error('Error creating or using modal:', error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "@examples/html-wagmi-cdn", | ||
"private": true, | ||
"version": "1.0.6", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
}, | ||
"devDependencies": { | ||
"vite": "5.2.11" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
server: { | ||
open: true, | ||
port: 3000 | ||
}, | ||
optimizeDeps: { | ||
exclude: ['@reown/appkit-cdn'] | ||
}, | ||
build: { | ||
commonjsOptions: { | ||
include: [] | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Due to some limitations on exporting multiple modules with UMD, we needed to export all of our modules in this file. | ||
* For now exporting only Wagmi and Solana adapters. Until we found a better workaround and need other adapters, we can keep it this way. | ||
*/ | ||
import '@reown/appkit-polyfills' | ||
import { createAppKit } from '@reown/appkit' | ||
import { WagmiAdapter } from '@reown/appkit-adapter-wagmi' | ||
import { SolanaAdapter } from '@reown/appkit-adapter-solana' | ||
import * as AppKitNetworks from '@reown/appkit/networks' | ||
|
||
const networks = AppKitNetworks | ||
|
||
export { createAppKit, networks, WagmiAdapter, SolanaAdapter } | ||
|
||
declare global { | ||
interface Window { | ||
AppKit: { | ||
createAppKit: typeof createAppKit | ||
WagmiAdapter: typeof WagmiAdapter | ||
SolanaAdapter: typeof SolanaAdapter | ||
networks: typeof AppKitNetworks | ||
} | ||
} | ||
} | ||
|
||
// Assign to window.AppKit | ||
if (typeof window !== 'undefined') { | ||
window.AppKit = { | ||
createAppKit, | ||
WagmiAdapter, | ||
SolanaAdapter, | ||
networks: AppKitNetworks | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.