-
Notifications
You must be signed in to change notification settings - Fork 63
[LW-10152] Setup preact webpack #1204
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
Closed
VanessaPC
wants to merge
1
commit into
feat/dapp-connector-client-poc
from
feat/lw-10152-setup-preact-webpack
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains hidden or 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,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta name="color-scheme" content="light dark" /> | ||
<title>Dapp connector</title> | ||
<script> | ||
window.global ||= window; | ||
</script> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> |
This file contains hidden or 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,53 @@ | ||
{ | ||
"name": "@cardano-sdk/dapp-connector-preact", | ||
"scripts": { | ||
"dev": "webpack serve --mode development --open", | ||
"build": "webpack --mode production", | ||
"lint": "eslint --ignore-path ../../../../../.eslintignore \"**/*.ts\" \"**/*.tsx\"" | ||
}, | ||
"dependencies": { | ||
"@cardano-sdk/cardano-services-client": "workspace:~", | ||
"@cardano-sdk/core": "workspace:~", | ||
"@cardano-sdk/crypto": "workspace:~", | ||
"@cardano-sdk/dapp-connector-client": "workspace:~", | ||
"@cardano-sdk/tx-construction": "workspace:~", | ||
"@cardano-sdk/util": "workspace:~", | ||
"@cardano-sdk/util-dev": "workspace:~", | ||
"@cardano-sdk/util-rxjs": "workspace:~", | ||
"@cardano-sdk/wallet": "workspace:~", | ||
"buffer": "^6.0.3", | ||
"copy-webpack-plugin": "^12.0.2", | ||
"crypto-browserify": "^3.12.0", | ||
"libsodium-wrappers-sumo": "^0.7.5", | ||
"preact": "^10.13.1", | ||
"preact-iso": "^2.6.2", | ||
"preact-render-to-string": "^6.4.1", | ||
"preact-router": "^4.1.2", | ||
"rollup-plugin-polyfill-node": "^0.13.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.24.4", | ||
"@babel/plugin-transform-react-jsx": "^7.23.4", | ||
"@babel/plugin-transform-runtime": "^7.24.3", | ||
"@babel/preset-env": "^7.24.4", | ||
"@babel/preset-react": "^7.24.1", | ||
"@babel/preset-typescript": "^7.24.1", | ||
"@preact/preset-vite": "^2.5.0", | ||
"babel-loader": "^9.1.3", | ||
"css-loader": "^7.1.0", | ||
"dotenv": "^16.4.5", | ||
"eslint": "^8.57.0", | ||
"eslint-config-preact": "^1.3.0", | ||
"html-webpack-plugin": "^5.6.0", | ||
"source-map-loader": "^5.0.0", | ||
"style-loader": "^4.0.0", | ||
"ts-loader": "^9.5.1", | ||
"typescript": "^5.4.3", | ||
"vite": "^4.3.2", | ||
"vite-compatible-readable-stream": "^3.6.1", | ||
"vite-plugin-node-polyfills": "^0.21.0", | ||
"webpack": "^5.91.0", | ||
"webpack-cli": "^5.1.4", | ||
"webpack-dev-server": "^5.0.4" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions
33
packages/dapp-connector-preact/src/components/connect/index.tsx
This file contains hidden or 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,33 @@ | ||
import { ConnectWalletDependencies, connectWallet, listWallets } from '@cardano-sdk/dapp-connector-client'; | ||
import { ObservableWallet } from '@cardano-sdk/wallet'; | ||
import { combineLatest, switchMap, tap } from 'rxjs'; | ||
import { logger } from '@cardano-sdk/util-dev'; | ||
|
||
import { connectWalletDependencies } from '../../constants'; | ||
import { connectorStore } from '../../state/store'; | ||
|
||
export type OnWalletConnected = (wallet: ObservableWallet) => void; | ||
|
||
const connectLace = (dependencies: ConnectWalletDependencies) => { | ||
const wallets = listWallets({ logger }); | ||
const lace = wallets.find(({ id }) => id === 'lace'); | ||
if (!lace) { | ||
return; | ||
} | ||
|
||
return connectWallet(lace, dependencies) | ||
.pipe( | ||
tap((connected) => { | ||
connectorStore.setConnectedWallet(connected.wallet); | ||
}), | ||
switchMap(({ wallet }) => combineLatest([wallet.addresses$, wallet.balance.utxo.available$])), | ||
tap(([addresses, balance]) => { | ||
connectorStore.setAddressesAndBalances(addresses, balance); | ||
}) | ||
) | ||
.subscribe({ | ||
error: (error) => console.error(error) | ||
}); | ||
}; | ||
|
||
export const Connect = () => <button onClick={() => connectLace(connectWalletDependencies)}>Connect wallet</button>; |
4 changes: 4 additions & 0 deletions
4
packages/dapp-connector-preact/src/components/dashboard/dashboard.css
This file contains hidden or 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,4 @@ | ||
.dashboard-container { | ||
display: flex; | ||
justify-content: space-between; | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/dapp-connector-preact/src/components/dashboard/index.tsx
This file contains hidden or 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,9 @@ | ||
import './dashboard.css'; | ||
import { Logs, WalletActions } from '..'; | ||
|
||
export const Dashboard = () => ( | ||
<div class="dashboard-container"> | ||
<WalletActions /> | ||
<Logs /> | ||
</div> | ||
); |
18 changes: 18 additions & 0 deletions
18
packages/dapp-connector-preact/src/components/header/index.tsx
This file contains hidden or 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,18 @@ | ||
import { useLocation } from 'preact-iso'; | ||
|
||
export const Header = () => { | ||
const { url } = useLocation(); | ||
|
||
return ( | ||
<header> | ||
<nav> | ||
<a href="/" className={url === '/' ? 'active' : undefined}> | ||
Home | ||
</a> | ||
<a href="/404" className={url === '/404' ? 'active' : undefined}> | ||
404 | ||
</a> | ||
</nav> | ||
</header> | ||
); | ||
}; |
This file contains hidden or 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,5 @@ | ||
export { Connect, type OnWalletConnected } from './connect'; | ||
export { Logs } from './wallet-logs'; | ||
export { WalletActions } from './wallet-actions'; | ||
export { Dashboard } from './dashboard'; | ||
export { Header } from './header'; |
92 changes: 92 additions & 0 deletions
92
packages/dapp-connector-preact/src/components/wallet-actions/index.tsx
This file contains hidden or 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,92 @@ | ||
import { Store, connectorStore } from '../../state/store'; | ||
import { sendCoins, sendSeveralAssets, singleDelegation, singleUndelegation } from '../../features'; | ||
import { useEffect, useState } from 'preact/hooks'; | ||
|
||
import './wallet-actions.css'; | ||
|
||
export const WalletActions = () => { | ||
const [storeState, setStoreState] = useState<Store>(connectorStore.initialState); | ||
|
||
useEffect(() => { | ||
const subscription = connectorStore.subscribe(setStoreState); | ||
connectorStore.init(); | ||
|
||
return () => { | ||
subscription.unsubscribe(); | ||
}; | ||
}, []); | ||
|
||
if (!storeState.wallet) { | ||
return null; | ||
} | ||
|
||
const handleSendCoins = async () => { | ||
if (!storeState.wallet) { | ||
return null; | ||
} | ||
|
||
const { hash, txId } = await sendCoins({ connectedWallet: storeState.wallet }); | ||
connectorStore.log({ | ||
hash, | ||
title: 'Send coins', | ||
txId | ||
}); | ||
}; | ||
|
||
const handleSendSeveralAssets = async () => { | ||
if (!storeState.wallet) { | ||
return null; | ||
} | ||
|
||
const { hash, txId } = await sendSeveralAssets({ connectedWallet: storeState.wallet }); | ||
connectorStore.log({ | ||
hash, | ||
title: 'Send several assets', | ||
txId | ||
}); | ||
}; | ||
|
||
const handleSingleDelegation = async () => { | ||
if (!storeState.wallet) { | ||
return null; | ||
} | ||
|
||
const { hash, txId } = await singleDelegation({ connectedWallet: storeState.wallet }); | ||
connectorStore.log({ | ||
hash, | ||
title: 'Single delegation', | ||
txId | ||
}); | ||
}; | ||
|
||
const handleSingleUndelegation = async () => { | ||
if (!storeState.wallet) { | ||
return null; | ||
} | ||
|
||
const { hash, txId } = await singleUndelegation({ connectedWallet: storeState.wallet }); | ||
connectorStore.log({ | ||
hash, | ||
title: 'Single undelegation', | ||
txId | ||
}); | ||
}; | ||
|
||
return ( | ||
<div class="actions-container"> | ||
<h3>Wallet actions</h3> | ||
<button class="wallet-button" onClick={() => handleSendCoins()}> | ||
Send coins | ||
</button> | ||
<button class="wallet-button" onClick={() => handleSendSeveralAssets()}> | ||
Send several assets | ||
</button> | ||
<button class="wallet-button" onClick={() => handleSingleDelegation()}> | ||
Single delegation | ||
</button> | ||
<button class="wallet-button" onClick={() => handleSingleUndelegation()}> | ||
Single undelegation | ||
</button> | ||
</div> | ||
); | ||
}; |
10 changes: 10 additions & 0 deletions
10
packages/dapp-connector-preact/src/components/wallet-actions/wallet-actions.css
This file contains hidden or 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,10 @@ | ||
.actions-container { | ||
display: flex; | ||
flex-direction: column; | ||
width: 300px; | ||
padding: 20px; | ||
} | ||
|
||
.wallet-button { | ||
margin: 10px 20px; | ||
} |
47 changes: 47 additions & 0 deletions
47
packages/dapp-connector-preact/src/components/wallet-logs/index.tsx
This file contains hidden or 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,47 @@ | ||
import { Store, connectorStore } from '../../state/store'; | ||
import { useEffect, useState } from 'preact/hooks'; | ||
|
||
import './logs.css'; | ||
|
||
export const Logs = () => { | ||
const [storeState, setStoreState] = useState<Store>(connectorStore.initialState); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would make this into a hook to be used in other places. |
||
|
||
useEffect(() => { | ||
const subscription = connectorStore.subscribe(setStoreState); | ||
connectorStore.init(); | ||
|
||
return () => { | ||
subscription.unsubscribe(); | ||
}; | ||
}, []); | ||
|
||
if (!storeState.wallet || !storeState.addresses || !storeState.balance) { | ||
return null; | ||
} | ||
|
||
const getAddresses = () => storeState.addresses?.map((a) => <p>{a.address}</p>); | ||
|
||
return ( | ||
<div class="logs-container"> | ||
<h3>Logs</h3> | ||
<div> | ||
<h4>Balance: </h4> <p>{storeState?.balance?.coins}</p> | ||
<h4>Addresses: </h4> {getAddresses()} | ||
</div> | ||
<div> | ||
{storeState.log.map((entry) => ( | ||
<> | ||
<h4>{entry.title}</h4> | ||
<p> | ||
<h5>hash:</h5> | ||
{entry.hash} | ||
</p> | ||
<p> | ||
<h5>tx ID:</h5> {entry.txId} | ||
</p> | ||
</> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; |
6 changes: 6 additions & 0 deletions
6
packages/dapp-connector-preact/src/components/wallet-logs/logs.css
This file contains hidden or 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,6 @@ | ||
.logs-container { | ||
display: flex; | ||
flex-direction: column; | ||
width: auto; | ||
padding: 20px; | ||
} |
This file contains hidden or 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 @@ | ||
export * from './wallet'; |
This file contains hidden or 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,25 @@ | ||
import { ConnectWalletDependencies } from '@cardano-sdk/dapp-connector-client'; | ||
import { | ||
assetInfoHttpProvider, | ||
chainHistoryHttpProvider, | ||
handleHttpProvider, | ||
networkInfoHttpProvider, | ||
rewardsHttpProvider, | ||
stakePoolHttpProvider | ||
} from '@cardano-sdk/cardano-services-client'; | ||
import { logger } from '@cardano-sdk/util-dev'; | ||
|
||
const httpProviderDependencies = { | ||
baseUrl: 'https://dev-preprod.lw.iog.io', | ||
logger | ||
}; | ||
|
||
export const connectWalletDependencies: ConnectWalletDependencies = { | ||
assetProvider: assetInfoHttpProvider(httpProviderDependencies), | ||
chainHistoryProvider: chainHistoryHttpProvider(httpProviderDependencies), | ||
handleProvider: handleHttpProvider(httpProviderDependencies), | ||
logger, | ||
networkInfoProvider: networkInfoHttpProvider(httpProviderDependencies), | ||
rewardsProvider: rewardsHttpProvider(httpProviderDependencies), | ||
stakePoolProvider: stakePoolHttpProvider(httpProviderDependencies) | ||
}; |
This file contains hidden or 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,4 @@ | ||
export { sendCoins } from './sendCoins'; | ||
export { sendSeveralAssets } from './sendSeveralAssets'; | ||
export { singleDelegation } from './singleDelegation'; | ||
export { singleUndelegation } from './singleUndelegation'; |
This file contains hidden or 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,17 @@ | ||
import { ObservableWallet } from '@cardano-sdk/wallet'; | ||
import { inspectAndSignTx } from '../utils'; | ||
|
||
export const sendCoins = async ({ | ||
connectedWallet | ||
}: { | ||
connectedWallet: ObservableWallet; | ||
}): Promise<{ hash: string; txId: string }> => { | ||
const builder = connectedWallet.createTxBuilder(); | ||
const output = await builder.buildOutput().handle('rhys').coin(10_000_000n).build(); | ||
const builtTx = builder.addOutput(output).build(); | ||
|
||
return new Promise(async (resolve) => { | ||
const { hash, txId } = await inspectAndSignTx({ builtTx, connectedWallet }); | ||
resolve({ hash, txId }); | ||
}); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like there are 4 (or even 8?) spaces intentation here, lets change it to our default of 2?