Skip to content

Commit 6c71713

Browse files
committed
feat: allows to expand swap strategies without breaking changes
1 parent 3eb2d1a commit 6c71713

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

.changeset/fluffy-drinks-dig.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/react": patch
4+
"@aave/client": patch
5+
---
6+
7+
**feat:** allows to expand swap strategies without breaking changes.

packages/graphql/src/fragments/swaps.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { ExtendWithOpaqueType } from '@aave/types';
22
import type { FragmentOf } from 'gql.tada';
33
import { type FragmentDocumentFor, graphql } from '../graphql';
4-
import type { SwapId } from '../id';
54
import {
65
DomainDataFragment,
76
type Erc20Amount,
@@ -149,8 +148,8 @@ export const PrepareTokenSwapResultFragment = graphql(
149148
InsufficientBalanceErrorFragment,
150149
],
151150
);
152-
export type PrepareTokenSwapResult = FragmentOf<
153-
typeof PrepareTokenSwapResultFragment
151+
export type PrepareTokenSwapResult = ExtendWithOpaqueType<
152+
FragmentOf<typeof PrepareTokenSwapResultFragment>
154153
>;
155154

156155
export const SwapTransactionRequestFragment = graphql(
@@ -185,11 +184,12 @@ export type SwapApprovalRequired = FragmentOf<
185184
typeof SwapApprovalRequiredFragment
186185
>;
187186

188-
export type SwapExecutionPlan =
187+
export type SwapExecutionPlan = ExtendWithOpaqueType<
189188
| SwapTransactionRequest
190189
| SwapApprovalRequired
191190
| InsufficientBalanceError
192-
| SwapReceipt;
191+
| SwapReceipt
192+
>;
193193

194194
export const SwapExecutionPlanFragment: FragmentDocumentFor<
195195
SwapExecutionPlan,
@@ -357,7 +357,6 @@ export const SwapStatusFragment = graphql(
357357
export type SwapStatus = ExtendWithOpaqueType<
358358
FragmentOf<typeof SwapStatusFragment>,
359359
{
360-
swapId: SwapId;
361360
createdAt: Date;
362361
explorerLink: string;
363362
}
@@ -538,7 +537,7 @@ export const PrepareWithdrawSwapResultFragment: FragmentDocumentFor<
538537
[PositionSwapByIntentApprovalsRequiredFragment],
539538
);
540539

541-
export type PreparePositionSwapResult = SwapByIntent;
540+
export type PreparePositionSwapResult = ExtendWithOpaqueType<SwapByIntent>;
542541

543542
export const PreparePositionSwapResultFragment: FragmentDocumentFor<
544543
PreparePositionSwapResult,

packages/react/src/swap.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,13 @@ export function useWithdrawSwapQuote({
11521152
request,
11531153
currency,
11541154
},
1155-
selector: (data) => data.quote,
1155+
selector: (data) => {
1156+
invariant(
1157+
data.__typename === 'PositionSwapByIntentApprovalsRequired',
1158+
`Unsupported swap plan: ${data.__typename}. Upgrade to a newer version of the @aave/react package.`,
1159+
);
1160+
return data.quote;
1161+
},
11561162
suspense,
11571163
pause,
11581164
});
@@ -1320,6 +1326,7 @@ export function useTokenSwap(
13201326
| SendTransactionError
13211327
| PendingTransactionError
13221328
| ValidationError<InsufficientBalanceError>
1329+
| UnexpectedError
13231330
> => {
13241331
switch (plan.__typename) {
13251332
case 'SwapTransactionRequest':
@@ -1329,6 +1336,7 @@ export function useTokenSwap(
13291336
.andThen(() => {
13301337
return okAsync(plan.orderReceipt);
13311338
});
1339+
13321340
case 'SwapApprovalRequired':
13331341
return handler(plan, { cancel })
13341342
.map(PendingTransaction.ensure)
@@ -1339,10 +1347,17 @@ export function useTokenSwap(
13391347
.andThen(() => {
13401348
return okAsync(plan.originalTransaction.orderReceipt);
13411349
});
1350+
13421351
case 'InsufficientBalanceError':
13431352
return ValidationError.fromGqlNode(plan).asResultAsync();
1353+
13441354
case 'SwapReceipt':
13451355
return okAsync(plan);
1356+
1357+
default:
1358+
return new UnexpectedError(
1359+
`Unsupported swap plan: ${plan.__typename}. Upgrade to a newer version of the @aave/react package.`,
1360+
).asResultAsync();
13461361
}
13471362
},
13481363
[handler],
@@ -1399,6 +1414,11 @@ export function useTokenSwap(
13991414

14001415
case 'InsufficientBalanceError':
14011416
return ValidationError.fromGqlNode(preparePlan).asResultAsync();
1417+
1418+
default:
1419+
return new UnexpectedError(
1420+
`Unsupported swap plan: ${preparePlan.__typename}. Upgrade to a newer version of the @aave/react package.`,
1421+
).asResultAsync();
14021422
}
14031423
}),
14041424
[client, handler, executeSwap],

0 commit comments

Comments
 (0)