From ceebf9f7669caa74f4f4c0469e84bdefae6c9dd3 Mon Sep 17 00:00:00 2001 From: Gera Barboni Date: Thu, 23 Oct 2025 09:32:02 -0300 Subject: [PATCH 1/4] update URLs --- components/notification/index.js | 37 ++++----- utils/addresses.js | 137 ++++++++++++++++--------------- 2 files changed, 87 insertions(+), 87 deletions(-) diff --git a/components/notification/index.js b/components/notification/index.js index ef1c3d5..e587656 100644 --- a/components/notification/index.js +++ b/components/notification/index.js @@ -1,13 +1,13 @@ -import styles from '../../styles/dapp.module.scss'; -import { useState, useEffect } from 'react'; -import { BsBell } from 'react-icons/bs'; -import { useSignMessage, useAccount } from 'wagmi'; -import { api } from '../../utils/addresses'; -import tooltip from '../../components/tooltip'; +import styles from "../../styles/dapp.module.scss"; +import { useState, useEffect } from "react"; +import { BsBell } from "react-icons/bs"; +import { useSignMessage, useAccount } from "wagmi"; +import { api } from "../../utils/addresses"; +import tooltip from "../../components/tooltip"; export default function Notification({ collateral }) { const [showTelegramModal, setShowTelegramModal] = useState(false); - const [registrationCode, setRegistrationCode] = useState(''); + const [registrationCode, setRegistrationCode] = useState(""); const [isLoading, setIsLoading] = useState(false); const [alreadyRegistered, setAlreadyRegistered] = useState(false); @@ -33,18 +33,17 @@ export default function Notification({ collateral }) { if (!address) return; setIsLoading(true); const response = await fetch(`${api.bot}/subscription/${address}`, { - method: 'GET', + method: "GET", headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", }, }); if (!response.ok) { - throw new Error('Failed to register for notifications'); + throw new Error("Failed to register for notifications"); } const { data } = await response.json(); - console.log({ data, collateral }); setAlreadyRegistered( data.find((item) => item.collateralName === collateral) ); @@ -67,9 +66,9 @@ export default function Notification({ collateral }) { // Call API to register for notifications const response = await fetch(`${api.bot}/registration/generate-code`, { - method: 'POST', + method: "POST", headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", }, body: JSON.stringify({ walletAddress: address, @@ -79,16 +78,16 @@ export default function Notification({ collateral }) { }); if (!response.ok) { - throw new Error('Failed to register for notifications'); + throw new Error("Failed to register for notifications"); } const { registrationCode } = await response.json(); setRegistrationCode(registrationCode); // setShowModal(true); } catch (error) { - console.error('Error setting up notifications:', error); + console.error("Error setting up notifications:", error); tooltip.error({ - content: 'Failed to setup notifications. Please try again.', + content: "Failed to setup notifications. Please try again.", duration: 5000, }); } finally { @@ -131,7 +130,7 @@ export default function Notification({ collateral }) { <>
  • Open our Telegram bot @BitProtocolBot
  • - Send the following code to the bot:{' '} + Send the following code to the bot:{" "} {registrationCode}
  • The bot will confirm your registration
  • @@ -152,7 +151,7 @@ export default function Notification({ collateral }) {
    {registrationCode ? ( handleNotificationSetup(false)} > - {isLoading ? 'Signing...' : 'Sign'} + {isLoading ? "Signing..." : "Sign"} )} diff --git a/utils/addresses.js b/utils/addresses.js index cf95e97..909dd1d 100644 --- a/utils/addresses.js +++ b/utils/addresses.js @@ -1,118 +1,119 @@ export const addresses = { troveManager: { - [23294]: '0xC91EDf48269D0373c17718F6D281D34908a5700d', - [23295]: '', // ... - [19236265]: '', + [23294]: "0xC91EDf48269D0373c17718F6D281D34908a5700d", + [23295]: "", // ... + [19236265]: "", }, troveManagerGetter: { - [23294]: '0x674487D9b51E9d14778f260e0B259fF9d61bB361', - [23295]: '', - [19236265]: '', + [23294]: "0x674487D9b51E9d14778f260e0B259fF9d61bB361", + [23295]: "", + [19236265]: "", }, factory: { - [23294]: '0xD58b7e6aC330a4bB7DA02AC626aaC527B0c8c6Cc', - [23295]: '', - [19236265]: '', + [23294]: "0xD58b7e6aC330a4bB7DA02AC626aaC527B0c8c6Cc", + [23295]: "", + [19236265]: "", }, priceFeed: { - [23294]: '0xd35c6AAA15F04C29E09635FB08f26C288ccE87Dd', - [23295]: '', - [19236265]: '', + [23294]: "0xd35c6AAA15F04C29E09635FB08f26C288ccE87Dd", + [23295]: "", + [19236265]: "", }, borrowerOps: { - [23294]: '0x9be6f065aFC34ca99e82af0f0BfB9a01E3f919eE', - [23295]: '', - [19236265]: '', + [23294]: "0x9be6f065aFC34ca99e82af0f0BfB9a01E3f919eE", + [23295]: "", + [19236265]: "", }, debtToken: { - [23294]: '0xA14167756d9F86Aed12b472C29B257BBdD9974C2', - [23295]: '', - [19236265]: '', + [23294]: "0xA14167756d9F86Aed12b472C29B257BBdD9974C2", + [23295]: "", + [19236265]: "", }, stabilityPool: { - [23294]: '0x5aa111d889E9C6e3cca8A86430665b5CE7DfcdFf', - [23295]: '', - [19236265]: '', + [23294]: "0x5aa111d889E9C6e3cca8A86430665b5CE7DfcdFf", + [23295]: "", + [19236265]: "", }, vault: { - [23294]: '0x6D4b43f6378d0b74EE8BF2F88630103518E0af30', - [23295]: '', - [19236265]: '', + [23294]: "0x6D4b43f6378d0b74EE8BF2F88630103518E0af30", + [23295]: "", + [19236265]: "", }, boostCalculator: { - [23294]: '', - [23295]: '0xc340f4fDb60F18BB5F7e736E848Eb38849d62b4F', - [19236265]: '', + [23294]: "", + [23295]: "0xc340f4fDb60F18BB5F7e736E848Eb38849d62b4F", + [19236265]: "", }, bitGov: { - [23294]: '0x94E4b9C5B544EdD825F62fBE094E90C7Cc363B91', - [23295]: '', - [19236265]: '', + [23294]: "0x94E4b9C5B544EdD825F62fBE094E90C7Cc363B91", + [23295]: "", + [19236265]: "", }, tokenLocker: { - [23294]: '0x32F50d6662fbe972713ac39DBA98C0C526017f2C', - [23295]: '', - [19236265]: '', + [23294]: "0x32F50d6662fbe972713ac39DBA98C0C526017f2C", + [23295]: "", + [19236265]: "", }, incentiveVoting: { - [23294]: '0x8aC0f9Ad26a36C76d78899b42E6aBd0d805A46A6', - [23295]: '', - [19236265]: '', + [23294]: "0x8aC0f9Ad26a36C76d78899b42E6aBd0d805A46A6", + [23295]: "", + [19236265]: "", }, bitGovLp: { - [23294]: '', - [23295]: '0x15F2b1Dc4c427A8a022ba1Bb457fcbb1172E1855', - [19236265]: '', + [23294]: "", + [23295]: "0x15F2b1Dc4c427A8a022ba1Bb457fcbb1172E1855", + [19236265]: "", }, bitGovDeposit: { - [23294]: '', - [23295]: '0x2719Adf8D2D03fBE0Cc7506AAc33b213538c5112', - [19236265]: '', + [23294]: "", + [23295]: "0x2719Adf8D2D03fBE0Cc7506AAc33b213538c5112", + [19236265]: "", }, bitUsdLp: { - [23294]: '', - [23295]: '0xC682Eb99486ACDD5a896bda6bD3198FE26f78Bb6', - [19236265]: '', + [23294]: "", + [23295]: "0xC682Eb99486ACDD5a896bda6bD3198FE26f78Bb6", + [19236265]: "", }, bitUsdDeposit: { - [23294]: '', - [23295]: '0x4dcd40e74504aAd595A308a33bd73DB39B55815b', - [19236265]: '', + [23294]: "", + [23295]: "0x4dcd40e74504aAd595A308a33bd73DB39B55815b", + [19236265]: "", }, multiCollateralHintHelpers: { - [23294]: '0xA0576AD90c960faf8a52B8D5647BF88A30fbc8e1', - [23295]: '', - [19236265]: '', + [23294]: "0xA0576AD90c960faf8a52B8D5647BF88A30fbc8e1", + [23295]: "", + [19236265]: "", }, bitUsdTWAP: { - [23294]: '', - [23295]: '0x793EA3ef890570f6935697CDc61f769a04Ed63C2', - [19236265]: '', + [23294]: "", + [23295]: "0x793EA3ef890570f6935697CDc61f769a04Ed63C2", + [19236265]: "", }, bitUsdLpOracle: { - [23294]: '', - [23295]: '0x6e0DfB9a7159e557273287dD4E46485fCA966C5c', - [19236265]: '', + [23294]: "", + [23295]: "0x6e0DfB9a7159e557273287dD4E46485fCA966C5c", + [19236265]: "", }, bitGovTWAP: { - [23294]: '', - [23295]: '0xD4a5b94EDEa30f9A07BB5270B6bf766aA760615F', - [19236265]: '', + [23294]: "", + [23295]: "0xD4a5b94EDEa30f9A07BB5270B6bf766aA760615F", + [19236265]: "", }, bitGovLpOracle: { - [23294]: '', - [23295]: '0xB1066f2B3E8fc94051295D9A63330C2bd31C00a5', - [19236265]: '', + [23294]: "", + [23295]: "0xB1066f2B3E8fc94051295D9A63330C2bd31C00a5", + [19236265]: "", }, }; export const rpc = { - [23294]: 'https://sapphire.oasis.io', - [23295]: 'https://testnet.sapphire.oasis.dev/', - [19236265]: '', + [23294]: "https://sapphire.oasis.io", + [23295]: "https://testnet.sapphire.oasis.dev/", + [19236265]: "", }; export const api = { - bot: 'https://api.bitusd.finance/api', - // bot: 'http://localhost:3000/api', + // bot: 'https://api.bitusd.finance/api', + bot: "http://localhost:4001/api/v1", + //TODO: Update with production URL }; From c2ca00217ec97b76c906e8425963fcf54ecd70be Mon Sep 17 00:00:00 2001 From: Gera Barboni Date: Thu, 23 Oct 2025 09:41:06 -0300 Subject: [PATCH 2/4] blockchain.js updates --- hook/blockchain.js | 196 ++++++++++++++++++++++----------------------- 1 file changed, 98 insertions(+), 98 deletions(-) diff --git a/hook/blockchain.js b/hook/blockchain.js index 165b276..6534324 100644 --- a/hook/blockchain.js +++ b/hook/blockchain.js @@ -4,44 +4,44 @@ import { useEffect, useMemo, useCallback, -} from 'react'; -import { ethers } from 'ethers'; +} from "react"; +import { ethers } from "ethers"; import { useAccount, usePublicClient, useBalance, useWalletClient, useConnectorClient, -} from 'wagmi'; -import { addresses, rpc } from '../utils/addresses'; -import { collateralNames } from '../utils/collateralNames'; -import TroveManagerGettersABI from '../abi/TroveManagerGetters'; -import TroveManagerABI from '../abi/TroveManager'; -import BorrowerOperationsABI from '../abi/BorrowerOperations'; -import FactoryABI from '../abi/Factory'; -import PriceFeedABI from '../abi/PriceFeed'; -import SortedTrovesABI from '../abi/SortedTroves'; -import DebtTokenABI from '../abi/DebtToken'; -import StabilityPoolABI from '../abi/StabilityPool'; -import BoostCalculatorABI from '../abi/BoostCalculator'; -import VaultABI from '../abi/Vault'; -import BitGovABI from '../abi/token'; -import TokenLockerABI from '../abi/tokenLocker'; -import IncentiveVotingABI from '../abi/IncentiveVoting'; -import BitLpTokenABI from '../abi/BitLpTokenPool'; -import MultiCollateralHintHelpersABI from '../abi/MultiCollateralHintHelpers'; -import BitLpOracleABI from '../abi/BitLpOracle'; -import TWAPOracleABI from '../abi/TWAPOracle'; -import { fromBigNumber } from '../utils/helpers'; -import { useSignatureCheck } from './useSignatureCheck'; -import BigNumber from 'bignumber.js'; -import * as sapphire from '@oasisprotocol/sapphire-paratime'; +} from "wagmi"; +import { addresses, rpc } from "../utils/addresses"; +import { collateralNames } from "../utils/collateralNames"; +import TroveManagerGettersABI from "../abi/TroveManagerGetters"; +import TroveManagerABI from "../abi/TroveManager"; +import BorrowerOperationsABI from "../abi/BorrowerOperations"; +import FactoryABI from "../abi/Factory"; +import PriceFeedABI from "../abi/PriceFeed"; +import SortedTrovesABI from "../abi/SortedTroves"; +import DebtTokenABI from "../abi/DebtToken"; +import StabilityPoolABI from "../abi/StabilityPool"; +import BoostCalculatorABI from "../abi/BoostCalculator"; +import VaultABI from "../abi/Vault"; +import BitGovABI from "../abi/token"; +import TokenLockerABI from "../abi/tokenLocker"; +import IncentiveVotingABI from "../abi/IncentiveVoting"; +import BitLpTokenABI from "../abi/BitLpTokenPool"; +import MultiCollateralHintHelpersABI from "../abi/MultiCollateralHintHelpers"; +import BitLpOracleABI from "../abi/BitLpOracle"; +import TWAPOracleABI from "../abi/TWAPOracle"; +import { fromBigNumber } from "../utils/helpers"; +import { useSignatureCheck } from "./useSignatureCheck"; +import BigNumber from "bignumber.js"; +import * as sapphire from "@oasisprotocol/sapphire-paratime"; export const BlockchainContext = createContext({ // STATES deposits: 0.0, debt: 0.0, - troveStatus: '', + troveStatus: "", balance: 0, collaterals: {}, systemTVL: 0, @@ -128,7 +128,7 @@ export const BlockchainContextProvider = ({ children }) => { // STATES const [deposits, setDeposits] = useState(0.0); const [debt, setDebt] = useState(0.0); - const [troveStatus, setTroveStatus] = useState(''); + const [troveStatus, setTroveStatus] = useState(""); const [balance, setBalance] = useState(0); const [collaterals, setCollaterals] = useState({}); const [userTroves, setUserTroves] = useState({}); @@ -150,8 +150,8 @@ export const BlockchainContextProvider = ({ children }) => { const [totalSystemDebt, setTotalSystemDebt] = useState(0); const [currentState, setCurrentState] = useState(false); const [currentWaitInfo, setCurrentWaitInfo] = useState({ - type: '', - info: '', + type: "", + info: "", }); const [systemWeek, setWeek] = useState(0); // GET DATA LOCK TO AVOID TOO MANY CALLS @@ -316,7 +316,7 @@ export const BlockchainContextProvider = ({ children }) => { const tx = await vault.batchClaimRewards( account.address, - '0x0000000000000000000000000000000000000000', + "0x0000000000000000000000000000000000000000", [ addresses.troveManager[account.chainId], addresses.stabilityPool[account.chainId], @@ -431,7 +431,7 @@ export const BlockchainContextProvider = ({ children }) => { const tx = await walletClient.writeContract({ account: account.address, abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE - functionName: 'approve', + functionName: "approve", address: collateralAddr, args, gas: await publicClient.estimateGas(args), @@ -652,7 +652,7 @@ export const BlockchainContextProvider = ({ children }) => { // QUERY FUNCTIONS const getData = useCallback(async () => { - if (typeof window === 'undefined') return; + if (typeof window === "undefined") return; const signatures = await getSignatures(); @@ -703,7 +703,7 @@ export const BlockchainContextProvider = ({ children }) => { truncatedDebtAmount: new BigNumber(hints[2]._hex).toFixed(), }; } catch (error) { - console.log('error', error); + console.log("error", error); throw error; } }; @@ -712,37 +712,37 @@ export const BlockchainContextProvider = ({ children }) => { const balanceLp = await publicClient.readContract({ abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE address: addresses.bitUsdLp[account.chainId], - functionName: 'balanceOf', + functionName: "balanceOf", args: [account.address], }); const allowanceLp = await publicClient.readContract({ abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE address: addresses.bitUsdLp[account.chainId], - functionName: 'allowance', + functionName: "allowance", args: [account.address, addresses.bitUsdDeposit[account.chainId]], }); const deposiitBalance = await publicClient.readContract({ abi: BitLpTokenABI, // JUST TO USE THE ERC20 INTERFACE address: addresses.bitUsdDeposit[account.chainId], - functionName: 'balanceOf', + functionName: "balanceOf", args: [account.address], }); const depositLpBalance = await publicClient.readContract({ abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE address: addresses.bitUsdLp[account.chainId], - functionName: 'balanceOf', + functionName: "balanceOf", args: [addresses.bitUsdDeposit[account.chainId]], }); const rewardRate = await publicClient.readContract({ abi: BitLpTokenABI, // JUST TO USE THE ERC20 INTERFACE address: addresses.bitUsdDeposit[account.chainId], - functionName: 'rewardRate', + functionName: "rewardRate", args: [], }); const totalSupply = await publicClient.readContract({ abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE address: addresses.bitUsdDeposit[account.chainId], - functionName: 'totalSupply', + functionName: "totalSupply", args: [], }); @@ -760,31 +760,31 @@ export const BlockchainContextProvider = ({ children }) => { const balanceLp = await publicClient.readContract({ abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE address: addresses.bitGovLp[account.chainId], - functionName: 'balanceOf', + functionName: "balanceOf", args: [account.address], }); const allowanceLp = await publicClient.readContract({ abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE address: addresses.bitGovLp[account.chainId], - functionName: 'allowance', + functionName: "allowance", args: [account.address, addresses.bitGovDeposit[account.chainId]], }); const depositBalance = await publicClient.readContract({ abi: BitLpTokenABI, // JUST TO USE THE ERC20 INTERFACE address: addresses.bitGovDeposit[account.chainId], - functionName: 'balanceOf', + functionName: "balanceOf", args: [account.address], }); const depositLpBalance = await publicClient.readContract({ abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE address: addresses.bitGovLp[account.chainId], - functionName: 'balanceOf', + functionName: "balanceOf", args: [addresses.bitGovDeposit[account.chainId]], }); const rewardRate = await publicClient.readContract({ abi: BitLpTokenABI, // JUST TO USE THE ERC20 INTERFACE address: addresses.bitGovDeposit[account.chainId], - functionName: 'rewardRate', + functionName: "rewardRate", args: [], }); @@ -801,7 +801,7 @@ export const BlockchainContextProvider = ({ children }) => { const weight = await publicClient.readContract({ abi: IncentiveVotingABI, address: addresses.incentiveVoting[account.chainId], - functionName: 'getReceiverWeightAt', + functionName: "getReceiverWeightAt", args: [receiver, week], }); @@ -812,7 +812,7 @@ export const BlockchainContextProvider = ({ children }) => { const currentWeeklyEmissions = await publicClient.readContract({ abi: VaultABI, address: addresses.vault[account.chainId], - functionName: 'weeklyEmissions', + functionName: "weeklyEmissions", args: [week], }); return Number(currentWeeklyEmissions); @@ -822,7 +822,7 @@ export const BlockchainContextProvider = ({ children }) => { const weight = await publicClient.readContract({ abi: IncentiveVotingABI, address: addresses.incentiveVoting[account.chainId], - functionName: 'getTotalWeightAt', + functionName: "getTotalWeightAt", args: [week], }); return Number(weight); @@ -832,7 +832,7 @@ export const BlockchainContextProvider = ({ children }) => { const votes = await publicClient.readContract({ abi: IncentiveVotingABI, address: addresses.incentiveVoting[account.chainId], - functionName: 'getAccountCurrentVotes', + functionName: "getAccountCurrentVotes", args: [account.address], }); return votes; @@ -842,19 +842,19 @@ export const BlockchainContextProvider = ({ children }) => { const tcr = await publicClient.readContract({ abi: BorrowerOperationsABI, address: addresses.borrowerOps[account.chainId], - functionName: 'getTCR', + functionName: "getTCR", args: [], }); const systemBalances = await publicClient.readContract({ abi: BorrowerOperationsABI, address: addresses.borrowerOps[account.chainId], - functionName: 'getGlobalSystemBalances', + functionName: "getGlobalSystemBalances", args: [], }); const getWeek = await publicClient.readContract({ abi: VaultABI, address: addresses.vault[account.chainId], - functionName: 'getWeek', + functionName: "getWeek", args: [], }); @@ -871,11 +871,11 @@ export const BlockchainContextProvider = ({ children }) => { const vault = await publicClient.readContract({ abi: VaultABI, address: addresses.vault[account.chainId], - functionName: 'claimableRewardAfterBoost', + functionName: "claimableRewardAfterBoost", args: [ account.address, account.address, - '0x0000000000000000000000000000000000000000', + "0x0000000000000000000000000000000000000000", trove, ], }); @@ -886,22 +886,22 @@ export const BlockchainContextProvider = ({ children }) => { const bitGovPool = await publicClient.readContract({ abi: VaultABI, address: addresses.vault[account.chainId], - functionName: 'claimableRewardAfterBoost', + functionName: "claimableRewardAfterBoost", args: [ account.address, account.address, - '0x0000000000000000000000000000000000000000', + "0x0000000000000000000000000000000000000000", addresses.bitGovDeposit[account.chainId], ], }); const bitUsdPool = await publicClient.readContract({ abi: VaultABI, address: addresses.vault[account.chainId], - functionName: 'claimableRewardAfterBoost', + functionName: "claimableRewardAfterBoost", args: [ account.address, account.address, - '0x0000000000000000000000000000000000000000', + "0x0000000000000000000000000000000000000000", addresses.bitUsdDeposit[account.chainId], ], }); @@ -917,19 +917,19 @@ export const BlockchainContextProvider = ({ children }) => { const deposits = await publicClient.readContract({ abi: StabilityPoolABI, address: addresses.stabilityPool[account.chainId], - functionName: 'getTotalDebtTokenDeposits', + functionName: "getTotalDebtTokenDeposits", args: [], }); const rewardRate = await publicClient.readContract({ abi: StabilityPoolABI, address: addresses.stabilityPool[account.chainId], - functionName: 'rewardRate', + functionName: "rewardRate", args: [], }); const accountDeposits = await publicClient.readContract({ abi: StabilityPoolABI, address: addresses.stabilityPool[account.chainId], - functionName: 'accountDeposits', + functionName: "accountDeposits", args: [account.address], }); // COMMENTED OUT UNLESS WE HAVE REWARDS @@ -948,7 +948,7 @@ export const BlockchainContextProvider = ({ children }) => { const collateralGainsByDepositor = await publicClient.readContract({ abi: StabilityPoolABI, address: addresses.stabilityPool[account.chainId], - functionName: 'getDepositorCollateralGain', + functionName: "getDepositorCollateralGain", args: [account.address], }); @@ -968,7 +968,7 @@ export const BlockchainContextProvider = ({ children }) => { const balance = await publicClient.readContract({ abi: DebtTokenABI, address: addresses.debtToken[account.chainId], - functionName: 'checkBalanceOf', + functionName: "checkBalanceOf", args: [dataDebt], }); setBitUSDBalance(fromBigNumber(balance)); @@ -978,7 +978,7 @@ export const BlockchainContextProvider = ({ children }) => { const balance = await publicClient.readContract({ abi: BitGovABI, address: addresses.bitGov[account.chainId], - functionName: 'balanceOf', + functionName: "balanceOf", args: [account.address], }); setBitGovBalance(fromBigNumber(balance)); @@ -988,7 +988,7 @@ export const BlockchainContextProvider = ({ children }) => { const balance = await publicClient.readContract({ abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE address, - functionName: 'balanceOf', + functionName: "balanceOf", args: [account.address], }); @@ -1002,7 +1002,7 @@ export const BlockchainContextProvider = ({ children }) => { const weight = await publicClient.readContract({ abi: TokenLockerABI, address: addresses.tokenLocker[account.chainId], - functionName: 'getAccountWeight', + functionName: "getAccountWeight", args: [account.address], }); setAccountWeight(Number(weight)); @@ -1012,7 +1012,7 @@ export const BlockchainContextProvider = ({ children }) => { const balance = await publicClient.readContract({ abi: TokenLockerABI, address: addresses.tokenLocker[account.chainId], - functionName: 'getAccountBalances', + functionName: "getAccountBalances", args: [account.address], }); setAccountLockAmount(Number(balance[0])); @@ -1023,7 +1023,7 @@ export const BlockchainContextProvider = ({ children }) => { const locks = await publicClient.readContract({ abi: TokenLockerABI, address: addresses.tokenLocker[account.chainId], - functionName: 'getAccountActiveLocks', + functionName: "getAccountActiveLocks", args: [account.address, 26], }); @@ -1040,7 +1040,7 @@ export const BlockchainContextProvider = ({ children }) => { const weight = await publicClient.readContract({ abi: TokenLockerABI, address: addresses.tokenLocker[account.chainId], - functionName: 'getTotalWeight', + functionName: "getTotalWeight", args: [], }); setTotalWeight(Number(weight)); @@ -1050,7 +1050,7 @@ export const BlockchainContextProvider = ({ children }) => { const amounts = await publicClient.readContract({ abi: TokenLockerABI, address: addresses.tokenLocker[account.chainId], - functionName: 'getWithdrawWithPenaltyAmounts', + functionName: "getWithdrawWithPenaltyAmounts", args: [account.address, value], }); @@ -1064,7 +1064,7 @@ export const BlockchainContextProvider = ({ children }) => { const circulation = await publicClient.readContract({ abi: DebtTokenABI, address: addresses.debtToken[account.chainId], - functionName: 'totalSupply', + functionName: "totalSupply", args: [], }); setBitUSDCirculation(fromBigNumber(circulation)); @@ -1074,7 +1074,7 @@ export const BlockchainContextProvider = ({ children }) => { const prev = await publicClient.readContract({ abi: SortedTrovesABI, address: sortedTroves, - functionName: 'getPrev', + functionName: "getPrev", args: [id], }); return prev; @@ -1084,7 +1084,7 @@ export const BlockchainContextProvider = ({ children }) => { const next = await publicClient.readContract({ abi: SortedTrovesABI, address: sortedTroves, - functionName: 'getNext', + functionName: "getNext", args: [id], }); return next; @@ -1096,7 +1096,7 @@ export const BlockchainContextProvider = ({ children }) => { const trove = await publicClient.readContract({ abi: TroveManagerABI, address: troveManagerAddr, - functionName: 'getTrove', + functionName: "getTrove", args: [account.address], }); @@ -1113,7 +1113,7 @@ export const BlockchainContextProvider = ({ children }) => { const trove = await publicClient.readContract({ abi: TroveManagerGettersABI, address: addresses.troveManagerGetter[account.chainId], - functionName: 'getTrove', + functionName: "getTrove", args: [dataTrove, troveManagerAddr], }); @@ -1141,7 +1141,7 @@ export const BlockchainContextProvider = ({ children }) => { const count = await publicClient.readContract({ abi: FactoryABI, address: addresses.factory[account.chainId], - functionName: 'troveManagerCount', + functionName: "troveManagerCount", args: [], }); @@ -1149,81 +1149,81 @@ export const BlockchainContextProvider = ({ children }) => { const address = await publicClient.readContract({ abi: FactoryABI, address: addresses.factory[account.chainId], - functionName: 'troveManagers', + functionName: "troveManagers", args: [index], }); const systemBalances = await publicClient.readContract({ abi: TroveManagerABI, address: address, - functionName: 'getEntireSystemBalances', + functionName: "getEntireSystemBalances", args: [], }); const redemptionRate = await publicClient.readContract({ abi: TroveManagerABI, address: address, - functionName: 'getRedemptionRate', + functionName: "getRedemptionRate", args: [], }); const borrowingRate = await publicClient.readContract({ abi: TroveManagerABI, address: address, - functionName: 'getBorrowingRate', + functionName: "getBorrowingRate", args: [], }); const mcr = await publicClient.readContract({ abi: TroveManagerABI, address: address, - functionName: 'MCR', + functionName: "MCR", args: [], }); const collateral = await publicClient.readContract({ abi: TroveManagerABI, address: address, - functionName: 'collateralToken', + functionName: "collateralToken", args: [], }); const maxSystemDebt = await publicClient.readContract({ abi: TroveManagerABI, address: address, - functionName: 'maxSystemDebt', + functionName: "maxSystemDebt", args: [], }); const rewardRate = await publicClient.readContract({ abi: TroveManagerABI, address: address, - functionName: 'rewardRate', + functionName: "rewardRate", args: [], }); const deploymentTime = await publicClient.readContract({ abi: TroveManagerABI, address: address, - functionName: 'systemDeploymentTime', + functionName: "systemDeploymentTime", args: [], }); const BOOTSTRAP_PERIOD = await publicClient.readContract({ abi: TroveManagerABI, address: address, - functionName: 'BOOTSTRAP_PERIOD', + functionName: "BOOTSTRAP_PERIOD", args: [], }); const redemptionFeeFloor = await publicClient.readContract({ abi: TroveManagerABI, address: address, - functionName: 'redemptionFeeFloor', + functionName: "redemptionFeeFloor", args: [], }); const baseRate = await publicClient.readContract({ abi: TroveManagerABI, address: address, - functionName: 'baseRate', + functionName: "baseRate", args: [], }); const sortedTroves = await publicClient.readContract({ abi: TroveManagerABI, address: address, - functionName: 'sortedTroves', + functionName: "sortedTroves", args: [], }); @@ -1245,7 +1245,7 @@ export const BlockchainContextProvider = ({ children }) => { ...collateralNames[collateral], address: collateral, payable: - collateral === '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + collateral === "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", }, sortedTroves, maxSystemDebt: fromBigNumber(maxSystemDebt), @@ -1271,7 +1271,7 @@ export const BlockchainContextProvider = ({ children }) => { const price = await publicClient.readContract({ abi: PriceFeedABI, address: addresses.priceFeed[account.chainId], - functionName: 'loadPrice', + functionName: "loadPrice", args: [collateral], }); return fromBigNumber(price); @@ -1281,7 +1281,7 @@ export const BlockchainContextProvider = ({ children }) => { const boost = await publicClient.readContract({ abi: BoostCalculatorABI, address: addresses.boostCalculator[account.chainId], - functionName: 'getBoostedAmount', + functionName: "getBoostedAmount", args: [account.address, 10000, 0, 100000], }); @@ -1294,14 +1294,14 @@ export const BlockchainContextProvider = ({ children }) => { const getLpTokenPrice = async (lpName) => { const lpAddress = - lpName === 'bitGov' + lpName === "bitGov" ? addresses.bitGovLpOracle[account.chainId] : addresses.bitUsdLpOracle[account.chainId]; const price = await publicClient.readContract({ abi: BitLpOracleABI, address: lpAddress, - functionName: 'getLPPrice', + functionName: "getLPPrice", args: [], }); @@ -1312,7 +1312,7 @@ export const BlockchainContextProvider = ({ children }) => { const price = await publicClient.readContract({ abi: TWAPOracleABI, address: addresses.bitGovTWAP[account.chainId], - functionName: 'consult', + functionName: "consult", args: [addresses.bitGov[account.chainId], new BigNumber(1e18).toFixed()], }); @@ -1326,7 +1326,7 @@ export const BlockchainContextProvider = ({ children }) => { const borrowingFee = await publicClient.readContract({ abi: TroveManagerABI, address: troveAddr, - functionName: 'getBorrowingFee', + functionName: "getBorrowingFee", args: [debt], }); @@ -1334,7 +1334,7 @@ export const BlockchainContextProvider = ({ children }) => { const maxFee = (fromBigNumber(borrowingFee) / fromBigNumber(debt)) * 1.2; return ethers.utils - .parseEther(maxFee.toString().replace(/,/g, '')) + .parseEther(maxFee.toString().replace(/,/g, "")) .toString(); }; @@ -1342,7 +1342,7 @@ export const BlockchainContextProvider = ({ children }) => { const surplus = await publicClient.readContract({ abi: TroveManagerABI, address: troveManager, - functionName: 'surplusBalances', + functionName: "surplusBalances", args: [account.address], }); From a682bce03c9ff89aff801e9f612e476c7264bb6a Mon Sep 17 00:00:00 2001 From: Gera Barboni Date: Wed, 29 Oct 2025 22:11:05 -0300 Subject: [PATCH 3/4] update bot env --- .gitignore | 4 +- components/notification/index.js | 83 +++++++++++++++++++++++++------- next.config.js | 18 ++++++- utils/addresses.js | 6 ++- 4 files changed, 88 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index bc1d547..bca192f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ node_modules -.next \ No newline at end of file +.next +.env +.env.local \ No newline at end of file diff --git a/components/notification/index.js b/components/notification/index.js index e587656..2460a35 100644 --- a/components/notification/index.js +++ b/components/notification/index.js @@ -15,6 +15,22 @@ export default function Notification({ collateral }) { const { address } = useAccount(); const handleTelegramSignup = () => { + // Validate that we have the necessary information + if (!collateral) { + tooltip.error({ + content: "Collateral information is not available. Please try again.", + duration: 5000, + }); + return; + } + + if (!address) { + tooltip.error({ + content: "Please connect your wallet first.", + duration: 5000, + }); + return; + } setShowTelegramModal(true); }; @@ -30,8 +46,9 @@ export default function Notification({ collateral }) { const getSubscription = async () => { try { - if (!address) return; + if (!address || !collateral) return; setIsLoading(true); + const response = await fetch(`${api.bot}/subscription/${address}`, { method: "GET", headers: { @@ -40,14 +57,18 @@ export default function Notification({ collateral }) { }); if (!response.ok) { - throw new Error("Failed to register for notifications"); + throw new Error("Failed to get subscription"); } - const { data } = await response.json(); - setAlreadyRegistered( - data.find((item) => item.collateralName === collateral) + const responseData = await response.json(); + + const { data } = responseData; + const subscription = data.find( + (item) => item.collateralName === collateral ); + setAlreadyRegistered(!!subscription); } catch (error) { + console.error("Error fetching subscription:", error); setAlreadyRegistered(false); } finally { setIsLoading(false); @@ -56,6 +77,23 @@ export default function Notification({ collateral }) { const handleNotificationSetup = async () => { try { + // Validate required fields + if (!address) { + tooltip.error({ + content: "Please connect your wallet first.", + duration: 5000, + }); + return; + } + + if (!collateral) { + tooltip.error({ + content: "Collateral information is not available. Please try again.", + duration: 5000, + }); + return; + } + setIsLoading(true); // Message to sign @@ -77,17 +115,24 @@ export default function Notification({ collateral }) { }), }); - if (!response.ok) { + if (response.status !== 200 && response.status !== 201) { + const errorText = await response.text(); + console.error("Error response:", errorText); throw new Error("Failed to register for notifications"); } - const { registrationCode } = await response.json(); + const data = await response.json(); + console.log("Response data:", data); + + const { registrationCode } = data; setRegistrationCode(registrationCode); + // setShowModal(true); } catch (error) { console.error("Error setting up notifications:", error); tooltip.error({ - content: "Failed to setup notifications. Please try again.", + content: + error.message || "Failed to setup notifications. Please try again.", duration: 5000, }); } finally { @@ -97,17 +142,19 @@ export default function Notification({ collateral }) { return ( <> -
    -
    - -
    Enable Telegram Notifications
    + {collateral && ( +
    +
    + +
    Enable Telegram Notifications
    +
    -
    + )} {/* Modal */} {showTelegramModal && ( diff --git a/next.config.js b/next.config.js index ae88795..9d991b9 100644 --- a/next.config.js +++ b/next.config.js @@ -2,6 +2,20 @@ const nextConfig = { reactStrictMode: true, swcMinify: true, -} + async rewrites() { + // Solo usar proxy en desarrollo + if (process.env.NODE_ENV === "development") { + return [ + { + source: "/api/bot/:path*", + destination: `${ + process.env.BACKEND_API_URL || "http://192.168.0.119/v1" + }/:path*`, + }, + ]; + } + return []; + }, +}; -module.exports = nextConfig +module.exports = nextConfig; diff --git a/utils/addresses.js b/utils/addresses.js index 909dd1d..cb3ece7 100644 --- a/utils/addresses.js +++ b/utils/addresses.js @@ -114,6 +114,8 @@ export const rpc = { export const api = { // bot: 'https://api.bitusd.finance/api', - bot: "http://localhost:4001/api/v1", - //TODO: Update with production URL + bot: + process.env.NODE_ENV === "production" + ? process.env.NEXT_PUBLIC_API_URL_V1 || "https://api.bitusd.finance/v1" + : process.env.NEXT_PUBLIC_API_LOCAL_URL_V1 || "/api/bot", }; From 685d7efe1848bda0cf6116b81f8768d61059efcf Mon Sep 17 00:00:00 2001 From: Gera Barboni Date: Thu, 30 Oct 2025 18:50:11 -0300 Subject: [PATCH 4/4] feat: add proxy support for Vercel preview to bypass CORS --- next.config.js | 8 +++++--- utils/addresses.js | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/next.config.js b/next.config.js index 9d991b9..b00d66a 100644 --- a/next.config.js +++ b/next.config.js @@ -3,13 +3,15 @@ const nextConfig = { reactStrictMode: true, swcMinify: true, async rewrites() { - // Solo usar proxy en desarrollo - if (process.env.NODE_ENV === "development") { + const isPreview = process.env.VERCEL_ENV === "preview"; + const isDevelopment = process.env.NODE_ENV === "development"; + + if (isDevelopment || isPreview) { return [ { source: "/api/bot/:path*", destination: `${ - process.env.BACKEND_API_URL || "http://192.168.0.119/v1" + process.env.BACKEND_API_URL || "https://api.bitusd.finance/v1" }/:path*`, }, ]; diff --git a/utils/addresses.js b/utils/addresses.js index cb3ece7..a96afac 100644 --- a/utils/addresses.js +++ b/utils/addresses.js @@ -115,7 +115,7 @@ export const rpc = { export const api = { // bot: 'https://api.bitusd.finance/api', bot: - process.env.NODE_ENV === "production" + process.env.NEXT_PUBLIC_VERCEL_ENV === "production" ? process.env.NEXT_PUBLIC_API_URL_V1 || "https://api.bitusd.finance/v1" : process.env.NEXT_PUBLIC_API_LOCAL_URL_V1 || "/api/bot", };