-
Notifications
You must be signed in to change notification settings - Fork 19
Feat/optional sender #491
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
base: main
Are you sure you want to change the base?
Feat/optional sender #491
Changes from 13 commits
c92354e
80ec848
2c8d8fb
9130179
5b5ad14
13011ab
d4c3f71
681f3bd
2eb565d
35f8ec5
78fb4a5
6f0be92
7a29bab
60930a8
39ed51a
6b170e0
3a0c3b7
09acee5
c715c55
829589b
1c9d7e5
0c29eaf
bbee3ec
920f098
80de8e7
0d069a1
1d255a3
d69ea30
877dcd3
f8f5b31
206971b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,12 @@ export type AddressOrNfdLinkProps = PropsWithChildren<{ | |
showCopyButton?: boolean | ||
showQRButton?: boolean | ||
nfd?: Nfd | ||
autoPopulated?: boolean | ||
}> | ||
|
||
export const AddressOrNfdLink = fixedForwardRef( | ||
( | ||
{ address: _address, nfd, short, className, children, showCopyButton, showQRButton, ...rest }: AddressOrNfdLinkProps, | ||
{ address: _address, nfd, short, className, children, showCopyButton, showQRButton, autoPopulated, ...rest }: AddressOrNfdLinkProps, | ||
ref?: React.LegacyRef<HTMLAnchorElement> | ||
) => { | ||
const [selectedNetwork] = useSelectedNetwork() | ||
|
@@ -54,6 +55,12 @@ export const AddressOrNfdLink = fixedForwardRef( | |
) : ( | ||
<div className="flex items-center overflow-hidden"> | ||
{link} | ||
{autoPopulated && ( | ||
<span className="group ml-1 cursor-help text-yellow-500"> | ||
<span>?</span> | ||
<div className="absolute z-10 hidden rounded-sm border-2 border-gray-300/20 p-1 group-hover:block">auto populated</div> | ||
|
||
</span> | ||
)} | ||
{showCopyButton && <CopyButton value={address} />} | ||
{showQRButton && <OpenAddressQRDialogButton address={address} />} | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { cn } from '../utils' | |
export type DescriptionListItems = { | ||
dt: string | ||
dd: string | number | bigint | boolean | React.JSX.Element[] | React.JSX.Element | undefined | ||
highlightedDD?: boolean | ||
}[] | ||
|
||
type Props = { | ||
|
@@ -16,7 +17,7 @@ export function DescriptionList({ items, dtClassName }: Props) { | |
{items.map((item, index) => ( | ||
<dl key={index} className={cn('grid grid-cols-subgrid col-span-2')}> | ||
<dt className={cn('font-medium', dtClassName)}>{item.dt}</dt> | ||
<dd className={cn('overflow-ellipsis whitespace-normal overflow-hidden')}> | ||
<dd className={cn('overflow-ellipsis whitespace-normal overflow-hidden', item.highlightedDD && 'font-medium text-green-500')}> | ||
|
||
{typeof item.dd === 'bigint' ? item.dd.toString() : item.dd} | ||
</dd> | ||
</dl> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,14 +30,15 @@ export const allWalletProviderNames: Record<WalletId, string> = { | |
pera: 'Pera', | ||
exodus: 'Exodus', | ||
lute: 'Lute', | ||
// The below providers aren't used | ||
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 think we should still keep this comment |
||
custom: 'Custom', | ||
kibisis: 'Kibisis', | ||
walletconnect: 'Wallet Connect', | ||
magic: 'Magic', | ||
biatec: 'Biatec', | ||
} | ||
|
||
export const FEE_SINK_ADDRESS = 'Y76M3MSY6DKBRHBL7C3NNDXGS5IIMQVQVUAB6MP4XEMMGVF2QWNPL226CA' | ||
|
||
export const defaultNetworkConfigs: Record<NetworkId, NetworkConfig> = { | ||
[localnetId]: { | ||
name: 'LocalNet', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import { numberSchema } from '@/features/forms/data/common' | ||
import { addressFieldSchema, commonSchema, optionalAddressFieldSchema, senderFieldSchema } from '../data/common' | ||
import { | ||
addressFieldSchema, | ||
commonSchema, | ||
optionalAddressFieldSchema, | ||
optionalSenderFieldShape, | ||
} from '@/features/transaction-wizard/data/common' | ||
import { z } from 'zod' | ||
import { useCallback, useMemo } from 'react' | ||
import { zfd } from 'zod-form-data' | ||
|
@@ -18,14 +23,17 @@ import { TransactionBuilderNoteField } from './transaction-builder-note-field' | |
import { asAddressOrNfd, asOptionalAddressOrNfd } from '../mappers/as-address-or-nfd' | ||
import { ActiveWalletAccount } from '@/features/wallet/types/active-wallet' | ||
|
||
import defineSenderAddress from '../utils/defineSenderAddress' | ||
import { useNetworkConfig } from '@/features/network/data' | ||
|
||
const senderLabel = 'Sender' | ||
const receiverLabel = 'Receiver' | ||
const closeRemainderToLabel = 'Close remainder to' | ||
|
||
const formSchema = z | ||
.object({ | ||
...commonSchema, | ||
...senderFieldSchema, | ||
...optionalSenderFieldShape, | ||
closeRemainderTo: addressFieldSchema, | ||
receiver: optionalAddressFieldSchema, | ||
amount: numberSchema(z.number({ required_error: 'Required', invalid_type_error: 'Required' }).min(0).optional()), | ||
|
@@ -58,12 +66,14 @@ type Props = { | |
} | ||
|
||
export function AccountCloseTransactionBuilder({ mode, transaction, activeAccount, onSubmit, onCancel }: Props) { | ||
const { id: networkId } = useNetworkConfig() | ||
|
||
const submit = useCallback( | ||
async (data: z.infer<typeof formData>) => { | ||
onSubmit({ | ||
id: transaction?.id ?? randomGuid(), | ||
type: BuildableTransactionType.AccountClose, | ||
sender: data.sender, | ||
sender: await defineSenderAddress(data.sender!, networkId), | ||
|
||
closeRemainderTo: data.closeRemainderTo, | ||
receiver: asOptionalAddressOrNfd(data.receiver), | ||
amount: data.amount, | ||
|
@@ -72,7 +82,7 @@ export function AccountCloseTransactionBuilder({ mode, transaction, activeAccoun | |
note: data.note, | ||
}) | ||
}, | ||
[onSubmit, transaction?.id] | ||
[onSubmit, transaction?.id, networkId] | ||
) | ||
const defaultValues = useMemo<Partial<z.infer<typeof formData>>>(() => { | ||
if (mode === TransactionBuilderMode.Edit && transaction) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import algosdk from 'algosdk' | ||
import { numberSchema } from '@/features/forms/data/common' | ||
import { | ||
senderFieldSchema, | ||
commonSchema, | ||
onCompleteOptionsForAppCreate, | ||
onCompleteForAppCreateFieldSchema, | ||
optionalSenderFieldShape, | ||
} from '@/features/transaction-wizard/data/common' | ||
import { z } from 'zod' | ||
import { zfd } from 'zod-form-data' | ||
|
@@ -22,9 +22,12 @@ import { TransactionBuilderNoteField } from './transaction-builder-note-field' | |
import { asAddressOrNfd } from '../mappers/as-address-or-nfd' | ||
import { ActiveWalletAccount } from '@/features/wallet/types/active-wallet' | ||
|
||
|
||
import defineSenderAddress from '../utils/defineSenderAddress' | ||
import { useNetworkConfig } from '@/features/network/data' | ||
|
||
const formData = zfd.formData({ | ||
...commonSchema, | ||
...senderFieldSchema, | ||
...optionalSenderFieldShape, | ||
...onCompleteForAppCreateFieldSchema, | ||
approvalProgram: zfd.text(z.string({ required_error: 'Required', invalid_type_error: 'Required' })), | ||
clearStateProgram: zfd.text(z.string({ required_error: 'Required', invalid_type_error: 'Required' })), | ||
|
@@ -50,14 +53,16 @@ type Props = { | |
} | ||
|
||
export function ApplicationCreateTransactionBuilder({ mode, transaction, activeAccount, onSubmit, onCancel }: Props) { | ||
const { id: networkId } = useNetworkConfig() | ||
|
||
const submit = useCallback( | ||
async (values: z.infer<typeof formData>) => { | ||
onSubmit({ | ||
id: transaction?.id ?? randomGuid(), | ||
type: BuildableTransactionType.ApplicationCreate, | ||
approvalProgram: values.approvalProgram, | ||
clearStateProgram: values.clearStateProgram, | ||
sender: values.sender, | ||
sender: await defineSenderAddress(values.sender!, networkId), | ||
onComplete: Number(values.onComplete), | ||
extraProgramPages: values.extraProgramPages, | ||
globalInts: values.globalInts, | ||
|
@@ -70,7 +75,7 @@ export function ApplicationCreateTransactionBuilder({ mode, transaction, activeA | |
note: values.note, | ||
}) | ||
}, | ||
[onSubmit, transaction?.id] | ||
[onSubmit, transaction?.id, networkId] | ||
) | ||
|
||
const defaultValues = useMemo<Partial<z.infer<typeof formData>>>(() => { | ||
|
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.
nitpick: there is double spaces here