Skip to content

Commit

Permalink
fix: add missing receiptsEndpoint to client instantiation (#647)
Browse files Browse the repository at this point in the history
## Description

This PR adds the `receiptsEndpoint` to the `w3up-client` instantiation.

## Motivation

Uploading in staging is currently broken. The console shows an error
when attempting to retrieve the receipt.

The receipts endpoint being used for staging is incorrect due to a
missing configuration. This causes the value to default to a hardcoded
production endpoint.
  • Loading branch information
BravoNatalie authored Nov 25, 2024
1 parent eb52893 commit 1c1e19d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface ContextActions {

export interface CreateClientOptions extends ServiceConfig {
events?: EventTarget
receiptsEndpoint?: URL
}

/**
Expand Down Expand Up @@ -72,6 +73,6 @@ export async function createClient (
const events = options?.events ?? new EventTarget()
const store = new IndexedDBEventDispatcherStore(dbName, events)
const serviceConf = createServiceConf(options)
const client = await createW3UPClient({ store, serviceConf })
const client = await createW3UPClient({ store, serviceConf, receiptsEndpoint: options?.receiptsEndpoint })
return { client, events, store }
}
8 changes: 5 additions & 3 deletions packages/react/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import type {
import { useState, useEffect, useCallback } from 'react'
import { STORE_SAVE_EVENT, createClient } from '@w3ui/core'

export type DatamodelProps = ServiceConfig
export type DatamodelProps = ServiceConfig & {
receiptsEndpoint?: URL
}

export interface Datamodel {
client?: Client
Expand All @@ -17,7 +19,7 @@ export interface Datamodel {
logout: () => Promise<void>
}

export function useDatamodel ({ servicePrincipal, connection }: DatamodelProps): Datamodel {
export function useDatamodel ({ servicePrincipal, connection, receiptsEndpoint }: DatamodelProps): Datamodel {
const [client, setClient] = useState<Client>()
const [events, setEvents] = useState<EventTarget>()
const [accounts, setAccounts] = useState<Account[]>([])
Expand All @@ -26,7 +28,7 @@ export function useDatamodel ({ servicePrincipal, connection }: DatamodelProps):
// update this function any time servicePrincipal or connection change
const setupClient = useCallback(
async (): Promise<void> => {
const { client, events } = await createClient({ servicePrincipal, connection })
const { client, events } = await createClient({ servicePrincipal, connection, receiptsEndpoint })
setClient(client)
setEvents(events)
setAccounts(Object.values(client.accounts()))
Expand Down
6 changes: 4 additions & 2 deletions packages/react/src/providers/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const Context = createContext<ContextValue>(

export interface ProviderProps extends ServiceConfig {
children?: ReactNode
receiptsEndpoint?: URL
}

/**
Expand All @@ -41,9 +42,10 @@ export interface ProviderProps extends ServiceConfig {
export function Provider ({
children,
servicePrincipal,
connection
connection,
receiptsEndpoint
}: ProviderProps): ReactNode {
const { client, accounts, spaces, logout } = useDatamodel({ servicePrincipal, connection })
const { client, accounts, spaces, logout } = useDatamodel({ servicePrincipal, connection, receiptsEndpoint })
return (
<Context.Provider value={[{ client, accounts, spaces }, { logout }]}>
{children}
Expand Down

0 comments on commit 1c1e19d

Please sign in to comment.