Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Feb 19, 2024
1 parent 4153449 commit 68d7da0
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 66 deletions.
3 changes: 0 additions & 3 deletions trade.renegade.fi/contexts/Renegade/renegade-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function RenegadeProvider({ children }: React.PropsWithChildren) {
const [balances, setBalances] = React.useState<Record<BalanceId, Balance>>({})
const [fees] = React.useState<Record<FeeId, Fee>>({})
const [orders, setOrders] = React.useState<Record<OrderId, Order>>({})
const [isLocked, setIsLocked] = React.useState<boolean>(false)

// Create task states.
const [taskId, setTaskId] = React.useState<TaskId>()
Expand Down Expand Up @@ -212,7 +211,6 @@ function RenegadeProvider({ children }: React.PropsWithChildren) {
if (!accountId) return
setBalances(renegade.getBalances(accountId))
setOrders(renegade.getOrders(accountId))
setIsLocked(renegade.getIsLocked(accountId))
}

function setTask(newTaskId?: TaskId, taskType?: TaskType) {
Expand All @@ -231,7 +229,6 @@ function RenegadeProvider({ children }: React.PropsWithChildren) {
balances,
counterparties,
fees,
isLocked,
orderBook,
orders,
refreshAccount,
Expand Down
1 change: 0 additions & 1 deletion trade.renegade.fi/contexts/Renegade/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export interface RenegadeContextType {
balances: Record<BalanceId, Balance>
counterparties: Record<PeerId, Counterparty>
fees: Record<FeeId, Fee>
isLocked: boolean
orderBook: Record<OrderId, CounterpartyOrder>
orders: Record<OrderId, Order>
refreshAccount: (accountId?: AccountId) => void
Expand Down
35 changes: 16 additions & 19 deletions trade.renegade.fi/hooks/use-balance.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import { useEffect, useState } from "react"
import { useRenegade } from "@/contexts/Renegade/renegade-context"
import { Balance, BalanceId } from "@renegade-fi/renegade-js"

import { renegade } from "@/app/providers"

export const useBalance = () => {
const [balances, setBalances] = useState<Record<BalanceId, Balance>>({})
const { accountId } = useRenegade()
// const [balances, setBalances] = useState<Record<BalanceId, Balance>>({})
// const { accountId } = useRenegade()

useEffect(() => {
if (!accountId) return
const interval = setInterval(async () => {
const fetchedBalances = await renegade
.queryWallet(accountId)
.then(() => renegade.getBalances(accountId))
setBalances(fetchedBalances)
}, 5000)
// useEffect(() => {
// if (!accountId) return
// const interval = setInterval(async () => {
// const fetchedBalances = await renegade
// .queryWallet(accountId)
// .then(() => renegade.getBalances(accountId))
// setBalances(fetchedBalances)
// }, 5000)

return () => {
clearInterval(interval)
}
}, [accountId])
// return () => {
// clearInterval(interval)
// }
// }, [accountId])

return balances
// const { balances } = useRenegade()
// return balances
const { balances } = useRenegade()
return balances
}
56 changes: 26 additions & 30 deletions trade.renegade.fi/hooks/use-order.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
import { useEffect, useState } from "react"
import { useRenegade } from "@/contexts/Renegade/renegade-context"
import { Order, OrderId } from "@renegade-fi/renegade-js"

import { safeLocalStorageGetItem, safeLocalStorageSetItem } from "@/lib/utils"
import { renegade } from "@/app/providers"

export const useOrders = () => {
const { accountId } = useRenegade()
const [orders, setOrders] = useState<Record<OrderId, Order>>({})
// const { accountId } = useRenegade()
// const [orders, setOrders] = useState<Record<OrderId, Order>>({})

useEffect(() => {
if (!accountId) return
const interval = setInterval(async () => {
const existingOrders = safeLocalStorageGetItem(`orders-${accountId}`)
const existingOrdersArray = existingOrders
? existingOrders.split(",")
: []
// useEffect(() => {
// if (!accountId) return
// const interval = setInterval(async () => {
// const existingOrders = safeLocalStorageGetItem(`orders-${accountId}`)
// const existingOrdersArray = existingOrders
// ? existingOrders.split(",")
// : []

const fetchedOrders = await renegade
.queryWallet(accountId)
.then(() => renegade.getOrders(accountId))
setOrders(fetchedOrders)
// const fetchedOrders = await renegade
// .queryWallet(accountId)
// .then(() => renegade.getOrders(accountId))
// setOrders(fetchedOrders)

const uniqueNewOrderIds = Object.keys(fetchedOrders).filter(
(orderId) => !existingOrdersArray.includes(orderId)
)
// const uniqueNewOrderIds = Object.keys(fetchedOrders).filter(
// (orderId) => !existingOrdersArray.includes(orderId)
// )

existingOrdersArray.push(...uniqueNewOrderIds)
const updatedOrders = existingOrdersArray.join(",")
// existingOrdersArray.push(...uniqueNewOrderIds)
// const updatedOrders = existingOrdersArray.join(",")

safeLocalStorageSetItem(`orders-${accountId}`, updatedOrders)
}, 1000)
// safeLocalStorageSetItem(`orders-${accountId}`, updatedOrders)
// }, 1000)

return () => {
clearInterval(interval)
}
}, [accountId])
// return () => {
// clearInterval(interval)
// }
// }, [accountId])

return orders
// const { orders } = useRenegade()
// return orders
const { orders } = useRenegade()
return orders
}
14 changes: 7 additions & 7 deletions trade.renegade.fi/hooks/use-tasks.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { useEffect, useState } from "react"
import { renegade } from "@/app/providers"
import { useRenegade } from "@/contexts/Renegade/renegade-context"
import { useEffect, useState } from "react"

import { renegade } from "@/app/providers"

export const useTasks = () => {
const [tasks, setTasks] = useState<
{
id?: string | undefined
status?:
| {
task_type?: string | undefined
state?: string | undefined
}
| undefined
| {
task_type?: string | undefined
state?: string | undefined
}
| undefined
committed?: boolean | undefined
}[]
>([])
Expand Down
4 changes: 2 additions & 2 deletions trade.renegade.fi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@chakra-ui/react": "^2.8.0",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@renegade-fi/renegade-js": "^0.4.8",
"@renegade-fi/renegade-js": "^0.4.9",
"@t3-oss/env-nextjs": "^0.6.0",
"connectkit": "^1.4.0",
"dayjs": "^1.11.10",
Expand All @@ -31,8 +31,8 @@
"react-dom": "^18.2.0",
"react-use-intercom": "^5.1.4",
"simplebar-react": "^3.2.4",
"usehooks-ts": "^2.13.0",
"sonner": "^1.4.0",
"usehooks-ts": "^2.13.0",
"uuid": "^9.0.1",
"viem": "^1.20.1",
"wagmi": "^1.4.12",
Expand Down
8 changes: 4 additions & 4 deletions trade.renegade.fi/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1721,10 +1721,10 @@
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.8.tgz#6b79032e760a0899cd4204710beede972a3a185f"
integrity sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==

"@renegade-fi/renegade-js@^0.4.8":
version "0.4.8"
resolved "https://registry.yarnpkg.com/@renegade-fi/renegade-js/-/renegade-js-0.4.8.tgz#879dfbbac7f0c28d5ffebd0e11f183cce7fb885a"
integrity sha512-KIXpUm7TjPkCBRFu2mj9+DZeaXGfJB+rOE5LvXrWVPDmHP5cu5Q2wiBTXxLIpjEqMuLcA6S/bdnvgNJhmu9kVw==
"@renegade-fi/renegade-js@^0.4.9":
version "0.4.9"
resolved "https://registry.yarnpkg.com/@renegade-fi/renegade-js/-/renegade-js-0.4.9.tgz#3b138f2b2787aa2ab5497e5399e81f9eafecfa82"
integrity sha512-AXOVNzijd7AZfXUeChhIR7hCzsKTKY0mP3X7d+TcPRMZ28GcFz3sySoAVIP3XE4YsDQ9R+e/5D1j0Psks9dfLA==
dependencies:
"@noble/hashes" "^1.3.0"
axios "^1.3.5"
Expand Down

0 comments on commit 68d7da0

Please sign in to comment.