Skip to content

Commit

Permalink
add production variables
Browse files Browse the repository at this point in the history
  • Loading branch information
radekm2000 committed Jun 13, 2024
1 parent b603a29 commit 300d596
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 26 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@ This app is a simplified version of **Vinted**, following a similar layout. Belo
- **Frontend:**
- React using Vite.



## Integration with discord

**Discord commands**

- You can check your top tokens in binance wallet, however **BINANCE_API_KEY** and **BINANCE_SECRET_KEY** is required in **ENV** file
![BinanceTokens](/readmeImages/BinanceAccountCommand.png)

- Profile
![Profile Command](/readmeImages/Profile%20command.png)
- Inventory + removing product ![Inventory command](/readmeImages/Inventory%20command.png)
Expand Down
1 change: 1 addition & 0 deletions client/ecommerce/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_BASE_URL=https://ecommerce-123.onrender.com
8 changes: 2 additions & 6 deletions client/ecommerce/src/api/axios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ import { ResponseOAuthInterceptor } from "./response-auth.interceptor";
import { FeedbackFormData } from "../components/FeedbackDialog";
import { ResponseErrorInterceptor } from "./responseError.interceptor";
const LIMIT = 8;
const baseUrl = "http://localhost:3000";
// if (import.meta.env.VITE_NETLIFY == "true") {
// baseUrl = "https://ecommerce-123.onrender.com";
// } else {
// baseUrl = "http://localhost:3000";
// }
const baseUrl = import.meta.env.VITE_BASE_URL;

const ACCESS_TOKEN_KEY = "accessToken";

export const axiosApi = axios.create({
Expand Down
7 changes: 5 additions & 2 deletions client/ecommerce/src/components/DiscordSignInButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { Box, BoxProps, Link, Typography } from "@mui/material";
import { DiscordIcon } from "./DiscordIcon";

export const DiscordSignInButton = (props: BoxProps) => {
const baseURL = import.meta.env.VITE_BASE_URL;
return (
<Box {...props}>
<Link
href={`http://localhost:3000/auth/discord/login`}
href={`${baseURL}/auth/discord/login`}
sx={{
display: "flex",
alignItems: "center",
Expand All @@ -20,7 +21,9 @@ export const DiscordSignInButton = (props: BoxProps) => {
},
}}
>
<DiscordIcon sx={{ color: "#fff", marginRight: "10px", height: '40px' }} />
<DiscordIcon
sx={{ color: "#fff", marginRight: "10px", height: "40px" }}
/>
<Typography sx={{ fontSize: "14px", fontWeight: 400, color: "#fff" }}>
SIGN IN
</Typography>
Expand Down
3 changes: 3 additions & 0 deletions client/ecommerce/src/components/pages/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import { useAllProducts } from "../../hooks/useAllProducts";
import { PaginatedProducts } from "../PaginatedProducts";
import { MainPageSkeleton } from "../skeletons/MainPageSkeleton";
import { NotAuthed } from "../NotAuthed";
import { useLocation } from "wouter";

export const MainPage = () => {
const location = useLocation();
console.log(location);
const { user, setUser } = useUserContext();
const { data: products, isLoading: isProductsDataLoading } = useAllProducts();
const {
Expand Down
Binary file added readmeImages/BinanceAccountCommand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions server/ecommerce/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/ecommerce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@types/jsonwebtoken": "^9.0.5",
"@types/passport-oauth2": "^1.4.15",
"bcrypt": "^5.1.1",
"binance-api-node": "^0.12.7",
"cookie-parser": "^1.4.6",
"discord-api-types": "^0.37.84",
"discord.js": "^14.15.2",
Expand Down
6 changes: 4 additions & 2 deletions server/ecommerce/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ export class AuthController {
response.cookie('refreshToken', refreshToken, {
httpOnly: true,
maxAge: 60 * 60 * 1000,
secure: true,
});

if (process.env.IS_DEV == 'true') {
response.redirect('http://localhost:5173');
return response.redirect('http://localhost:5173');
} else {
response.redirect('https://exquisite-pasca-338883.netlify.app');
return response.redirect('https://exquisite-pasca-338883.netlify.app');
}
}
}
5 changes: 4 additions & 1 deletion server/ecommerce/src/auth/utils/DiscordStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export class DiscordStrategy extends PassportStrategy(Strategy, 'discord') {
tokenURL: TOKEN_URL,
clientID: process.env.DISCORD_CLIENT_ID ?? '',
clientSecret: process.env.DISCORD_CLIENT_SECRET ?? '',
callbackURL: process.env.DISCORD_REDIRECT_URL ?? '',
callbackURL:
process.env.IS_DEV == 'true'
? process.env.DISCORD_REDIRECT_URL_DEV
: process.env.DISCORD_REDIRECT_URL_PRO,
scope: ['identify', 'guilds'],
} as StrategyOptions);
this.logger = new Logger(DiscordStrategy.name);
Expand Down
16 changes: 1 addition & 15 deletions server/ecommerce/src/binance/binance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ export class BinanceService {
balancesWithTotalValueCalculated,
);

const revertedBalances = this.revertBalances(sortedBalances);

const topBalances = revertedBalances.slice(0, numberOfTopBalances);
const topBalances = sortedBalances.slice(0, numberOfTopBalances);

return topBalances;
};
Expand All @@ -84,18 +82,6 @@ export class BinanceService {
);
};

private revertBalances = (
balances: BinanceBalanceWithTotalValueAndSymbol[],
) => {
return balances.map((balance) => ({
asset: balance.asset,
free: balance.free,
locked: balance.locked,
symbol: balance.symbol,
totalValue: balance.totalValue,
}));
};

private addTotalValueAndCurrencySymbolToBalances = async (
balances: BinanceBalance[],
currencyName?: string,
Expand Down
11 changes: 11 additions & 0 deletions server/ecommerce/src/discord-bot/src/discordbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,19 @@ export class DiscordBot {
};

private handleCommand = async (interaction: ChatInputCommandInteraction) => {
const userId = interaction.user.id;
const command = this.commands.get(interaction.commandName);
const commandName = interaction.commandName;
if (!command) return;
if (
commandName == 'binance-account' &&
userId !== process.env.MY_DISCORD_ID
) {
await interaction.reply({
content:
'You are not authorized to use this command! Only project owner can use this command',
});
}
try {
await command.execute(interaction);
} catch (error) {
Expand Down

0 comments on commit 300d596

Please sign in to comment.