Skip to content

Commit

Permalink
Fix Max button for deposit, withdraw and rounding places (#365)
Browse files Browse the repository at this point in the history
* Update issue templates

* Update issue templates

* Fix Max button for deposit, withdraw and rounding places

- Fix Max button for deposit, switch to different tzkt endpoint
- Add Max button to withdraw
- Change round places to 10 decimal places and ROUND_DOWN to ZERO

Signed-off-by: Manank Patni <manank321@gmail.com>

* Remove console.log

Signed-off-by: Manank Patni <manank321@gmail.com>

Signed-off-by: Manank Patni <manank321@gmail.com>
Co-authored-by: Magenta Ceiba <38021350+magentaceiba@users.noreply.github.com>
Co-authored-by: Fernando Torres <80982814+thenerdcat@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 29, 2022
1 parent 46a262e commit d6b9119
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 18 deletions.
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Issue
about: This is our standard issue template for all contributors
title: ''
labels: ''
assignees: ''

---

**Name**

**Description (what needs to be done) / Expected Behavior**

**Acceptance Criteria**

**Supporting information (Figma link, notes, etc)**

**When finished, please add Link to the PR or completed Figma / design asset, as a comment to the ticket.**
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 @@ -164,17 +164,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 @@ -127,3 +127,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 d6b9119

Please sign in to comment.