Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
poolsar42 committed Jun 6, 2023
1 parent d9bdb9a commit c57c6da
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
23 changes: 14 additions & 9 deletions apps/passport/app/routes/authorize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ import { ThemeContext } from '@proofzero/design-system/src/contexts/theme'
import { AuthenticationScreenDefaults } from '@proofzero/design-system/src/templates/authentication/Authentication'
import { Helmet } from 'react-helmet'
import { getRGBColor } from '@proofzero/design-system/src/helpers'
import { AddressURNSpace, type AddressURN } from '@proofzero/urns/address'
import { AddressURNSpace } from '@proofzero/urns/address'
import type { DropdownSelectListItem } from '@proofzero/design-system/src/atoms/dropdown/DropdownSelectList'

export type UserProfile = {
displayName: string
Expand Down Expand Up @@ -421,19 +422,19 @@ export default function Authorize() {

const [persona] = useState<PersonaData>(personaData!)

const [selectedEmail, setSelectedEmail] = useState<AddressURN | undefined>(
const [selectedEmail, setSelectedEmail] = useState<DropdownSelectListItem | undefined>(
() => {
let selected
if (connectedEmails && connectedEmails.length)
selected = connectedEmails.find(email => email.selected)
return selected?.value as AddressURN
return selected
}
)
const [selectedConnectedAccounts, setSelectedConnectedAccounts] = useState<
Array<AddressURN | AuthorizationControlSelection>
Array<DropdownSelectListItem | AuthorizationControlSelection>
>([])
const [selectedSCWallets, setSelectedSCWallets] = useState<
Array<AddressURN | AuthorizationControlSelection>
Array<DropdownSelectListItem | AuthorizationControlSelection>
>([])

// Re-render the component every time persona gets updated
Expand Down Expand Up @@ -475,7 +476,7 @@ export default function Authorize() {
}

if (requestedScope.includes('email') && selectedEmail) {
personaData.email = selectedEmail
personaData.email = selectedEmail.value
}

if (
Expand All @@ -485,7 +486,9 @@ export default function Authorize() {
if (selectedConnectedAccounts[0] === AuthorizationControlSelection.ALL) {
personaData.connected_accounts = AuthorizationControlSelection.ALL
} else {
personaData.connected_accounts = selectedConnectedAccounts
personaData.connected_accounts = selectedConnectedAccounts.map(
(account) => (account as DropdownSelectListItem).value
)
}
}

Expand All @@ -494,7 +497,9 @@ export default function Authorize() {
if (selectedSCWallets[0] === AuthorizationControlSelection.ALL) {
personaData.erc_4337 = AuthorizationControlSelection.ALL
} else {
personaData.erc_4337 = selectedSCWallets
personaData.erc_4337 = selectedSCWallets.map(
(wallet) => (wallet as DropdownSelectListItem).value
)
}
} else {
form.append('createSCWallet', JSON.stringify({
Expand Down Expand Up @@ -655,7 +660,7 @@ export default function Authorize() {
disableAuthorize={
// TODO: make generic!
(requestedScope.includes('email') &&
(!connectedEmails?.length || !selectedEmail)) ||
(!connectedEmails?.length || !selectedEmail?.value)) ||
(requestedScope.includes('connected_accounts') &&
!selectedConnectedAccounts?.length)
}
Expand Down
10 changes: 3 additions & 7 deletions packages/design-system/src/atoms/dropdown/DropdownSelectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
import { Button } from "../buttons/Button"
import { TbCirclePlus } from "react-icons/tb"
import { BadRequestError } from "@proofzero/errors"
import type { AddressURN } from "@proofzero/urns/address"


export type DropdownSelectListItem = {
title: string
Expand Down Expand Up @@ -93,7 +91,7 @@ export const Dropdown = ({
}: {
items: Array<DropdownSelectListItem>,
placeholder: string,
onSelect: (selected: Array<AddressURN> | AddressURN) => void,
onSelect: (selected: Array<DropdownSelectListItem> | DropdownSelectListItem) => void,
multiple?: boolean
ConnectButtonPhrase: string,
ConnectButtonCallback: () => void,
Expand Down Expand Up @@ -148,13 +146,11 @@ export const Dropdown = ({
if (multiple) {
setSelectedItems(input as DropdownSelectListItem[])
if (!allItemsSelected) {
//@ts-ignore
onSelect(input.map((i) => i.value as AddressURN))
onSelect(input)
}
} else {
setSelectedItem(input as DropdownSelectListItem)
//@ts-ignore
onSelect(input.value as AddressURN)
onSelect(input)
}
}}
multiple={multiple}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
ChevronDownIcon,
ChevronUpIcon,
} from '@heroicons/react/20/solid'
import type { AddressURN } from '@proofzero/urns/address'

type UserProfile = {
pfpURL: string
Expand All @@ -46,16 +45,16 @@ type AuthorizationProps = {

connectedSmartContractWallets?: Array<DropdownSelectListItem>
addNewSmartWalletCallback: () => void
selectSmartWalletsCallback: (selected: Array<AddressURN>) => void
selectSmartWalletsCallback: (selected: Array<DropdownSelectListItem>) => void
selectAllSmartWalletsCallback: () => void

connectedEmails?: Array<DropdownSelectListItem>
addNewEmailCallback: () => void
selectEmailCallback: (selected: AddressURN) => void
selectEmailCallback: (selected: DropdownSelectListItem) => void

connectedAccounts?: Array<DropdownSelectListItem>
addNewAccountCallback: () => void
selectAccountsCallback: (selected: Array<AddressURN>) => void
selectAccountsCallback: (selected: Array<DropdownSelectListItem>) => void
selectAllAccountsCallback: () => void

cancelCallback: () => void
Expand Down Expand Up @@ -305,7 +304,7 @@ export default ({
placeholder="Create New Wallet"
multiple={true}
onSelect={(
selectedItems: Array<AddressURN>
selectedItems: Array<DropdownSelectListItem>
) => {
selectSmartWalletsCallback(selectedItems)
}}
Expand All @@ -324,7 +323,7 @@ export default ({
<Dropdown
items={connectedEmails}
placeholder="Select an Email Address"
onSelect={(selectedItem: AddressURN) => {
onSelect={(selectedItem: DropdownSelectListItem) => {
selectEmailCallback(selectedItem)
}}
ConnectButtonPhrase="Connect New Email Address"
Expand All @@ -339,7 +338,7 @@ export default ({
<Dropdown
items={connectedAccounts}
onSelect={(
selectedItems: Array<AddressURN>
selectedItems: Array<DropdownSelectListItem>
) => {
selectAccountsCallback(selectedItems)
}}
Expand Down

0 comments on commit c57c6da

Please sign in to comment.