Skip to content

Commit

Permalink
feat!: v2 init
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This contains breaking changes
  • Loading branch information
dawidsowardx committed Apr 22, 2024
1 parent 2740825 commit 827db57
Show file tree
Hide file tree
Showing 205 changed files with 67,904 additions and 11,436 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
- name: Use Node.js
uses: RDXWorks-actions/setup-node@main
with:
node-version: '18.x'
node-version: '20.x'

- name: Authenticate with private NPM package
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPMJS_TOKEN }}" > ~/.npmrc
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ jobs:
- name: Setup Node.js
uses: RDXWorks-actions/setup-node@main
with:
node-version: '18.x'
node-version: '20.x'
- name: Authenticate with private NPM package
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPMJS_TOKEN }}" > ~/.npmrc
- name: Install dependencies
run: npm ci
- name: Prepare
run: npm run build
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPMJS_TOKEN }}
run: |
cd packages/dapp-toolkit
npx semantic-release | tee out
echo "RELEASE_VERSION=$(grep 'Created tag ' out | awk -F 'Created tag ' '{print $2}')" >> $GITHUB_ENV
Expand Down
36 changes: 33 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,41 @@ yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

# Dependencies
node_modules
.pnp
.pnp.js

# Local env files
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Turbo
.turbo

# Vercel
.vercel

# Build Outputs
.next/
out/
build
dist
types
dist-ssr
*.local


# Debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Misc
.DS_Store
*.pem

.envrc

# Editor directories and files
.vscode/*
Expand Down
7 changes: 4 additions & 3 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = {
'style',
'test',
'major',
],
],
},
'code'
]
]
}
}
10 changes: 0 additions & 10 deletions examples/index.html

This file was deleted.

34 changes: 0 additions & 34 deletions examples/main.js

This file was deleted.

26 changes: 26 additions & 0 deletions examples/simple-dapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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?

.sst
14 changes: 14 additions & 0 deletions examples/simple-dapp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Simple dApp</title>
</head>
<body>
<header><radix-connect-button /></header>
<div id="app"></div>

<script type="module" src="/src/main.ts"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions examples/simple-dapp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "simple-dapp",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite --host",
"build": "tsc && vite build",
"preview": "vite preview",
"deploy": "sst deploy"
},
"dependencies": {
"@radixdlt/radix-dapp-toolkit": "*"
},
"devDependencies": {
"sst": "^2.41.3",
"typescript": "^5.2.2",
"vite": "^5.1.6",
"vite-plugin-ngrok": "^1.0.0"
}
}
5 changes: 5 additions & 0 deletions examples/simple-dapp/public/.well-known/radix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dApps": [
{}
]
}
122 changes: 122 additions & 0 deletions examples/simple-dapp/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import './style.css'
import {
RadixDappToolkit,
RadixNetwork,
LocalStorageClient,
Logger,
RequestItemClient,
ConnectorExtensionClient,
DataRequestBuilder,
} from '@radixdlt/radix-dapp-toolkit'

const dAppDefinitionAddress = import.meta.env.VITE_DAPP_DEFINITION_ADDRESS
const networkId = RadixNetwork.Stokenet
const storageClient = LocalStorageClient(
`rdt:${dAppDefinitionAddress}:${networkId}`,
)
const requestsStore = storageClient.getPartition('requests')
const sessionStore = storageClient.getPartition('sessions')
const identityStore = storageClient.getPartition('identities')
const stateStore = storageClient.getPartition('state')

const content = document.getElementById('app')!

content.innerHTML = `
<button id="reset">Reset</button>
<pre id="sessions"></pre>
<pre id="keyPairs"></pre>
<pre id="walletResponse"></pre>
<pre id="requests"></pre>
<pre id="state"></pre>
<pre id="device"></pre>
<pre id="logs"></pre>
`
const resetButton = document.getElementById('reset')!
const sessions = document.getElementById('sessions')!
const keyPairs = document.getElementById('keyPairs')!
const requests = document.getElementById('requests')!
const walletResponse = document.getElementById('walletResponse')!
const device = document.getElementById('device')!
const logs = document.getElementById('logs')!
const state = document.getElementById('state')!

const logger = Logger()

logger.attachTransport((logObj) => {
const { _meta, ...rest } = logObj
logs.innerHTML = `${logs.innerHTML}
[${_meta.name}]
${JSON.stringify(rest, null, 2)}`
})

const requestItemClient = RequestItemClient({
logger,
providers: { storageClient: storageClient.getPartition('requests') },
})

const dAppToolkit = RadixDappToolkit({
dAppDefinitionAddress,
networkId,
enableMobile: true,
providers: {
storageClient,
requestItemClient,
transports: [
ConnectorExtensionClient({ logger, providers: { requestItemClient } }),
],
},
logger,
})

dAppToolkit.walletApi.provideChallengeGenerator(async () =>
[...window.crypto.getRandomValues(new Uint8Array(32))]
.map((x) => x.toString(16).padStart(2, '0'))
.join(''),
)

dAppToolkit.walletApi.setRequestData(DataRequestBuilder.persona().withProof())

resetButton.onclick = () => {
sessionStore.clear()
requestsStore.clear()
stateStore.clear()
identityStore.clear()
window.location.hash = ``
window.location.replace(window.location.origin)
}

setInterval(() => {
requestsStore.getState().map((value: any) => {
requests.innerHTML = JSON.stringify({ requests: value ?? {} }, null, 2)
})
stateStore.getState().map((value: any) => {
state.innerHTML = JSON.stringify({ state: value ?? {} }, null, 2)
})
sessionStore.getItemList().map((value: any) => {
sessions.innerHTML = JSON.stringify({ sessions: value }, null, 2)
})
// storageClient.getPartition('identities')
// .getState((state) => {
// keyPairs.innerHTML = JSON.stringify(state, null, 2)
// debugger
// })
// .map((items) => {
// keyPairs.innerHTML = JSON.stringify(items, null, 2)
// })
// storageClient
// .getData<
// Record<string, { createdAt: number; status: string }>
// >(`rdt:${dAppDefinitionAddress}:${networkId}:sessions`)
// .map((items) => {
// sessions.innerHTML = JSON.stringify({ sessions: items }, null, 2)
// })
// const url = new URL(window.location.href)
// const entries = Object.fromEntries([...url.searchParams.entries()])
// walletResponse.innerHTML = JSON.stringify({ walletResponse: entries }, null, 2)
// device.innerHTML = JSON.stringify(
// { device: navigator.userAgent, isAndroid: navigator.userAgent.includes('Android') },
// null,
// 2
// )
}, 1000)
5 changes: 5 additions & 0 deletions examples/simple-dapp/src/sst-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="vite/client" />
interface ImportMetaEnv {}
interface ImportMeta {
readonly env: ImportMetaEnv
}
Loading

0 comments on commit 827db57

Please sign in to comment.