Skip to content

Commit

Permalink
Merge pull request #298 from radixdlt/develop
Browse files Browse the repository at this point in the history
v2.2
  • Loading branch information
dawidsowardx authored Dec 16, 2024
2 parents 46fd40f + 783f1c4 commit 96752a3
Show file tree
Hide file tree
Showing 98 changed files with 5,640 additions and 3,149 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ name: Build
on:
push:
branches:
- '**'
- develop
- main
- release/**
pull_request:

jobs:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/connect-button-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Connect button CI/CD'
name: 'Connect Button Storybook'

on:
pull_request:
Expand All @@ -19,6 +19,7 @@ env:
jobs:

build_push_container:
if: ${{ (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy-pr')) || (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')) }}
permissions:
packages: write
id-token: write
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main
- next
- develop
- release/**
workflow_dispatch:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ yarn-error.log*

.envrc

examples/cdn/radix-dapp-toolkit.bundle.umd.cjs
examples/cdn/radix-dapp-toolkit.bundle.umd.js

# Editor directories and files
.vscode/*
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,26 @@
<a href="RADIX-SOFTWARE-EULA">
<img src="https://img.shields.io/badge/EULA-red" alt="eula" />
</a>
<a href="https://sonarcloud.io/project/overview?id=radix-dapp-toolkit">
<img src="https://img.shields.io/sonar/coverage/radix-dapp-toolkit?server=https%3A%2F%2Fsonarcloud.io" alt="coverage" />
</a>
<br/>
<a href="https://www.npmjs.com/@radixdlt/radix-dapp-toolkit">
<img src="https://img.shields.io/npm/v/@radixdlt/radix-dapp-toolkit.svg?logo=npm&logoColor=fff&label=NPM+package&color=limegreen" alt="RDT on NPM" />
<img src="https://img.shields.io/npm/v/@radixdlt/radix-dapp-toolkit.svg?logo=npm&logoColor=fff&label=NPM+package&color=limegreen" alt="NPM version" />
</a>
<a href="http://discord.gg/radixdlt">
<img src="https://img.shields.io/discord/417762285172555786.svg?logo=discord&logoColor=fff&label=Discord&color=7389d8" alt="Discord conversation" />
</a>
<a href="https://www.npmjs.com/@radixdlt/radix-dapp-toolkit">
<img src="https://img.shields.io/npm/dm/@radixdlt/radix-dapp-toolkit" alt="Discord conversation" />
<img src="https://img.shields.io/npm/dm/@radixdlt/radix-dapp-toolkit" alt="NPM downloads" />
</a>
</p>

<hr>

## How to start?

Install [Node.js] which includes [Node Package Manager][npm]. Use `create-radix-dapp` package - paste following command into your terminal and it will walk you through all required steps!
Install [Node.js] which includes [Node Package Manager][npm]. Use `create-radix-dapp` package - paste following command into your terminal and it will walk you through all required steps.

```bash
npx create-radix-dapp@latest
Expand Down
4 changes: 2 additions & 2 deletions examples/cdn/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<header><radix-connect-button /></header>
<div id="app"></div>

<script src="./radix-dapp-toolkit.bundle.umd.cjs"></script>
<script src="./radix-dapp-toolkit.bundle.umd.js"></script>
<script>
const rdt = window.RDT.RadixDappToolkit({
dAppDefinitionAddress:
Expand All @@ -25,7 +25,7 @@
applicationVersion: '1.0.0',
logger: window.RDT.Logger(1),
})
console.log(rdt);
console.log(rdt)
</script>
</body>
</html>
1 change: 1 addition & 0 deletions examples/simple-dapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://telegram.org/js/telegram-web-app.js"></script>
<title>Simple dApp</title>
</head>
<body>
Expand Down
183 changes: 164 additions & 19 deletions examples/simple-dapp/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ import {
DataRequestBuilder,
OneTimeDataRequestBuilder,
LocalStorageModule,
EnvironmentModule,
generateRolaChallenge,
SubintentRequestBuilder,
} from '@radixdlt/radix-dapp-toolkit'

const dAppDefinitionAddress = import.meta.env.VITE_DAPP_DEFINITION_ADDRESS
const widgetUrl = import.meta.env.VITE_WIDGET_DAPP_URL
const networkId = RadixNetwork.Stokenet
const storageModule = LocalStorageModule(
`rdt:${dAppDefinitionAddress}:${networkId}`,
{
providers: {
environmentModule: EnvironmentModule(),
},
},
)
const requestsStore = storageModule.getPartition('requests')
const sessionStore = storageModule.getPartition('sessions')
Expand All @@ -29,7 +35,79 @@ content.innerHTML = `
<button id="removeCb">Remove Connect Button</button>
<button id="addCb">Add Connect Button</button>
<div class="mt-25"><button id="one-time-request">Send one time request</button></div>
<div class="mt-25">
<button id="one-time-request">Send one time request</button>
</div>
<div class="mt-25">
<button id="proof-of-ownership-request">Send proof of ownership request</button>
</div>
<hr/>
<textarea id="subintentManifest" cols="50" rows="10">ASSERT_WORKTOP_RESOURCES_INCLUDE
Map<Address, Enum>(
Address("resource_tdx_2_1t5cjs290gd2v4pm5rys02ty372zapefjejqm3w6ktcxj9aw3e7t4jw") => Enum<ResourceConstraint::General>(
Tuple(
Array<NonFungibleLocalId>(),
Enum<LowerBound::NonZero>(),
Enum<UpperBound::Unbounded>(),
Enum<AllowedIds::Any>()
)
),
Address("resource_tdx_2_1t5dapa24l4xvwqtqe2jrdphtn7ga46gw67wr9fwn4gp532myfjqpck") => Enum<ResourceConstraint::General>(
Tuple(
Array<NonFungibleLocalId>(),
Enum<LowerBound::Inclusive>(Decimal("6")),
Enum<UpperBound::Unbounded>(),
Enum<AllowedIds::Any>()
)
),
Address("resource_tdx_2_1th9k30slgu9uekfu42llstgcq80dx8d59hxgexe5hdaqzyp8etc2dv") => Enum<ResourceConstraint::General>(
Tuple(
Array<NonFungibleLocalId>(),
Enum<LowerBound::NonZero>(),
Enum<UpperBound::Inclusive>(Decimal("10")),
Enum<AllowedIds::Any>()
)
),
Address("resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc") => Enum<ResourceConstraint::General>(
Tuple(
Array<NonFungibleLocalId>(),
Enum<LowerBound::Inclusive>(Decimal("2")),
Enum<UpperBound::Inclusive>(Decimal("5")),
Enum<AllowedIds::Any>()
)
),
Address("resource_tdx_2_1thjlp88pc28eyfg3f2alq8zkggnr273j0saye4nj70vfnga6ldy7ru") => Enum<ResourceConstraint::General>(
Tuple(
Array<NonFungibleLocalId>(),
Enum<LowerBound::Inclusive>(Decimal("3")),
Enum<UpperBound::Inclusive>(Decimal("3")),
Enum<AllowedIds::Any>()
)
),
)
;
CALL_METHOD
Address("account_tdx_2_12xuly5lqj0vzqctehs7a3c9wdjduh5sjelp2ywydw2ur4v3kjwlaly")
"deposit_batch"
Expression("ENTIRE_WORKTOP")
;
YIELD_TO_PARENT;</textarea>
<div class="mt-25">
<label>
<input checked type="radio" name="option" value="secondsAfterSignature"> afterDelay
</label>
<label>
<input type="radio" name="option" value="atTime"> atTime
</label>
</div>
<input id="subintentExpirationValue" type="text" value="3600"/>
<button id="subintent">Send Pre Authorization</button>
<hr/>
<pre id="sessions"></pre>
<pre id="requests"></pre>
Expand All @@ -44,12 +122,36 @@ const sendTxButton = document.getElementById('sendTx')!
const sessions = document.getElementById('sessions')!
const removeCb = document.getElementById('removeCb')!
const addCb = document.getElementById('addCb')!
const subintentButton = document.getElementById('subintent')!
const subintentManifest = document.getElementById(
'subintentManifest',
)! as HTMLTextAreaElement
const subintentExpirationValue = document.getElementById(
'subintentExpirationValue',
)! as HTMLInputElement
const requests = document.getElementById('requests')!
const logs = document.getElementById('logs')!
const state = document.getElementById('state')!
const gatewayConfig = document.getElementById('gatewayConfig')!
const gatewayStatus = document.getElementById('gatewayStatus')!
const oneTimeRequest = document.getElementById('one-time-request')!
const proofOfOwnershipRequest = document.getElementById(
'proof-of-ownership-request',
)!

let subintentExpiration: 'afterDelay' | 'atTime' = 'afterDelay'

document.querySelectorAll('input[name="option"]').forEach((radio) => {
radio.addEventListener('change', () => {
const selectedOption = document.querySelector(
'input[name="option"]:checked',
) as HTMLInputElement
if (selectedOption) {
console.log(`Selected value: ${selectedOption.value}`)
subintentExpiration = selectedOption.value as 'afterDelay' | 'atTime'
}
})
})

const logger = Logger()

Expand All @@ -68,6 +170,21 @@ removeCb.onclick = () => {
document.querySelector('radix-connect-button')?.remove()
}

subintentButton.onclick = async () => {
console.log(subintentManifest.value)
console.log(subintentExpirationValue.value)
const result = await dAppToolkit.walletApi.sendPreAuthorizationRequest(
SubintentRequestBuilder()
.manifest(subintentManifest.value)
.setExpiration(
subintentExpiration,
parseInt(subintentExpirationValue.value as string),
),
)

console.log('result', result.isOk() && result.value)
}

addCb.onclick = () => {
const connectButton = document.createElement('radix-connect-button')
const header = document.querySelector('header')!
Expand All @@ -76,15 +193,16 @@ addCb.onclick = () => {
const dAppToolkit = RadixDappToolkit({
dAppDefinitionAddress,
networkId,
featureFlags: ['ExperimentalMobileSupport'],
logger,
// logger,
})

const gatewayApi = GatewayApiClient.initialize(
dAppToolkit.gatewayApi.clientConfig,
)

dAppToolkit.walletApi.provideChallengeGenerator(async () => generateRolaChallenge())
dAppToolkit.walletApi.provideChallengeGenerator(async () =>
generateRolaChallenge(),
)

dAppToolkit.walletApi.setRequestData(
DataRequestBuilder.persona().withProof(),
Expand All @@ -105,25 +223,52 @@ resetButton.onclick = () => {
window.location.replace(window.location.origin)
}

sendTxButton.onclick = () => {
dAppToolkit.walletApi.sendTransaction({
transactionManifest: `CALL_METHOD
Address("component_tdx_2_1cptxxxxxxxxxfaucetxxxxxxxxx000527798379xxxxxxxxxyulkzl")
"free"
;
CALL_METHOD
Address("account_tdx_2_12yfw30hdc445j4lnepw7dmrkjcqcswsrxlff5r07mrjq9f8mnnn2r5")
"try_deposit_batch_or_abort"
Expression("ENTIRE_WORKTOP")
Enum<0u8>()
;`,
sendTxButton.onclick = async () => {
const res = await dAppToolkit.walletApi.sendTransaction({
transactionManifest: `
CALL_METHOD
Address("component_tdx_2_1cptxxxxxxxxxfaucetxxxxxxxxx000527798379xxxxxxxxxyulkzl")
"free"
;
CALL_METHOD
Address("account_tdx_2_1299trm47s3x648jemhu3lfm4d6gt73289rd9s2hpdjm3tp5pdwq4m5")
"try_deposit_batch_or_abort"
Expression("ENTIRE_WORKTOP")
Enum<0u8>()
;`,
})
console.log('send tx result', res)
}

oneTimeRequest.onclick = async () => {
const res = await dAppToolkit.walletApi.sendOneTimeRequest(
OneTimeDataRequestBuilder.accounts().exactly(1),
)

console.log('one time request result', res)
}

oneTimeRequest.onclick = () => {
dAppToolkit.walletApi.sendOneTimeRequest(
proofOfOwnershipRequest.onclick = async () => {
const connectedAccounts =
dAppToolkit.walletApi.getWalletData()?.accounts ?? []
const connectedPersona = dAppToolkit.walletApi.getWalletData()?.persona

if (connectedAccounts.length === 0 || !connectedPersona) {
alert('No connected account or persona')
return
}

const result = await dAppToolkit.walletApi.sendOneTimeRequest(
OneTimeDataRequestBuilder.accounts().exactly(1),
OneTimeDataRequestBuilder.proofOfOwnership()
.accounts(connectedAccounts.map((account) => account.address))
.identity(connectedPersona.identityAddress),
)

console.log(result)

alert(`Result is ok: ${result.isOk()}`)
}

setInterval(() => {
Expand Down
Loading

0 comments on commit 96752a3

Please sign in to comment.