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

Adds validations for user login, wallet and enough money #186

Merged
merged 16 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 15 additions & 19 deletions components/stock-card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,21 @@ export const Card = ({ stock }) => {
const router = useRouter();

const getStockOperation = () => {
if (router.pathname == '/trading') {
return (
<StockOperation
stockId={stock.stockId}
name={stock.name}
price={stock.price}
availableQty={stock.quantity}
/>
);
} else {
return (
<StockOperation
stockId={stock.stockId}
name={stock.stockName}
price={stock.initialStockValue}
availableQty={stock.quantity}
/>
);
}
return router.pathname == '/trading' ? (
<StockOperation
stockId={stock.stockId}
name={stock.name}
price={stock.price}
availableQty={stock.quantity}
/>
) : (
<StockOperation
stockId={stock.stockId}
name={stock.stockName}
price={stock.initialStockValue}
availableQty={stock.quantity}
/>
);
};
return (
<div className="stock-card">
Expand Down
14 changes: 6 additions & 8 deletions components/stock-operation-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const StockOperationModal = (props) => {
} = props;

const [quantity, setQuantity] = useState('');
const [isUserLoggedIn, setIsUserLoggedIn] = useState('');
const [userMoney, setUserMoney] = useState();
const [isUserLoggedIn, setIsUserLoggedIn] = useState('false');
Rucha1499 marked this conversation as resolved.
Show resolved Hide resolved
const [userMoney, setUserMoney] = useState(0);

const validateQuantity = (quantity) => {
if (quantity > availableQty) {
Expand All @@ -44,12 +44,10 @@ const StockOperationModal = (props) => {
});
const { wallet } = await response.json();
if (Object.keys(wallet).length === 0) return setUserMoney(0);
else {
const {
currencies: { dinero },
} = wallet;
setUserMoney(dinero);
}
const {
currencies: { dinero },
} = wallet;
setUserMoney(dinero);
};

getUserWallet();
Expand Down