Skip to content

Commit

Permalink
Merge branch 'feature/liquidiy-provider' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Ho3einWave committed Jan 7, 2025
2 parents 4cd1469 + 1772db9 commit e43142c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/components/Swap/Swap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
button {
cursor: pointer;
border: none;
background: transparent;
font-family: Inter, sans-serif;
}
input {
Expand Down
15 changes: 15 additions & 0 deletions lib/components/Swap/Swap.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,21 @@ export const WithAppId: Story = {
],
};

export const WithLiquidityProvider: Story = {
args: {
options: {
liquidity_provider: 'dedust',
},
},
decorators: [
(Story) => (
<div className="mts-ton-jiggle">
<Story />
</div>
),
],
};

export const HideSwapDetail: Story = {
args: {
options: {
Expand Down
3 changes: 2 additions & 1 deletion lib/components/SwapCard/CardDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ const CardDialog: FC<CardDialogProps> = ({
return (
item.name.toLowerCase().includes(searchValue) ||
item.symbol.toLowerCase().includes(searchValue) ||
item.address.includes(addressSearch)
(addressSearch.length > 0 &&
item.address.includes(addressSearch))
);
})
.filter((item) => (communityTokens ? true : !item.warning)) || [];
Expand Down
38 changes: 33 additions & 5 deletions lib/store/options.store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { create } from "zustand";
import { defaultsDeep } from "lodash";
import { TonConnectUI } from "@tonconnect/ui-react";
import { useSwapStore } from "./swap.store";
import { create } from 'zustand';
import { defaultsDeep } from 'lodash';
import { TonConnectUI } from '@tonconnect/ui-react';
import { useSwapStore } from './swap.store';
import { MyTonSwapClient } from '@mytonswap/sdk';
import { WIDGET_VERSION } from '../constants';
import { useWalletStore } from './wallet.store';

export type SwapOptions = {
default_pay_token?: string;
Expand All @@ -13,7 +16,13 @@ export type SwapOptions = {
default_pay_amount?: string;
pin_tokens?: string[];
app_id?: string;
layout_direction?: "ltr" | "rtl";
liquidity_provider?:
| 'mytonswap'
| 'stonfi'
| 'dedust'
| 'tonco'
| 'omniston';
layout_direction?: 'ltr' | 'rtl';
ui_preferences?: {
disable_provided_text?: boolean;
show_swap_details?: boolean;
Expand Down Expand Up @@ -41,6 +50,7 @@ export const useOptionsStore = create<SwapOptionsActions & SwapOptionsStates>(
(set, get) => ({
tonConnectInstance: null,
options: {
liquidity_provider: 'mytonswap',
ui_preferences: {
disable_provided_text: false,
disable_token_select_pay: false,
Expand All @@ -67,6 +77,24 @@ export const useOptionsStore = create<SwapOptionsActions & SwapOptionsStates>(
if (option.default_slippage) {
useSwapStore.getState().setSlippage(option.default_slippage);
}
if (option.liquidity_provider) {
useSwapStore.setState({
client: new MyTonSwapClient({
headers: {
'widget-version': WIDGET_VERSION,
'liquidity-provider': option.liquidity_provider,
},
}),
});
useWalletStore.setState({
client: new MyTonSwapClient({
headers: {
'widget-version': WIDGET_VERSION,
'liquidity-provider': option.liquidity_provider,
},
}),
});
}
},
setTonConnectInstance: (instance) => {
if (get().tonConnectInstance) return;
Expand Down
4 changes: 3 additions & 1 deletion lib/store/swap.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ type SwapActions = {

export const useSwapStore = create<SwapActions & SwapStates>((set, get) => ({
client: new MyTonSwapClient({
headers: { 'widget-version': WIDGET_VERSION },
headers: {
'widget-version': WIDGET_VERSION,
},
}),
refetchInterval: null,
pay_token: null,
Expand Down
4 changes: 3 additions & 1 deletion lib/store/wallet.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ type WalletActions = {
export const useWalletStore = create<WalletActions & WalletStates>(
(set, get) => ({
client: new MyTonSwapClient({
headers: { 'widget-version': WIDGET_VERSION },
headers: {
'widget-version': WIDGET_VERSION,
},
}),
wallet: null,
walletConnected: false,
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export default async function swap(
bestRoute: BestRoute
) {
const client = new MyTonSwapClient({
headers: { 'widget-version': WIDGET_VERSION },
headers: {
'widget-version': WIDGET_VERSION,
},
});
const app_id = useOptionsStore.getState().options.app_id;
const rawMessageResult = await catchError(() =>
Expand Down

0 comments on commit e43142c

Please sign in to comment.