Skip to content
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
22 changes: 22 additions & 0 deletions examples/mint/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const nfd = NfdClient.testNet()
export function App() {
const [nfdName, setNfdName] = useState('')
const [years, setYears] = useState(1)
const [reservedFor, setReservedFor] = useState('')
const [nfdData, setNfdData] = useState<Nfd | null>(null)
const [quoteData, setQuoteData] = useState<NfdMintQuote | null>(null)
const [error, setError] = useState('')
Expand All @@ -27,6 +28,12 @@ export function App() {
setNfdName(e.target.value)
}

const handleReservedForChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setQuoteData(null)
setNfdData(null)
setReservedFor(e.target.value)
}

const handleGetQuote = async (e: React.FormEvent) => {
e.preventDefault()
setError('')
Expand Down Expand Up @@ -78,6 +85,7 @@ export function App() {
.mint(quote.nfdName, {
buyer: quote.buyer,
years: quote.years,
...(reservedFor.trim() && { reservedFor: reservedFor.trim() }),
})

setNfdData(mintedNfd)
Expand Down Expand Up @@ -139,6 +147,20 @@ export function App() {
))}
</select>
</div>

<div style={{ marginBottom: '10px' }}>
<label htmlFor="reservedFor" style={{ marginRight: '10px' }}>
Reserved for (optional):
</label>
<input
id="reservedFor"
type="text"
value={reservedFor}
onChange={handleReservedForChange}
placeholder="Enter Algorand address"
style={{ width: '350px' }}
/>
</div>
</fieldset>

<button type="submit" disabled={isQuoteLoading || !nfdName.trim()}>
Expand Down
15 changes: 13 additions & 2 deletions packages/sdk/src/modules/minting.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AlgoAmount } from '@algorandfoundation/algokit-utils/types/amount'
import { isValidAddress } from 'algosdk'

import {
canMintSegment,
Expand All @@ -25,6 +26,11 @@ export interface NfdMintParams {
* Number of years until expiration (1-20)
*/
years: number

/**
* Optional address to reserve the NFD for. If not provided, the buyer's address will be used.
*/
reservedFor?: string
}

/**
Expand Down Expand Up @@ -264,7 +270,7 @@ export class MintingModule extends BaseModule {
)
}

const { buyer: buyerAddr, years: numYears } = params
const { buyer: buyerAddr, years: numYears, reservedFor } = params

// Validate years parameter
if (numYears <= 0) {
Expand All @@ -275,6 +281,11 @@ export class MintingModule extends BaseModule {
throw new Error('Years must be an integer')
}

// Validate reservedFor address
if (reservedFor && !isValidAddress(reservedFor)) {
throw new Error('Invalid reservedFor address')
}

// Get constraints to determine max years allowed
let maxYearsAllowed = 20 // Default fallback
try {
Expand Down Expand Up @@ -328,7 +339,7 @@ export class MintingModule extends BaseModule {
args: {
purchaseTxn: paymentTxn,
nfdName,
reservedFor: buyerAddr,
reservedFor: reservedFor || buyerAddr,
linkOnMint: false,
},
extraFee: AlgoAmount.MicroAlgos(extraFee),
Expand Down