Skip to content

Commit 44cc04d

Browse files
thisconnectbznein
authored andcommitted
frontend: propose swap api
1 parent aae8eb9 commit 44cc04d

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

frontends/web/src/api/swap.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Copyright 2025 Shift Crypto AG
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import type { FailResponse, SuccessResponse } from './response';
18+
import type { AccountCode } from './account';
19+
import { apiGet, apiPost } from '@/utils/request';
20+
import { subscribeEndpoint, TUnsubscribe } from './subscribe';
21+
22+
export type TSwapQuotes = {
23+
quoteId: string;
24+
buyAsset: 'ETH.ETH';
25+
sellAsset: 'BTC.BTC';
26+
sellAmount: '0.001';
27+
// expectedBuyAmount;
28+
// expectedBuyAmountMaxSlippage;
29+
// fees: [];
30+
// routeId: string;
31+
// ...
32+
// expiration
33+
// estimatedTime
34+
// warnings: [];
35+
// targetAddress // so we can show the address in the app so the user can confirm with the one on the device
36+
// memo?
37+
};
38+
39+
export const getSwapState = (): Promise<TSwapQuotes> => {
40+
return apiGet('swap/state');
41+
};
42+
43+
export const syncSwapState = (
44+
cb: (state: TSwapQuotes) => void
45+
): TUnsubscribe => {
46+
return subscribeEndpoint('swap/state', cb);
47+
};
48+
49+
export type TProposeSwap = {
50+
buyAsset: AccountCode;
51+
sellAmount: string;
52+
sellAsset: AccountCode;
53+
};
54+
55+
export const proposeSwap = (
56+
data: TProposeSwap,
57+
): Promise<void> => {
58+
return apiPost('swap/quote', data);
59+
};
60+
61+
type TSwapFailed = FailResponse & { aborted: boolean };
62+
type TSwapExecutionResult = SuccessResponse | TSwapFailed;
63+
64+
export const executeSwap = (): Promise<TSwapExecutionResult> => {
65+
return apiPost('swap/execute');
66+
};

0 commit comments

Comments
 (0)