Skip to content

Commit 1048ef6

Browse files
authored
🦕 feat: added singleTxOnly customisation option (#20)
* feat: added singleTxOnly customisation option * minor fix
1 parent 7861f47 commit 1048ef6

File tree

6 files changed

+40
-20
lines changed

6 files changed

+40
-20
lines changed

src/components/Input.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ export const Input = ({
124124
}, [allNetworks]);
125125

126126
// For Input & tokens
127+
const inputAmountFromReduxState = useSelector(
128+
(state: any) => state.amount.sourceAmount
129+
);
127130
const [inputAmount, updateInputAmount] = useState<string>("");
128131
const [parsedInputAmount, setParsedInputAmount] = useState<string>(""); // to check the min balance requirement
129132

@@ -270,6 +273,11 @@ export const Input = ({
270273
} else formateAndParseAmount(balance);
271274
}
272275

276+
// Reset source amount on mount
277+
useEffect(() => {
278+
inputAmountFromReduxState && dispatch(setSourceAmount(null));
279+
}, []);
280+
273281
return (
274282
<div className="mt-3.5">
275283
<div className="flex items-center justify-between">

src/hooks/apis.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import { Web3Context } from "../providers/Web3Provider";
2121
export let socket;
2222

2323
// Function that lets you set the api key and preferences.
24-
export const initSocket = (apiKey) => {
24+
export const initSocket = (apiKey: string, _singleTxOnly: boolean) => {
2525
socket = new Socket({
2626
apiKey: apiKey,
2727
defaultQuotePreferences: {
28-
singleTxOnly: false,
28+
singleTxOnly: _singleTxOnly,
2929
},
3030
});
3131
};
@@ -114,7 +114,15 @@ export const useRoutes = (
114114

115115
const { data, error, isValidating } = useSWR(
116116
shouldFetch
117-
? [sourceToken, destToken, amount, userAddress, sort, refuelEnabled, "quotes"]
117+
? [
118+
sourceToken,
119+
destToken,
120+
amount,
121+
userAddress,
122+
sort,
123+
refuelEnabled,
124+
"quotes",
125+
]
118126
: null,
119127
fetchQuotes,
120128
{

src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import { Web3Provider } from "./providers/Web3Provider";
1111
import { initSocket } from "./hooks/apis";
1212

1313
export const Bridge = (props: WidgetProps) => {
14-
const { API_KEY } = props;
14+
const { API_KEY, singleTxOnly = false } = props;
1515

1616
if (!API_KEY) {
1717
return <IntegrationError>Please pass the API key</IntegrationError>;
18-
} else initSocket(API_KEY); // initialising socket sdk
18+
} else initSocket(API_KEY, singleTxOnly); // initialising socket sdk
1919

2020
if (API_KEY) {
2121
return (

src/state/customSettingsSlice.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ const customSettingsSlice = createSlice({
2525
state.defaultSourceNetwork = action.payload;
2626
},
2727
setDefaultDestNetwork: (state, action) => {
28-
state.defaultDestNetwork = action.payload
28+
state.defaultDestNetwork = action.payload;
2929
},
3030
setCustomSourceTokens: (state, action) => {
31-
state.sourceTokens = action.payload
32-
},
31+
state.sourceTokens = action.payload;
32+
},
3333
setCustomDestTokens: (state, action) => {
34-
state.destTokens = action.payload
34+
state.destTokens = action.payload;
3535
},
3636
setDefaultSourceToken: (state, action) => {
37-
state.defaultSourceToken = action.payload
37+
state.defaultSourceToken = action.payload;
3838
},
3939
setDefaultDestToken: (state, action) => {
40-
state.defaultDestToken = action.payload
41-
}
40+
state.defaultDestToken = action.payload;
41+
},
4242
},
4343
});
4444

src/state/quotesSlice.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createSlice } from "@reduxjs/toolkit";
33
const initialState = {
44
allQuotes: null,
55
bestRoute: null,
6-
sortPref: 'output',
6+
sortPref: "output",
77
refuelEnabled: false,
88
};
99

@@ -12,19 +12,20 @@ const quotesSlice = createSlice({
1212
initialState,
1313
reducers: {
1414
setQuotes: (state, action) => {
15-
state.allQuotes = action.payload
15+
state.allQuotes = action.payload;
1616
},
1717
setBestRoute: (state, action) => {
18-
state.bestRoute = action.payload
18+
state.bestRoute = action.payload;
1919
},
2020
setSortPref: (state, action) => {
21-
state.sortPref = action.payload
21+
state.sortPref = action.payload;
2222
},
2323
enableRefuel: (state, action) => {
24-
state.refuelEnabled = action.payload
25-
}
24+
state.refuelEnabled = action.payload;
25+
},
2626
},
2727
});
2828

2929
export default quotesSlice.reducer;
30-
export const { setQuotes, setBestRoute, setSortPref, enableRefuel } = quotesSlice.actions;
30+
export const { setQuotes, setBestRoute, setSortPref, enableRefuel } =
31+
quotesSlice.actions;

src/types/index.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export interface WidgetProps {
2323
defaultSourceToken?: string;
2424
defaultDestToken?: string;
2525

26-
locale?: string;
26+
// To enable only single tx quotes
27+
singleTxOnly?: boolean;
28+
29+
locale?: string;
2730
customize?: Customize;
2831
}
2932

0 commit comments

Comments
 (0)