Skip to content

Commit 05f4190

Browse files
committed
chore: add signatures endpoint
1 parent 8902eb6 commit 05f4190

4 files changed

Lines changed: 187 additions & 14 deletions

File tree

apps/customer/app/test/page.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
usePlaceOrder,
3434
useProfile,
3535
useRequestIban,
36+
useSignatures,
3637
useSubmitProfileDetails,
3738
useSubscribeOrderNotification,
3839
useTokens,
@@ -95,6 +96,7 @@ export default function Test() {
9596
});
9697

9798
const { data: tokens } = useTokens();
99+
const { data: signatures } = useSignatures();
98100

99101
/**
100102
* Monerium mutations
@@ -855,6 +857,13 @@ export default function Test() {
855857
<PrettyPrintJson data={tokens} />
856858
</details>
857859
</div>
860+
<div>
861+
<h2>Signatures</h2>
862+
<details>
863+
<summary>Click to Expand, total: {signatures?.total}</summary>
864+
<PrettyPrintJson data={signatures} />
865+
</details>
866+
</div>
858867
</div>
859868
<br />
860869

packages/sdk-react-provider/src/lib/hooks.tsx

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import MoneriumClient, {
2424
ProfilesResponse,
2525
RequestIbanPayload,
2626
ResponseStatus,
27+
SignaturesQueryParams,
28+
SignaturesResponse,
2729
SubmitProfileDetailsPayload,
2830
Token,
2931
} from '@monerium/sdk';
@@ -86,6 +88,11 @@ export const keys = {
8688
requestIban: ['monerium', 'request-iban'],
8789
placeOrder: ['monerium', 'place-order'],
8890
linkAddress: ['monerium', 'link-address'],
91+
getSignatures: (filter?: unknown) => [
92+
'monerium',
93+
'signatures',
94+
...(filter ? [filter] : []),
95+
],
8996
};
9097

9198
/** Internal hook to use SDK */
@@ -998,6 +1005,72 @@ export function usePlaceOrder({
9981005
...rest,
9991006
};
10001007
}
1008+
/**
1009+
* Get pending signatures for the authenticated user.
1010+
*
1011+
* Returns pending signatures that require user action, such as order signatures
1012+
* or link address signatures. Accepts filtering by address, chain, kind, and profile.
1013+
*
1014+
* @group Hooks
1015+
* @category Signatures
1016+
* @param {Object} params
1017+
* @param {SignaturesQueryParams} params.query - Optional query parameters to filter signatures
1018+
*
1019+
* @example
1020+
* ```ts
1021+
* // Get all pending signatures
1022+
* const {
1023+
* data: signatures,
1024+
* isLoading,
1025+
* isError,
1026+
* error,
1027+
* refetch,
1028+
* ...moreUseQueryResults
1029+
* } = useSignatures();
1030+
*
1031+
* // Get pending order signatures for a specific address
1032+
* const { data: orderSignatures } = useSignatures({
1033+
* query: {
1034+
* address: '0x1234...',
1035+
* kind: 'order'
1036+
* }
1037+
* });
1038+
*
1039+
* // Check the kind of signature
1040+
* signatures?.pending.forEach(sig => {
1041+
* if (sig.kind === 'order') {
1042+
* console.log('Order signature:', sig.id, sig.amount);
1043+
* } else {
1044+
* console.log('Link address signature');
1045+
* }
1046+
* });
1047+
* ```
1048+
* @see {@link https://monerium.dev/api-docs-v2#tag/signatures/operation/get-signatures | API Documentation}
1049+
*/
1050+
export function useSignatures({
1051+
query,
1052+
options,
1053+
}: {
1054+
query?: SignaturesQueryParams;
1055+
/** {@inheritDoc QueryOptions} */
1056+
options?: QueryOptions<SignaturesResponse>;
1057+
} = {}) {
1058+
const sdk = useSdk();
1059+
const { isAuthorized } = useAuth();
1060+
1061+
return useQuery<SignaturesResponse>({
1062+
...options,
1063+
queryKey: keys.getSignatures(query),
1064+
queryFn: () => {
1065+
if (!sdk) {
1066+
throw new Error('No SDK instance available');
1067+
}
1068+
return sdk.getSignatures(query);
1069+
},
1070+
enabled: Boolean(sdk && isAuthorized && (options?.enabled ?? true)),
1071+
});
1072+
}
1073+
10011074
/**
10021075
* # Add address to profile.
10031076
*

packages/sdk/src/client.ts

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ import type {
5151
RefreshTokenPayload,
5252
RequestIbanPayload,
5353
ResponseStatus,
54+
SignaturesQueryParams,
55+
SignaturesResponse,
5456
SubmitProfileDetailsPayload,
5557
SupportingDoc,
5658
Token,
@@ -555,6 +557,43 @@ export class MoneriumClient {
555557
return this.#api<Token[]>('get', 'tokens');
556558
}
557559

560+
/**
561+
* Get pending signatures for the authenticated user.
562+
*
563+
* Returns pending signatures that require user action, such as order signatures
564+
* or link address signatures. Accepts filtering by address, chain, kind, and profile.
565+
*
566+
* @group Signatures
567+
* @param {SignaturesQueryParams} [params] - Optional query parameters to filter signatures
568+
* @see {@link https://monerium.dev/api-docs-v2#tag/signatures/operation/get-signatures | API Documentation}
569+
*
570+
* @example
571+
* ```ts
572+
* // Get all pending signatures
573+
* const signatures = await monerium.getSignatures();
574+
*
575+
* // Get pending order signatures for a specific address
576+
* const orderSignatures = await monerium.getSignatures({
577+
* address: '0x1234...',
578+
* kind: 'order'
579+
* });
580+
*
581+
* // Get pending signatures on a specific chain
582+
* const polygonSignatures = await monerium.getSignatures({
583+
* chain: 'polygon'
584+
* });
585+
* ```
586+
*/
587+
getSignatures(params?: SignaturesQueryParams): Promise<SignaturesResponse> {
588+
const queryParameters = params
589+
? mapChainIdToChain(this.#env.name, params)
590+
: undefined;
591+
return this.#api<SignaturesResponse>(
592+
'get',
593+
`signatures${queryParams(queryParameters)}`
594+
);
595+
}
596+
558597
/**
559598
* Add a new address to the profile
560599
* @group Addresses
@@ -574,25 +613,11 @@ export class MoneriumClient {
574613
*
575614
* **Note:** For multi-signature orders, the API returns a 202 Accepted response
576615
* with `{status: 202, statusText: "Accepted"}` instead of the full Order object.
577-
* Check if the response has an `id` property to determine if it's a full Order.
578616
*
579617
* @returns Promise that resolves to either:
580618
* - `Order` - Full order object for regular orders
581619
* - `ResponseStatus` - Status object with `{status: 202, statusText: "Accepted"}` for multi-sig orders
582620
*
583-
* @example
584-
* ```ts
585-
* const result = await monerium.placeOrder(orderData);
586-
*
587-
* if ('id' in result) {
588-
* // Regular order - full Order object
589-
* console.log('Order placed:', result.id);
590-
* } else {
591-
* // Multi-sig order - 202 Accepted
592-
* console.log('Multi-sig order accepted:', result.status);
593-
* }
594-
* ```
595-
*
596621
* @see {@link https://monerium.dev/api-docs-v2#tag/orders/operation/post-orders | API Documentation}
597622
*
598623
* @group Orders

packages/sdk/src/types.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,3 +684,69 @@ export type ResponseStatus = {
684684
status: number;
685685
statusText: string;
686686
};
687+
688+
// -- Signatures
689+
690+
/**
691+
* Type of pending signature
692+
*/
693+
export type PendingSignatureKind = 'linkAddress' | 'order';
694+
695+
/**
696+
* Base interface for pending signatures
697+
*/
698+
interface PendingSignatureBase {
699+
kind: PendingSignatureKind;
700+
chain: Chain;
701+
address: string;
702+
createdAt: string;
703+
}
704+
705+
/**
706+
* Pending signature for an order
707+
*/
708+
export interface PendingOrderSignature extends PendingSignatureBase {
709+
id: string;
710+
kind: 'order';
711+
amount: string;
712+
counterpart: Counterpart;
713+
currency: Currency;
714+
}
715+
716+
/**
717+
* Pending signature for linking an address
718+
*/
719+
export interface PendingLinkAddressSignature extends PendingSignatureBase {
720+
kind: 'linkAddress';
721+
}
722+
723+
/**
724+
* Union type for all pending signature types
725+
*/
726+
export type PendingSignature =
727+
| PendingOrderSignature
728+
| PendingLinkAddressSignature;
729+
730+
/**
731+
* Query parameters for fetching pending signatures
732+
*/
733+
export interface SignaturesQueryParams {
734+
/** Filter by blockchain address */
735+
address?: string;
736+
/** Filter by blockchain network */
737+
chain?: Chain | ChainId;
738+
/** Filter by signature request kind */
739+
kind?: PendingSignatureKind;
740+
/** UUID of the profile (defaults to authenticated user's default profile) */
741+
profile?: string;
742+
}
743+
744+
/**
745+
* Response from the signatures endpoint
746+
*/
747+
export interface SignaturesResponse {
748+
/** Array of pending signatures */
749+
pending: PendingSignature[];
750+
/** Total number of pending signatures */
751+
total: number;
752+
}

0 commit comments

Comments
 (0)