Skip to content
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

feat: extend sandbox with PoO request #996

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"database": "*",
"filepond": "^4.30.4",
"filepond-plugin-file-validate-type": "^1.2.8",
"neverthrow": "^6.2.1",
"neverthrow": "^8.0.0",
"ramda": "^0.28.0",
"sanitize-html": "^2.11.0",
"svelte-filepond": "^0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"filepond": "^4.30.4",
"filepond-plugin-file-validate-type": "^1.2.8",
"jsonwebtoken": "^9.0.2",
"neverthrow": "^6.2.1",
"neverthrow": "^8.0.0",
"ramda": "^0.28.0",
"sanitize-html": "^2.11.0",
"svelte-filepond": "^0.2.0",
Expand Down
1 change: 0 additions & 1 deletion apps/sandbox/src/data-request/PersonaDataCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export const PersonaDataCard = () => {
)
}
)}
;
<Box mt={2}>
<Checkbox
disabled={!enabled}
Expand Down
92 changes: 92 additions & 0 deletions apps/sandbox/src/one-time-data-request/AccountsProof.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import Box from '@mui/joy/Box'
import Checkbox from '@mui/joy/Checkbox'
import { Card } from '../components/Card'
import { Button, Input } from '@mui/joy'

export const AccountsProofCard = ({
state,
updateState
}: {
state: {
enabled: boolean
data: {
addresses: string[]
}
}
updateState: (state: {
enabled: boolean
data: {
addresses: string[]
}
}) => void
}) => {
const enabled = !!state.enabled
return (
<Card
title="Accounts Proof of Ownership"
side={
<Checkbox
checked={enabled}
onChange={(ev) => {
updateState({ ...state, enabled: ev.target.checked })
}}
/>
}
>
<Box
sx={{
p: 2,
display: 'grid',
gap: 2
}}
>
<Button
color="primary"
onClick={() => {
updateState({
...state,
data: {
addresses: [...state.data.addresses, '']
}
})
}}
>
Add
</Button>
{state.data.addresses.map((address, index) => (
<Box sx={{ display: 'flex', gap: 1 }} key={index}>
<Input
sx={{ width: '100%' }}
placeholder="account address"
value={address}
onChange={(ev) => {
const addresses = [...state.data.addresses]
addresses[index] = ev.target.value
updateState({
...state,
data: {
addresses
}
})
}}
/>
<Button
onClick={() => {
const addresses = [...state.data.addresses]
addresses.splice(index, 1)
updateState({
...state,
data: {
addresses
}
})
}}
>
x
</Button>
</Box>
))}
</Box>
</Card>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
OneTimeDataRequestBuilderItem
} from '@common/rdt'
import { useState } from 'react'
import { PersonaProofCard } from './PersonaProof'
import { AccountsProofCard } from './AccountsProof'
export const OneTimeDataRequestsPage = () => {
const [state, setState] = useState<{
accounts: {
Expand All @@ -32,6 +34,18 @@ export const OneTimeDataRequestsPage = () => {
phoneNumbers: boolean
}
}
personaProof: {
enabled: boolean
data: {
address: string
}
}
accountsProof: {
enabled: boolean
data: {
addresses: string[]
}
}
}>({
accounts: {
enabled: true,
Expand All @@ -47,14 +61,27 @@ export const OneTimeDataRequestsPage = () => {
emailAddresses: false,
phoneNumbers: false
}
},
personaProof: {
enabled: false,
data: {
address: ''
}
},
accountsProof: {
enabled: false,
data: {
addresses: []
}
}
})

return (
<Box
sx={{
display: 'grid',
gridTemplateColumns: 'minmax(160px, 300px) minmax(200px, 1fr)',
gridTemplateColumns:
'minmax(160px, 300px) minmax(300px, 500px) minmax(200px, 1fr)',
gap: 1
}}
>
Expand All @@ -77,6 +104,25 @@ export const OneTimeDataRequestsPage = () => {
}}
/>
</Box>
<Box
sx={{
display: 'grid',
gap: 1
}}
>
<PersonaProofCard
state={state.personaProof}
updateState={(personaProof) => {
setState((prev) => ({ ...prev, personaProof }))
}}
/>
<AccountsProofCard
state={state.accountsProof}
updateState={(accountsProof) => {
setState((prev) => ({ ...prev, accountsProof }))
}}
/>
</Box>
<Box>
<Sheet
variant="outlined"
Expand Down Expand Up @@ -124,6 +170,35 @@ export const OneTimeDataRequestsPage = () => {
dataRequest.push(personaDataRequest)
}

if (
state.personaProof.enabled ||
state.accountsProof.enabled
) {
let poo = OneTimeDataRequestBuilder.proofOfOwnership()
if (
state.personaProof.enabled &&
state.accountsProof.enabled
) {
dataRequest.push(
poo
.accounts(
state.accountsProof.data.addresses.filter(Boolean)
)
.identity(state.personaProof.data.address)
)
} else if (state.personaProof.enabled) {
dataRequest.push(
poo.identity(state.personaProof.data.address)
)
} else if (state.accountsProof.enabled) {
dataRequest.push(
poo.accounts(
state.accountsProof.data.addresses.filter(Boolean)
)
)
}
}

rdt.walletApi.sendOneTimeRequest(...dataRequest)
}}
sx={{ alignSelf: 'center', width: '150px' }}
Expand Down
49 changes: 49 additions & 0 deletions apps/sandbox/src/one-time-data-request/PersonaProof.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Box from '@mui/joy/Box'
import Checkbox from '@mui/joy/Checkbox'
import { Card } from '../components/Card'
import { Input } from '@mui/joy'

export const PersonaProofCard = ({
state,
updateState
}: {
state: {
enabled: boolean
data: {
address: string
}
}
updateState: (state: {
enabled: boolean
data: {
address: string
}
}) => void
}) => {
const enabled = !!state.enabled
return (
<Card
title="Persona Proof of Ownership"
side={
<Checkbox
checked={enabled}
onChange={(ev) => {
updateState({ ...state, enabled: ev.target.checked })
}}
/>
}
>
<Box sx={{ p: 2 }}>
<Input
placeholder="Identity address"
onChange={(event) => {
updateState({
...state,
data: { address: event.target.value.toString() }
})
}}
/>
</Box>
</Card>
)
}
13 changes: 11 additions & 2 deletions apps/sandbox/src/rdt/rdt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BehaviorSubject, tap } from 'rxjs'
import {
DataRequestBuilder,
EnvironmentModule,
GatewayModule,
LocalStorageModule,
RadixDappToolkit,
Expand Down Expand Up @@ -87,8 +88,15 @@ export const gatewayApi = GatewayApiClient({
applicationVersion
})

const environmentModule = EnvironmentModule()

const storageModule = LocalStorageModule(
`rdt:${dAppDefinitionAddress.value}:${networkId}`
`rdt:${dAppDefinitionAddress.value}:${networkId}`,
{
providers: {
environmentModule
}
}
)

const stateModule = StateModule({
Expand Down Expand Up @@ -116,7 +124,8 @@ const walletRequestModule = WalletRequestModule({
providers: {
stateModule,
storageModule,
gatewayModule
gatewayModule,
environmentModule
}
})

Expand Down
Loading
Loading