@sodax/dapp-kit 2.1.0-rc.9 → 2.2.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +25 -6
- package/dist/index.mjs +29 -23
- package/package.json +2 -2
- package/src/hooks/_apiKeyWire.test.ts +487 -0
- package/src/hooks/bridge/useBridge.test.ts +104 -0
- package/src/hooks/shared/index.ts +1 -0
- package/src/hooks/shared/retryUnlessAuthFailure.test.ts +38 -0
- package/src/hooks/shared/retryUnlessAuthFailure.ts +18 -0
- package/src/hooks/sponsoring/useActivateStellarAccount.wire.test.ts +109 -0
- package/src/hooks/swap/useSwap.test.ts +128 -0
- package/src/hooks/swapsApi/useSwapsApiAllowance.ts +2 -1
- package/src/hooks/swapsApi/useSwapsApiApprove.ts +2 -1
- package/src/hooks/swapsApi/useSwapsApiCancelIntent.ts +2 -1
- package/src/hooks/swapsApi/useSwapsApiCreateIntent.ts +2 -1
- package/src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts +2 -1
- package/src/hooks/swapsApi/useSwapsApiDeadline.ts +2 -1
- package/src/hooks/swapsApi/useSwapsApiEstimateGas.ts +2 -1
- package/src/hooks/swapsApi/useSwapsApiFilledIntent.ts +2 -1
- package/src/hooks/swapsApi/useSwapsApiIntent.ts +2 -1
- package/src/hooks/swapsApi/useSwapsApiIntentExtraData.ts +2 -1
- package/src/hooks/swapsApi/useSwapsApiIntentHash.ts +2 -1
- package/src/hooks/swapsApi/useSwapsApiIntentPacket.ts +2 -1
- package/src/hooks/swapsApi/useSwapsApiPartnerFee.ts +2 -1
- package/src/hooks/swapsApi/useSwapsApiQuote.ts +5 -1
- package/src/hooks/swapsApi/useSwapsApiSolverFee.ts +2 -1
- package/src/hooks/swapsApi/useSwapsApiStatus.ts +10 -4
- package/src/hooks/swapsApi/useSwapsApiSubmitTx.ts +5 -3
- package/src/hooks/swapsApi/useSwapsApiSubmitTxStatus.ts +8 -4
- package/src/hooks/swapsApi/useSwapsApiTokens.ts +2 -1
- package/src/hooks/swapsApi/useSwapsApiTokensByChain.ts +2 -1
- package/src/providers/SodaxProvider.test.ts +41 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `SodaxProvider` wire test for the consumer-supplied API key: `config.apiKey` handed to the
|
|
3
|
+
* provider must reach the backend as `x-api-key` on requests made through the provided instance.
|
|
4
|
+
*
|
|
5
|
+
* Covers the one key-supply surface the hook manifests' hand-built `Sodax` does not: the provider's
|
|
6
|
+
* own `new Sodax(config)`. No renderer — `useMemo` is patched to evaluate its factory so the
|
|
7
|
+
* component can be called as a plain function and the provided `sodax` read off the element's
|
|
8
|
+
* context value.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { Sodax } from '@sodax/sdk';
|
|
12
|
+
import type { ReactElement } from 'react';
|
|
13
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
14
|
+
|
|
15
|
+
vi.mock('react', async importOriginal => ({
|
|
16
|
+
...(await importOriginal<typeof import('react')>()),
|
|
17
|
+
useMemo: <T>(factory: () => T): T => factory(),
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
const { SodaxProvider } = await import('./SodaxProvider.js');
|
|
21
|
+
|
|
22
|
+
const fetchMock = vi.fn(
|
|
23
|
+
async () => new Response('{}', { status: 200, headers: { 'content-type': 'application/json' } }),
|
|
24
|
+
);
|
|
25
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
26
|
+
|
|
27
|
+
describe('SodaxProvider — config.apiKey on the wire', () => {
|
|
28
|
+
it('provides a Sodax whose backend requests carry x-api-key from the provider config', async () => {
|
|
29
|
+
const element = SodaxProvider({ config: { apiKey: 'provider-key', logger: 'silent' }, children: null });
|
|
30
|
+
|
|
31
|
+
const { sodax } = (element as ReactElement<{ value: { sodax: Sodax } }>).props.value;
|
|
32
|
+
const result = await sodax.api.getAllConfig();
|
|
33
|
+
|
|
34
|
+
expect(result.ok).toBe(true);
|
|
35
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
36
|
+
const [url, init] = fetchMock.mock.calls[0] ?? [];
|
|
37
|
+
expect(new URL(String(url)).pathname).toBe('/v1/be/config/all');
|
|
38
|
+
expect(init?.method).toBe('GET');
|
|
39
|
+
expect(new Headers(init?.headers).get('x-api-key')).toBe('provider-key');
|
|
40
|
+
});
|
|
41
|
+
});
|