Skip to content

Commit

Permalink
feat: add currency type in alert
Browse files Browse the repository at this point in the history
  • Loading branch information
baptistr committed Jul 31, 2024
1 parent cb165e7 commit d62e816
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ ROLE_ALERT=YOUR_ROLE_ID
ROLE_FR=YOUR_ROLE_ID
ROLE_EN=YOUR_ROLE_ID

# EMOJIS
EMOJI_USDC=YOUR_EMOJI_ID
EMOJI_XDAI=YOUR_EMOJI_ID

# MYSQL
MYSQL_HOST=HOST
MYSQL_USER=USER
Expand Down
34 changes: 32 additions & 2 deletions _constants/blockchain.constants.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions controllers/gnosisController.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class RealtController {
const value = await YAMcontract.showOffer(offerId);

const formattedValue = {
offerToken: value[0],
buyerToken: value[1],
offerToken: value[0].toLowerCase(),
buyerToken: value[1].toLowerCase(),
seller: value[2],
buyer: value[3] === '0x0000000000000000000000000000000000000000' ? null : value[3],
price: +formatPrice(value[4]),
Expand Down
17 changes: 10 additions & 7 deletions discord/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import RealtController from '../controllers/realtController.js';
import UserController from '../controllers/userController.js';
import GnosisController from '../controllers/gnosisController.js';
import commands from './commands.js';
import { flags, typePropertyNames } from '../_constants/index.js';
import { flags, typePropertyNames, STABLE_COINS } from '../_constants/index.js';

const {
NODE_ENV,
Expand All @@ -36,14 +36,15 @@ let params = {};
let messageAlertId;
let messageLanguageId;

const blockQuoteContent = (delta, quantity, newYield, id, name, image, lang = 'en') => {
const blockQuoteContent = (delta, quantity, newYield, id, name, image, lang = 'en', buyerToken) => {
const token = Object.prototype.hasOwnProperty.call(STABLE_COINS, buyerToken) ? STABLE_COINS[buyerToken] : null;
let content;
switch (lang) {
case 'fr':
content = {
title: `:link: ${name}`,
url: `https://yam.realtoken.network/offer/${id}`,
description: `:chart_with_upwards_trend: Yield de \`${newYield} %\`\n${delta}\n:1234: Quantité disponible : \`${quantity}\``,
description: `:chart_with_upwards_trend: Yield de \`${newYield} %\`\n${delta}\n:1234: Quantité disponible : \`${quantity}\`${token ? `\nDevise : ${token.emoji} (${token.name})` : ''}`,
color: 16777215,
timestamp: new Date(),
image: {
Expand All @@ -58,7 +59,7 @@ const blockQuoteContent = (delta, quantity, newYield, id, name, image, lang = 'e
content = {
title: `:link: ${name}`,
url: `https://yam.realtoken.network/offer/${id}`,
description: `:chart_with_upwards_trend: Offer Yield of \`${newYield} %\`\n${delta}\n:1234: Available quantity : \`${quantity}\``,
description: `:chart_with_upwards_trend: Offer Yield of \`${newYield} %\`\n${delta}\n:1234: Available quantity : \`${quantity}\`${token ? `\nCurrency : ${token.emoji} (${token.name})` : ''}`,
color: 16777215,
timestamp: new Date(),
image: {
Expand Down Expand Up @@ -102,13 +103,15 @@ const yamOffer = async () => {
continue;
}

const { availableAmount, offerToken, buyer, price } = offer;
const { availableAmount, offerToken, buyerToken, buyer, price } = offer;

console.log('offer', offer);

if (buyer) { // if the offer is private
continue;
}

const property = properties.find((prop) => prop.uuid.toLowerCase() === offerToken.toLowerCase());
const property = properties.find((prop) => prop.uuid.toLowerCase() === offerToken);

if (!property) {
console.error('No property found');
Expand Down Expand Up @@ -158,7 +161,7 @@ const yamOffer = async () => {
const member = await guild.members.fetch(userId);

const deltaPriceMessage = generateDeltaPrice(deltaPrice, lang);
member.send(blockQuoteContent(deltaPriceMessage, availableAmount, newYield, offerId, name, imageLink[0], lang));
member.send(blockQuoteContent(deltaPriceMessage, availableAmount, newYield, offerId, name, imageLink[0], lang, buyerToken));
} catch (error) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ Link to access the project : [Discord](https://discord.gg/Fexax4DYYc)

---

## TODO (for 2024)
## TODO (for S2 2024)

- [ ] Switch programming language from JS to TS in entire project
- [ ] Enable modification of default notification settings from an admin area on Discord (currently managed via a JSON file and requires a server restart to apply changes)
- [ ] Add filtering option for tokens that people are whitelisted
- [ ] Develop a Telegram version of the bot using the same functions as the current bot for synergy
- [ ] Add an option in the notification settings to hide properties with hasTenants set to false (configurable per user)
- [ ] Display the currency type of the offer in messages
- [x] Display the currency type of the offer in messages
- [ ] Make notifications configurable from a website with better UI/UX than Discord, enabling less experienced users to use the bot easily


Expand Down

0 comments on commit d62e816

Please sign in to comment.