Skip to content

Commit

Permalink
Merge pull request #392 from dOrgTech/develop
Browse files Browse the repository at this point in the history
Merge develop to V2
  • Loading branch information
Man-Jain authored Dec 17, 2022
2 parents 5e7281c + 9f45567 commit 287b4a2
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 18 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ At a contract level, there is no such distinction, but in the UI it exists to le
```

# Contributing
## Developer Docs

- [Tezos Homebase Docs](https://docs.google.com/document/d/1zZwcvX0jNE8PycOMNSULy2i-mcjg1LJ9FFYbGP4m9TM/edit?usp=sharing)
- [Tezos Homebase - Local Env Setup](https://docs.google.com/document/d/1GDnJzwezXXEGiwZAWioOlfvmcSuHuREpO7GIKMLjYmk/edit?usp=sharing)

## Running the project

To run the project:
Expand Down
2 changes: 1 addition & 1 deletion src/modules/explorer/components/DAOStatsRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export const DAOStatsRow: React.FC = () => {
<ProposalInfoTitle color="secondary">{symbol} Locked</ProposalInfoTitle>
</Grid>
<Grid item>
<LargeNumber>{amountLocked.dp(10).toString()}</LargeNumber>
<LargeNumber>{amountLocked.dp(10, 1).toString()}</LargeNumber>
</Grid>
<Grid item>
<LockedTokensBar variant="determinate" value={amountLockedPercentage.toNumber()} color="secondary" />
Expand Down
30 changes: 25 additions & 5 deletions src/modules/explorer/components/FreezeDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export const FreezeDialog: React.FC<{ freeze: boolean }> = ({ freeze }) => {
const { account } = useTezos()

const [showMax, setShowMax] = React.useState<boolean>(false)
const [max, setMax] = React.useState(0)
const [maxDeposit, setMaxDeposit] = React.useState(0)
const [maxWithdraw, setMaxWithdraw] = React.useState(0)

const handleClickOpen = () => {
setOpen(true)
Expand Down Expand Up @@ -83,8 +84,17 @@ export const FreezeDialog: React.FC<{ freeze: boolean }> = ({ freeze }) => {
)
setShowMax(true)
if (availableBalance) {
const formattedBalance = parseUnits(new BigNumber(availableBalance), dao.data.token.decimals).toNumber()
setMax(formattedBalance)
const formattedBalance = parseUnits(new BigNumber(availableBalance), dao.data.token.decimals)
.dp(10, 1)
.toNumber()
setMaxDeposit(formattedBalance)
}

const userLedger = ledger.find(l => l.holder.address.toLowerCase() === account.toLowerCase())
if (userLedger) {
if (userLedger.available_balance) {
setMaxWithdraw(userLedger.available_balance.dp(10, 1).toNumber())
}
}
}
}
Expand All @@ -111,9 +121,19 @@ export const FreezeDialog: React.FC<{ freeze: boolean }> = ({ freeze }) => {
{showMax && freeze ? (
<>
<Typography>
{max} {dao?.data.token.symbol}
{maxDeposit} {dao?.data.token.symbol}
</Typography>
<CustomMaxLabel color="secondary" onClick={() => setAmount(maxDeposit)}>
Use Max
</CustomMaxLabel>
</>
) : null}
{showMax && !freeze ? (
<>
<Typography>
{maxWithdraw} {dao?.data.token.symbol}
</Typography>
<CustomMaxLabel color="secondary" onClick={() => setAmount(max)}>
<CustomMaxLabel color="secondary" onClick={() => setAmount(maxWithdraw)}>
Use Max
</CustomMaxLabel>
</>
Expand Down
6 changes: 3 additions & 3 deletions src/modules/explorer/components/UserBalances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ export const UserBalances: React.FC<{ daoId: string }> = ({ daoId, children }) =
return userBalances
}

userBalances.available.balance = userLedger.available_balance.dp(10).toString()
userBalances.pending.balance = userLedger.pending_balance.dp(10).toString()
userBalances.staked.balance = userLedger.staked.dp(10).toString()
userBalances.available.balance = userLedger.available_balance.dp(10, 1).toString()
userBalances.pending.balance = userLedger.pending_balance.dp(10, 1).toString()
userBalances.staked.balance = userLedger.staked.dp(10, 1).toString()

return userBalances
}, [account, ledger])
Expand Down
4 changes: 2 additions & 2 deletions src/modules/explorer/pages/DAO/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export const DAO: React.FC = () => {
.sort((a, b) => b.available_balance.minus(a.available_balance).toNumber())
.map(p => ({
address: p.holder.address,
totalStaked: new BigNumber(p.total_balance).dp(10).toString(),
availableStaked: new BigNumber(p.available_balance).dp(10).toString(),
totalStaked: new BigNumber(p.total_balance).dp(10, 1).toString(),
availableStaked: new BigNumber(p.available_balance).dp(10, 1).toString(),
votes: p.holder.votes_cast.toString(),
proposalsVoted: p.holder.proposals_voted.toString()
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const createData = (daoHolding: DAOHolding): RowData => {
return {
symbol: daoHolding.token.symbol,
address: daoHolding.token.contract,
amount: daoHolding.balance.dp(10).toString()
amount: daoHolding.balance.dp(10, 1).toString()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const createData = (transfer: TransferWithBN, isInbound: boolean) => {
return {
token: transfer.name,
date: dayjs(transfer.date).format("ll"),
amount: transfer.amount.dp(10).toString(),
amount: transfer.amount.dp(10, 1).toString(),
address: isInbound ? transfer.sender : transfer.recipient,
hash: transfer.hash
}
Expand Down
8 changes: 3 additions & 5 deletions src/services/bakingBad/tokenBalances/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NFT, Token } from "models/Token"
import { Network } from "services/beacon"
import { parseUnits } from "services/contracts/utils"
import { networkNameMap } from ".."
import { BalanceTZKT, DAOToken, FA2TokenDTO, NFTDTO, TokenDataTZKT } from "./types"
import { BalanceDataDTO, BalanceTZKT, DAOToken, FA2TokenDTO, NFTDTO, TokenDataTZKT } from "./types"

const isNFTDTO = (value: DAOToken): value is NFTDTO => value.hasOwnProperty("artifact_uri")

Expand Down Expand Up @@ -189,17 +189,15 @@ export const getTokenMetadata = async (contractAddress: string, network: Network
}

export const getUserTokenBalance = async (accountAddress: string, network: Network = "mainnet", tokenAddress = "") => {
const url = `https://api.${networkNameMap[network]}.tzkt.io/v1/tokens/balances/?account=${accountAddress}`
const url = `https://api.${networkNameMap[network]}.tzkt.io/v1/tokens/balances/?account=${accountAddress}&token.contract=${tokenAddress}`

const response = await fetch(url)

if (!response.ok) {
throw new Error("Failed to fetch user balances")
}

const userTokens = await response.json()

const userTokenBalance = userTokens.filter((token: any) => token.token.contract.address === tokenAddress)
const userTokenBalance: BalanceDataDTO[] = await response.json()

if (userTokenBalance && userTokenBalance[0]) {
return userTokenBalance[0].balance
Expand Down
12 changes: 12 additions & 0 deletions src/services/bakingBad/tokenBalances/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,15 @@ export interface TokenDataTZKT {
totalSupply: string
metadata: Metadata
}

export interface BalanceDataDTO {
id: number
account: Account
token: Token
balance: string
transfersCount: number
firstLevel: number
firstTime: string
lastLevel: number
lastTime: string
}

0 comments on commit 287b4a2

Please sign in to comment.