Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store custom link in select dropdown option #33

Merged
merged 1 commit into from
Nov 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions packages/react-app/src/views/TokenSwap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ export default function TokenSwap({
const approveTokenAllowance = async ({ maxApproval, tokenInContract }) => {
// const decimals = await getTokenDetails({ token });
// FIX: Harcoded decimals value
const newAllowance = ethers.utils.parseUnits(maxApproval, await tokenInContract.decimals());
console.log("maxApproval", maxApproval);
const newAllowance = ethers.utils.parseUnits(maxApproval.toString(), await tokenInContract.decimals());
const res = await tokenInContract.approve(readContracts.MoonSwap.address, newAllowance);
await res.wait(1);
};
Expand All @@ -138,6 +139,8 @@ export default function TokenSwap({
const signer = userSigner;

const inContract = new ethers.Contract(tokenInAddress, ERC20ABI, signer);
console.log("tokenInAddress: ", tokenInAddress);
console.log("tokenOutAddress: ", tokenOutAddress);

const currentAllowance = await checkAllowance(tokenInAddress, signer, readContracts.MoonSwap.address);
const roundedSwapInValue = Math.round(swapValueIn);
Expand Down Expand Up @@ -244,6 +247,35 @@ export default function TokenSwap({
);
}

const [tokenMetaDataOptions, setTokenMetaDataOptions] = useState({
"0x01be23585060835e02b77ef475b0cc51aa1e0709": {
label: "LINK",
symbol: "LINK",
},
});

useEffect(() => {
if (tokenInMetadata && tokenInMetadata.name) {
const options = { ...tokenMetaDataOptions };
options[tokenInAddress] = {
label: tokenInMetadata.name,
symbol: tokenInMetadata.symbol,
};
setTokenMetaDataOptions(options);
}
}, [tokenInMetadata]);

useEffect(() => {
if (tokenOutMetadata && tokenOutMetadata.name) {
const options = { ...tokenMetaDataOptions };
options[tokenOutAddress] = {
label: tokenOutMetadata.name,
symbol: tokenOutMetadata.symbol,
};
setTokenMetaDataOptions(options);
}
}, [tokenOutMetadata]);

return (
<div
style={{
Expand Down Expand Up @@ -337,8 +369,13 @@ export default function TokenSwap({
setLinkUsdValueIn(0);
}}
>
{Object.keys(tokenMetaDataOptions).map(key => (
<Select.Option key={key} value={key.toString()}>
{tokenMetaDataOptions[key].symbol}
</Select.Option>
))}
<Select.Option value={""}>Custom Token</Select.Option>
<Select.Option value={tokenList[0]}>LINK</Select.Option>
{/* <Select.Option value={tokenList[0]}>LINK</Select.Option> */}
</Select>
}
/>
Expand Down Expand Up @@ -414,8 +451,13 @@ export default function TokenSwap({
setLinkUsdValueOut(0);
}}
>
{Object.keys(tokenMetaDataOptions).map(key => (
<Select.Option label={tokenMetaDataOptions[key].symbol} key={key} value={key.toString()}>
{tokenMetaDataOptions[key].symbol}
</Select.Option>
))}
<Select.Option value={""}>Custom Token</Select.Option>
<Select.Option value={tokenList[0]}>LINK</Select.Option>
{/* <Select.Option value={tokenList[0]}>LINK</Select.Option> */}
</Select>
}
/>
Expand Down