Skip to content

Commit

Permalink
Credit offers & Vesting balances
Browse files Browse the repository at this point in the history
prevent launching new tab windows on hyperlinks in electron

Added a credit offer view page
Added a vesting balance claim page
  • Loading branch information
grctest committed Sep 2, 2024
1 parent 19dabec commit 74d27f0
Show file tree
Hide file tree
Showing 57 changed files with 995 additions and 62 deletions.
4 changes: 4 additions & 0 deletions app/background.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/background.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const createWindow = async () => {

mainWindow.loadURL('http://localhost:8080/index.html');

mainWindow.webContents.setWindowOpenHandler(() => {
return { action: "deny" };
});

tray = new Tray(path.join(__dirname, "img", "tray.png"));
const contextMenu = Menu.buildFromTemplate([
{
Expand Down
2 changes: 1 addition & 1 deletion src/components/CreditDeals.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default function CreditDeals(properties) {
let unsubscribeBorrowerDeals;

if (usr && usr.id) {
const borrowerDealsStore = createBorrowerDealsStore([usr.chain, usr.id]);
const borrowerDealsStore = createBorrowerDealsStore([usr.chain, usr.id, currentNode ? currentNode.url : null]);

unsubscribeBorrowerDeals = borrowerDealsStore.subscribe(({ data, error, loading }) => {
if (data && !error && !loading) {
Expand Down
205 changes: 205 additions & 0 deletions src/components/CreditOffers.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
import React, { useSyncExternalStore, useMemo } from "react";
import { FixedSizeList as List } from "react-window";
import { useTranslation } from "react-i18next";

import { i18n as i18nInstance, locale } from "@/lib/i18n.js";

import { Button } from "@/components/ui/button";

import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";

import { useInitCache } from "@/nanoeffects/Init.ts";

import { $currentUser } from "@/stores/users.ts";
import {
$assetCacheBTS,
$assetCacheTEST,
$offersCacheBTS,
$offersCacheTEST,
} from "@/stores/cache.ts";

import { humanReadableFloat } from "@/lib/common.js";

function hoursTillExpiration(expirationTime) {
var expirationDate = new Date(expirationTime);
var currentDate = new Date();
var difference = expirationDate - currentDate;
var hours = Math.round(difference / 1000 / 60 / 60);
return hours;
}

export default function CreditBorrow(properties) {
const { t, i18n } = useTranslation(locale.get(), { i18n: i18nInstance });
const usr = useSyncExternalStore($currentUser.subscribe, $currentUser.get, () => true);

const _assetsBTS = useSyncExternalStore($assetCacheBTS.subscribe, $assetCacheBTS.get, () => true);
const _assetsTEST = useSyncExternalStore(
$assetCacheTEST.subscribe,
$assetCacheTEST.get,
() => true
);

const _offersBTS = useSyncExternalStore(
$offersCacheBTS.subscribe,
$offersCacheBTS.get,
() => true
);
const _offersTEST = useSyncExternalStore(
$offersCacheTEST.subscribe,
$offersCacheTEST.get,
() => true
);

const _chain = useMemo(() => {
if (usr && usr.chain) {
return usr.chain;
}
return "bitshares";
}, [usr]);

useInitCache(_chain ?? "bitshares", ["assets", "offers"]);

const assets = useMemo(() => {
if (_chain && (_assetsBTS || _assetsTEST)) {
return _chain === "bitshares" ? _assetsBTS : _assetsTEST;
}
return [];
}, [_assetsBTS, _assetsTEST, _chain]);

const offers = useMemo(() => {
if (_chain && (_offersBTS || _offersTEST)) {
return _chain === "bitshares"
? _offersBTS.filter((x) => hoursTillExpiration(x.auto_disable_time) >= 0 && x.owner_account === usr.id)
: _offersTEST.filter((x) => hoursTillExpiration(x.auto_disable_time) >= 0 && x.owner_account === usr.id);
}
return [];
}, [_offersBTS, _offersTEST, _chain, usr]);

function CommonRow({ index, style, res, foundAsset }) {
return (
<div style={{ ...style }} key={`acard-${res.id}`}>
<Card className="ml-2 mr-2" onClick={() => {}}>
<CardHeader className="pb-1">
<CardTitle>
{t("CreditBorrow:common.title", {
orderID: res.id.replace("1.21.", ""),
owner_name: res.owner_name,
owner_account: res.owner_account,
})}
</CardTitle>
<CardDescription>
{t("CreditBorrow:common.offering")}
<b>
{` ${humanReadableFloat(res.current_balance, foundAsset.precision)} ${
foundAsset.symbol
} (${res.asset_type})`}
</b>
<br />
{t("CreditBorrow:common.accepting")}
<b>
{assets && assets.length
? ` ${res.acceptable_collateral
.map((asset) => asset[0])
.map((x) => {
return assets.find((y) => y.id === x)?.symbol;
})
.map((x) => x)
.join(", ")}`
: t("CreditBorrow:common.loading")}
</b>
</CardDescription>
</CardHeader>
<CardContent className="text-sm pb-3">
<div className="grid grid-cols-2 gap-2">
<div className="col-span-1">
{t("CreditBorrow:common.fee", { fee: res.fee_rate / 10000 })}
<br />
{t("CreditBorrow:common.repayPeriod", {
repayPeriod: (res.max_duration_seconds / 60 / 60).toFixed(
res.max_duration_seconds / 60 / 60 < 1 ? 2 : 0
),
})}
</div>
<div className="col-span-1">
{t("CreditBorrow:common.validity", {
validity: hoursTillExpiration(res.auto_disable_time),
})}
<br />
{t("CreditBorrow:common.min", {
amount: humanReadableFloat(res.min_deal_amount, foundAsset.precision),
asset: foundAsset.symbol,
})}
</div>
</div>
</CardContent>
<CardFooter className="pb-5">
<a href={`/lend/index.html?id=${res.id}`}>
<Button>
{t(`CreditBorrow:common.${usr.id === res.owner_account ? "edit" : "view"}`, {
offerID: res.id.replace("1.21.", ""),
})}
</Button>
</a>
</CardFooter>
</Card>
</div>
);
}

const Row = ({ index, style }) => {
let res = offers[index];

const foundAsset = assets.find((x) => x.id === res.asset_type);

if (!res || !foundAsset) {
return null;
}

return <CommonRow index={index} style={style} res={res} foundAsset={foundAsset} />;
};

return (
<>
<div className="container mx-auto mt-5 mb-5">
<div className="grid grid-cols-1 gap-3">
<Card>
<CardHeader className="pb-1">
<CardTitle>{t("CreditOffers:card.title")}</CardTitle>
<CardDescription>{t("CreditOffers:card.description")}</CardDescription>
</CardHeader>
<CardContent>
<>
{
offers && offers.length
? (
<List
height={500}
itemCount={offers.length}
itemSize={225}
className="w-full mt-3"
>
{Row}
</List>
)
: null
}
{
offers && !offers.length
? t("CreditOffers:card.noResults")
: null
}
</>
</CardContent>
</Card>
</div>
</div>
</>
);
}
38 changes: 38 additions & 0 deletions src/components/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,44 @@ export default function Home(properties) {
</ul>
</HoverCardContent>
</HoverCard>

<HoverCard key="offers">
<HoverCardTrigger asChild>
<a href="/offers/index.html" style={{ textDecoration: "none" }}>
<Card className="h-full hover:shadow-md hover:shadow-black">
<CardHeader>
<CardTitle>{t("Home:offers.title")}</CardTitle>
<CardDescription>{t("Home:offers.subtitle")}</CardDescription>
</CardHeader>
</Card>
</a>
</HoverCardTrigger>
<HoverCardContent className="w-80 text-sm pt-1">
<ul className="ml-2 list-disc [&>li]:mt-2">
<li>{t("Home:offers.hover1")}</li>
<li>{t("Home:offers.hover2")}</li>
</ul>
</HoverCardContent>
</HoverCard>

<HoverCard key="vesting">
<HoverCardTrigger asChild>
<a href="/vesting/index.html" style={{ textDecoration: "none" }}>
<Card className="h-full hover:shadow-md hover:shadow-black">
<CardHeader>
<CardTitle>{t("Home:vesting.title")}</CardTitle>
<CardDescription>{t("Home:vesting.subtitle")}</CardDescription>
</CardHeader>
</Card>
</a>
</HoverCardTrigger>
<HoverCardContent className="w-80 text-sm pt-1">
<ul className="ml-2 list-disc [&>li]:mt-2">
<li>{t("Home:vesting.hover1")}</li>
<li>{t("Home:vesting.hover2")}</li>
</ul>
</HoverCardContent>
</HoverCard>
</div>

<h4 className="mt-3 mb-2">
Expand Down
1 change: 0 additions & 1 deletion src/components/PortfolioTabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ export default function PortfolioTabs(properties) {

unsubscribeUserBalancesStore = userBalancesStore.subscribe(({ data, error, loading }) => {
if (data && !error && !loading) {
console.log({data})
const updatedData = data.map((balance) => {
return {
...balance,
Expand Down
23 changes: 0 additions & 23 deletions src/components/SimpleSwap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -467,29 +467,6 @@ export default function SimpleSwap() {
)) /
Number(poolamountap);
}

/*
console.log({
calculated: {
poolamounta,
poolamountap,
poolamountb,
poolamountbp,
maker_market_fee_percenta,
maker_market_fee_percentb,
max_market_feea,
max_market_feeb,
taker_fee_percenta,
taker_market_fee_percent_a
},
inputs: {
foundPool,
assetA,
assetB,
},
result
})
*/

return result;
}
Expand Down
Loading

0 comments on commit 74d27f0

Please sign in to comment.