Skip to content

Commit

Permalink
fix: user balance display on buy/sell
Browse files Browse the repository at this point in the history
  • Loading branch information
crnbarr93 committed Aug 13, 2024
1 parent 776779d commit b25fdf6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ const ClaimAndCloseButton = observer(
>
<span className="body2 flex items-center text-wosmongton-200">
{claiming && <Spinner className="mr-2 h-2 w-2" />}
{t("limitOrders.claimAndClose")}
{order.percentFilled > order.percentClaimed
? t("limitOrders.claimAndClose")
: t("limitOrders.close")}
</span>
</button>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ const OrderDetails = observer(

return order?.status === "open"
? "limitOrders.cancel"
: "limitOrders.claimAndClose";
: order?.percentFilled > order?.percentClaimed
? "limitOrders.claimAndClose"
: "limitOrders.close";
}, [order]);

const orderAmount = useMemo(() => {
Expand Down
46 changes: 26 additions & 20 deletions packages/web/hooks/limit-orders/use-place-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,33 +378,39 @@ export const usePlaceLimit = ({
placeLimitMsg,
]);

const { data: balances, isLoading: isBalancesLoading } =
api.local.balances.getUserBalances.useQuery(
{ bech32Address: account?.address ?? "" },
const { data, isLoading: isBalancesLoading } =
api.edge.assets.getUserAssets.useQuery(
{
userOsmoAddress: account?.address ?? "",
},
{
enabled: !!account?.address,
select: (balances) =>
balances.filter(
({ denom }) =>
denom === baseAsset?.coinMinimalDenom ||
denom === quoteAsset?.coinMinimalDenom
select: ({ items }) =>
items.filter(
({ coinMinimalDenom }) =>
coinMinimalDenom === baseAsset?.coinMinimalDenom ||
coinMinimalDenom === quoteAsset?.coinMinimalDenom
),
}
);

const quoteTokenBalance = useMemo(() => {
if (!balances) return;

return balances.find(({ denom }) => denom === quoteAsset?.coinMinimalDenom)
?.coin;
}, [balances, quoteAsset]);

const baseTokenBalance = useMemo(() => {
if (!balances) return;
const baseTokenBalance = useMemo(
() =>
data?.find(
({ coinMinimalDenom }) =>
coinMinimalDenom === baseAsset?.coinMinimalDenom
)?.amount,
[data, baseAsset]
);
const quoteTokenBalance = useMemo(
() =>
data?.find(
({ coinMinimalDenom }) =>
coinMinimalDenom === quoteAsset?.coinMinimalDenom
)?.amount,
[data, quoteAsset]
);

return balances.find(({ denom }) => denom === baseAsset?.coinMinimalDenom)
?.coin;
}, [balances, baseAsset]);
const insufficientFunds = useMemo(() => {
return orderDirection === "bid"
? (quoteTokenBalance?.toDec() ?? new Dec(0)).lt(
Expand Down
1 change: 1 addition & 0 deletions packages/web/localizations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,7 @@
"filled": "Filled",
"claimable": "Claimable",
"claimAndClose": "Claim and close",
"close": "Close",
"claim": "Claim",
"accept": "Accept",
"cancelled": "Cancelled",
Expand Down

0 comments on commit b25fdf6

Please sign in to comment.