Skip to content

Commit b9db3fb

Browse files
authored
set default token in CreateStream (#87)
* set default token * prettify
1 parent e29535f commit b9db3fb

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

ui/lib/CreateStream.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,22 @@ const CreateStream = (props: CreateStreamProps) => {
229229
};
230230

231231
// Get your current chainID
232-
let targetChainId: number | undefined;
233-
if (chain) {
234-
targetChainId = chain.id;
235-
}
232+
const targetChainId = chain ? chain.id : undefined;
236233

237-
// reset selectedToken if chainId changes
238234
useEffect(() => {
235+
// Reset the selectedToken when the targetChainId changes
239236
setSelectedToken(null);
240-
}, [targetChainId]);
237+
238+
// Filter the tokens based on the chainId
239+
const filteredTokens = props.tokenList.filter(
240+
(token) => token.chainId === targetChainId,
241+
);
242+
243+
// If there's only one token, set it as the selected token
244+
if (filteredTokens.length === 1) {
245+
setSelectedToken(filteredTokens[0]);
246+
}
247+
}, [props.tokenList, targetChainId]);
241248

242249
// Select the payment token among tokens with the same chainID
243250
const Step1 = () => {

0 commit comments

Comments
 (0)