Skip to content

Commit

Permalink
Merge pull request #161 from peanutprotocol/develop
Browse files Browse the repository at this point in the history
Main Release
  • Loading branch information
Hugo0 authored Oct 24, 2024
2 parents f6e5dea + 5c90b19 commit a171b22
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ export interface ICreateRequestLinkProps {
APIKey?: string
}

export interface IGetRequestLinkDetailsProps {
link: string
export type IGetRequestLinkDetailsProps = {
APIKey?: string
apiUrl?: string
}
} & (
| {
link: string
}
| {
uuid: string
}
)

export interface IPrepareRequestLinkFulfillmentTransactionProps {
recipientAddress: string
Expand Down Expand Up @@ -154,12 +160,12 @@ export async function createRequestLink({
}
}

export async function getRequestLinkDetails({
link,
APIKey,
apiUrl = 'https://api.peanut.to/',
}: IGetRequestLinkDetailsProps): Promise<IGetRequestLinkDetailsResponse> {
const uuid = getUuidFromLink(link)
export async function getRequestLinkDetails(
props: IGetRequestLinkDetailsProps
): Promise<IGetRequestLinkDetailsResponse> {
const { APIKey, apiUrl = 'https://api.peanut.to/' } = props

const uuid = 'uuid' in props ? props.uuid : getUuidFromLink(props.link)

const apiResponse = await fetch(normalizePath(`${apiUrl}/request-links/${uuid}`), {
method: 'GET',
Expand Down
14 changes: 14 additions & 0 deletions test/unit/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ describe('Request', () => {

expect(mockFetch).toHaveBeenCalledWith(`https://api.peanut.to/request-links/${linkUuid}`, expect.anything())
})

it('should accept uuid directly', async () => {
const linkUuid = 'ee3b904d-9809-4b97-b82b-34de1d1a7314'
mockFetch.mockResolvedValueOnce({
json: jest.fn().mockResolvedValueOnce({
link: `https://peanut.to/request/pay?id=${linkUuid}`,
}),
status: 200,
})

await getRequestLinkDetails({ uuid: linkUuid })

expect(mockFetch).toHaveBeenCalledWith(`https://api.peanut.to/request-links/${linkUuid}`, expect.anything())
})
})

describe('submitRequestLinkFulfillment', () => {
Expand Down

0 comments on commit a171b22

Please sign in to comment.