|
| 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