Skip to content

Commit b0e01cc

Browse files
committed
frontend: propose swap api
1 parent 89c7f62 commit b0e01cc

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

frontends/web/src/api/swap.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 { apiGet, apiPost } from '@/utils/request';
18+
import { subscribeEndpoint, TUnsubscribe } from './subscribe';
19+
import { AccountCode } from './account';
20+
21+
export type TSwapQuotes = {
22+
quoteId: string;
23+
buyAsset: "ETH.ETH";
24+
sellAsset: 'BTC.BTC';
25+
sellAmount: '0.001';
26+
// expectedBuyAmount;
27+
// expectedBuyAmountMaxSlippage;
28+
// fees: [];
29+
// routeId: string;
30+
// ...
31+
// expiration
32+
// estimatedTime
33+
// warnings: [];
34+
// targetAddress // so we can show the address in the app so the user can confirm with the one on the device
35+
// memo?
36+
}
37+
38+
export const getSwapState = (): Promise<TSwapQuotes> => {
39+
return apiGet('swap/state');
40+
};
41+
42+
export const syncSwapState = (
43+
cb: (state: TSwapQuotes) => void
44+
): TUnsubscribe => {
45+
return subscribeEndpoint('swap/state', cb);
46+
};
47+
48+
export type TProposeSwap = {
49+
buyAsset: AccountCode;
50+
sellAmount: string;
51+
sellAsset: AccountCode;
52+
}
53+
54+
export const proposeSwap = (
55+
data: TProposeSwap,
56+
): Promise<void> => {
57+
return apiPost('swap/quote', data);
58+
};

0 commit comments

Comments
 (0)