Skip to content

Commit 3eb2d1a

Browse files
committed
feat: support changes to SwapStatus union
1 parent 2c63536 commit 3eb2d1a

File tree

2 files changed

+74
-26
lines changed

2 files changed

+74
-26
lines changed

.changeset/floppy-sheep-grow.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@aave/graphql": patch
3+
"@aave/client": patch
4+
"@aave/react": patch
5+
---
6+
7+
**feat:** support changes to `SwapStatus` union.

packages/graphql/src/fragments/swaps.ts

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
import type { ExtendWithOpaqueType } from '@aave/types';
12
import type { FragmentOf } from 'gql.tada';
23
import { type FragmentDocumentFor, graphql } from '../graphql';
4+
import type { SwapId } from '../id';
35
import {
46
DomainDataFragment,
7+
type Erc20Amount,
8+
Erc20AmountFragment,
9+
type NativeAmount,
10+
NativeAmountFragment,
511
PaginatedResultInfoFragment,
612
PercentNumberFragment,
713
TokenAmountFragment,
814
} from './common';
15+
import { ReserveInfoFragment } from './reserve';
916
import {
1017
type InsufficientBalanceError,
1118
InsufficientBalanceErrorFragment,
@@ -231,6 +238,39 @@ export const SwapExpiredFragment = graphql(
231238
);
232239
export type SwapExpired = FragmentOf<typeof SwapExpiredFragment>;
233240

241+
export const PositionAmountFragment = graphql(
242+
`fragment PositionAmount on PositionAmount {
243+
__typename
244+
reserve {
245+
...ReserveInfo
246+
}
247+
amount {
248+
...Erc20Amount
249+
}
250+
}`,
251+
[ReserveInfoFragment, Erc20AmountFragment],
252+
);
253+
export type PositionAmount = FragmentOf<typeof PositionAmountFragment>;
254+
255+
export type SwapAmount = PositionAmount | NativeAmount | Erc20Amount;
256+
257+
export const SwapAmountFragment: FragmentDocumentFor<SwapAmount, 'SwapAmount'> =
258+
graphql(
259+
`fragment SwapAmount on SwapAmount {
260+
__typename
261+
... on PositionAmount {
262+
...PositionAmount
263+
}
264+
... on NativeAmount {
265+
...NativeAmount
266+
}
267+
... on Erc20Amount {
268+
...Erc20Amount
269+
}
270+
}`,
271+
[PositionAmountFragment, NativeAmountFragment, Erc20AmountFragment],
272+
);
273+
234274
export const SwapOpenFragment = graphql(
235275
`fragment SwapOpen on SwapOpen {
236276
__typename
@@ -239,13 +279,13 @@ export const SwapOpenFragment = graphql(
239279
deadline
240280
explorerLink
241281
desiredSell {
242-
...TokenAmount
282+
...SwapAmount
243283
}
244284
desiredBuy {
245-
...TokenAmount
285+
...SwapAmount
246286
}
247287
}`,
248-
[TokenAmountFragment],
288+
[SwapAmountFragment],
249289
);
250290
export type SwapOpen = FragmentOf<typeof SwapOpenFragment>;
251291

@@ -266,36 +306,28 @@ export const SwapFulfilledFragment = graphql(
266306
__typename
267307
txHash
268308
desiredSell {
269-
...TokenAmount
309+
...SwapAmount
270310
}
271311
desiredBuy {
272-
...TokenAmount
312+
...SwapAmount
273313
}
274314
sold {
275-
...TokenAmount
315+
...SwapAmount
276316
}
277317
bought {
278-
...TokenAmount
318+
...SwapAmount
279319
}
280320
createdAt
281321
fulfilledAt
282322
explorerLink
283323
refundTxHash
284324
}`,
285-
[TokenAmountFragment],
325+
[SwapAmountFragment],
286326
);
287327
export type SwapFulfilled = FragmentOf<typeof SwapFulfilledFragment>;
288328

289-
export type SwapStatus =
290-
| SwapOpen
291-
| SwapPendingSignature
292-
| SwapCancelled
293-
| SwapExpired
294-
| SwapFulfilled;
295-
296-
export const SwapStatusFragment: FragmentDocumentFor<SwapStatus, 'SwapStatus'> =
297-
graphql(
298-
`fragment SwapStatus on SwapStatus {
329+
export const SwapStatusFragment = graphql(
330+
`fragment SwapStatus on SwapStatus {
299331
__typename
300332
... on SwapOpen {
301333
...SwapOpen
@@ -313,14 +345,23 @@ export const SwapStatusFragment: FragmentDocumentFor<SwapStatus, 'SwapStatus'> =
313345
...SwapFulfilled
314346
}
315347
}`,
316-
[
317-
SwapOpenFragment,
318-
SwapPendingSignatureFragment,
319-
SwapCancelledFragment,
320-
SwapExpiredFragment,
321-
SwapFulfilledFragment,
322-
],
323-
);
348+
[
349+
SwapOpenFragment,
350+
SwapPendingSignatureFragment,
351+
SwapCancelledFragment,
352+
SwapExpiredFragment,
353+
SwapFulfilledFragment,
354+
],
355+
);
356+
357+
export type SwapStatus = ExtendWithOpaqueType<
358+
FragmentOf<typeof SwapStatusFragment>,
359+
{
360+
swapId: SwapId;
361+
createdAt: Date;
362+
explorerLink: string;
363+
}
364+
>;
324365

325366
export const PrepareSwapCancelResultFragment = graphql(
326367
`fragment PrepareSwapCancelResult on PrepareSwapCancelResult {

0 commit comments

Comments
 (0)