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

Add index and resolve the swap list loading issue #20

Merged
merged 1 commit into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
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
32 changes: 18 additions & 14 deletions packages/react-app/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -497,20 +497,24 @@ function App(props) {

<Switch>
<Route exact path="/">
<SwapList
address={address}
userSigner={userSigner}
mainnetProvider={mainnetProvider}
localProvider={localProvider}
yourLocalBalance={yourLocalBalance}
price={price}
tx={tx}
writeContracts={writeContracts}
readContracts={readContracts}
purpose={purpose}
setPurposeEvents={setPurposeEvents}
chainId={selectedChainId}
/>
{readContracts.MoonSwap ? (
<SwapList
address={address}
userSigner={userSigner}
mainnetProvider={mainnetProvider}
localProvider={localProvider}
yourLocalBalance={yourLocalBalance}
price={price}
tx={tx}
writeContracts={writeContracts}
readContracts={readContracts}
purpose={purpose}
setPurposeEvents={setPurposeEvents}
chainId={selectedChainId}
/>
) : (
<h1>Loading...</h1>
)}
</Route>
<Route exact path="/swap">
<TokenSwap
Expand Down
6 changes: 3 additions & 3 deletions packages/react-app/src/components/SwapItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useThemeSwitcher } from "react-css-theme-switcher";
import { Typography, Button } from "antd";
import { NETWORK } from "../constants";

export default function SwapItem({ onClick, hash, localProvider, chainId, ...props }) {
export default function SwapItem({ onClick, hash, index, localProvider, chainId, ...props }) {
const { currentTheme } = useThemeSwitcher();
const [loading, updateLoading] = useState(true);
const [txData, updateTxData] = useState({});
Expand Down Expand Up @@ -36,7 +36,8 @@ export default function SwapItem({ onClick, hash, localProvider, chainId, ...pro
fontSize: props.fontSize ? props.fontSize : 20,
}}
>
<div>
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", width: "100%" }}>
<Typography>{index}</Typography>
<Typography.Text copyable={{ text: hash }}>
<a
style={{ color: currentTheme === "light" ? "#222222" : "#ddd" }}
Expand All @@ -49,7 +50,6 @@ export default function SwapItem({ onClick, hash, localProvider, chainId, ...pro
</Typography.Text>
<Button onClick={onClick}>Commit Swap</Button>
</div>
{loading ? <div style={{ fontStyle: "italic", color: "#efefef" }}>Loading...</div> : <button></button>}
</div>
</div>
);
Expand Down
12 changes: 11 additions & 1 deletion packages/react-app/src/views/SwapList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function SwapList({
chainId,
}) {
const history = useHistory();
const { id } = useParams();

const [activeSwaps, setActiveSwaps] = useState([]);
const [swapIds, setSwapIds] = useState([]);

Expand All @@ -41,6 +41,14 @@ export default function SwapList({
}
};

useEffect(() => {
console.log("active Swaps", activeSwaps);
}, []);

useEffect(() => {
console.log("readContract", readContracts);
}, []);

useEffect(async () => {
getActiveSwaps();
}, [activeSwaps]);
Expand All @@ -57,9 +65,11 @@ export default function SwapList({
<div
style={{
width: "80%",
margin: "auto",
}}
>
<SwapItem
index={swapIds[index]}
onClick={() => {
history.push(`/swap/${swapIds[index]}`);
}}
Expand Down