Skip to content
8 changes: 8 additions & 0 deletions src/components/AppSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
title: "Offered",
url: "/quotes/offered",
},
{
title: "Offer Expired",
url: "/quotes/offerexpired",
},

Check warning on line 35 in src/components/AppSidebar.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/AppSidebar.tsx#L32-L35

Added lines #L32 - L35 were not covered by tests
{
title: "Accepted",
url: "/quotes/accepted",
Expand All @@ -41,6 +45,10 @@
title: "Rejected",
url: "/quotes/rejected",
},
{
title: "Canceled",
url: "/quotes/canceled",
},

Check warning on line 51 in src/components/AppSidebar.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/AppSidebar.tsx#L48-L51

Added lines #L48 - L51 were not covered by tests
],
},
],
Expand Down
13 changes: 12 additions & 1 deletion src/generated/client/sdk.gen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file is auto-generated by @hey-api/openapi-ts

import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';
import type { ListQuotesData, ListQuotesResponse, ListPendingQuotesData, ListPendingQuotesResponse, AdminLookupQuoteData, AdminLookupQuoteResponse, AdminUpdateQuoteData, AdminUpdateQuoteResponse, ResolveOfferData, EnquireQuoteData, EnquireQuoteResponse, LookupQuoteData, LookupQuoteResponse, ActivateKeysetData, ActivateKeysetResponse, DebitData, CreditData, ECashBalance, OnChainBalanceData, OnChainData} from './types.gen';
import type { ListQuotesData, ListQuotesResponse, ListPendingQuotesData, ListPendingQuotesResponse, AdminLookupQuoteData, AdminLookupQuoteResponse, AdminUpdateQuoteData, AdminUpdateQuoteResponse, ResolveOfferData, EnquireQuoteData, EnquireQuoteResponse, LookupQuoteData, LookupQuoteResponse, ActivateKeysetData, ActivateKeysetResponse, DebitData, CreditData, ECashBalance, OnChainBalanceData, OnChainData, KeysetInfoData, KeySetInfo} from './types.gen';
import { client as _heyApiClient } from './client.gen';

export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
Expand Down Expand Up @@ -125,3 +125,14 @@
...options
});
};

/**
* --------------------------- KeySetInfo
*/

export const keysetInfo = <ThrowOnError extends boolean = false>(options: Options<KeysetInfoData, ThrowOnError>) => {
return (options.client ?? _heyApiClient).get<KeySetInfo, unknown, ThrowOnError>({
url: '/v1/admin/keysets/{keyset_id}',
...options
});
};

Check warning on line 138 in src/generated/client/sdk.gen.ts

View check run for this annotation

Codecov / codecov/patch

src/generated/client/sdk.gen.ts#L133-L138

Added lines #L133 - L138 were not covered by tests
40 changes: 37 additions & 3 deletions src/generated/client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,36 @@ export type InfoReply = {
} | {
bill: BillInfo;
id: string;
signatures: Array<BlindSignature>;
status: 'Canceled';
tstamp: string;
} | {
bill: BillInfo;
id: string;
keyset_id: string;
status: 'Offered';
discounted: number;
ttl: string;
} | {
bill: BillInfo;
id: string;
status: 'OfferExpired';
discounted: number;
tstamp: string;
} | {
bill: BillInfo;
id: string;
status: 'Denied';
} | {
bill: BillInfo;
id: string;
signatures: Array<BlindSignature>;
keyset_id: string;
discounted: number;
status: 'Accepted';
} | {
bill: BillInfo;
id: string;
status: 'Rejected';
discounted: number;
tstamp: string;
};

Expand Down Expand Up @@ -455,10 +469,30 @@ export type OnChainBalanceData = {
confirmed: number;
};


export type OnChainData = {
body?: never;
path?: never;
query?: never;
url: '/v1/admin/onchain/balance';
};

/**
* Keyset information
*/

export type KeySetInfo = {
id: string;
unit: CurrencyUnit;
active: boolean;
input_fee_ppk: number;
};


export type KeysetInfoData = {
body?: never;
path: {
keyset_id: string;
};
query?: never;
url: '/v1/admin/keysets/{keyset_id}';
};
7 changes: 2 additions & 5 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@

const prepare = async () => {
await initKeycloak()
// if (meta.apiMocksEnabled) {
// const { worker } = await import("./mocks/browser")
// await worker.start()
// }
}

function App() {

Check warning on line 25 in src/main.tsx

View workflow job for this annotation

GitHub Actions / test (v22.11.0)

Fast refresh only works when a file has exports. Move your component(s) to a separate file
return (
<QueryClientProvider client={queryClient}>
<BrowserRouter>
Expand All @@ -39,10 +35,11 @@
<Route path="quotes" element={<StatusQuotePage />} />
<Route path="quotes/pending" element={<StatusQuotePage status="Pending" />} />
<Route path="quotes/accepted" element={<StatusQuotePage status="Accepted" />} />
<Route path="quotes/canceled" element={<StatusQuotePage status="Canceled" />} />

Check warning on line 38 in src/main.tsx

View check run for this annotation

Codecov / codecov/patch

src/main.tsx#L38

Added line #L38 was not covered by tests
<Route path="quotes/offered" element={<StatusQuotePage status="Offered" />} />
<Route path="quotes/offerexpired" element={<StatusQuotePage status="OfferExpired" />} />

Check warning on line 40 in src/main.tsx

View check run for this annotation

Codecov / codecov/patch

src/main.tsx#L40

Added line #L40 was not covered by tests
<Route path="quotes/denied" element={<StatusQuotePage status="Denied" />} />
<Route path="quotes/rejected" element={<StatusQuotePage status="Rejected" />} />
{/* <Route path="quotes/expired" element={<StatusQuotePage status="Rejected" />} /> */}
<Route path="quotes/:id" element={<QuotePage />} />
<Route path="settings" element={<SettingsPage />} />
<Route path="info" element={<InfoPage />} />
Expand Down
187 changes: 128 additions & 59 deletions src/pages/quotes/QuotePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
adminLookupQuoteQueryKey,
adminUpdateQuoteMutation,
} from "@/generated/client/@tanstack/react-query.gen"
import { activateKeyset } from "@/generated/client/sdk.gen"
import { activateKeyset, keysetInfo } from "@/generated/client/sdk.gen"

Check warning on line 15 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L15

Added line #L15 was not covered by tests
import { cn, getInitials } from "@/lib/utils"
import { formatDate, humanReadableDuration } from "@/utils/dates"

import { formatNumber, truncateString } from "@/utils/strings"
import { useMutation, useQueryClient, useSuspenseQuery } from "@tanstack/react-query"
import { useMutation, useQuery, useQueryClient, useSuspenseQuery } from "@tanstack/react-query"

Check warning on line 20 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L20

Added line #L20 was not covered by tests
import { getDeterministicColor } from "@/utils/dev"

import { LoaderIcon } from "lucide-react"
Expand Down Expand Up @@ -211,7 +211,15 @@
)
}

function QuoteActions({ value, isFetching }: { value: InfoReply; isFetching: boolean }) {
function QuoteActions({
value,
isFetching,
keysetActive,
}: {

Check warning on line 218 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L214-L218

Added lines #L214 - L218 were not covered by tests
value: InfoReply
isFetching: boolean
keysetActive: boolean
}) {

Check warning on line 222 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L222

Added line #L222 was not covered by tests
const [offerFormData, setOfferFormData] = useState<OfferFormResult>()
const [offerFormDrawerOpen, setOfferFormDrawerOpen] = useState(false)
const [offerConfirmDrawerOpen, setOfferConfirmDrawerOpen] = useState(false)
Expand Down Expand Up @@ -331,42 +339,50 @@
const onActivateKeyset = () => {
activateKeysetMutation.mutate()
}

return (
<div className="flex items-center gap-2">
<DenyConfirmDrawer
title="Confirm denying quote"
open={denyConfirmDrawerOpen}
onOpenChange={setDenyConfirmDrawerOpen}
onSubmit={() => {
onDenyQuote()
setDenyConfirmDrawerOpen(false)
}}
>
<Button
className="flex-1"
disabled={isFetching || denyQuote.isPending || value.status !== "Pending"}
variant={value.status !== "Pending" ? "outline" : "destructive"}
{value.status === "Pending" ? (
<DenyConfirmDrawer
title="Confirm denying quote"
open={denyConfirmDrawerOpen}
onOpenChange={setDenyConfirmDrawerOpen}
onSubmit={() => {
onDenyQuote()
setDenyConfirmDrawerOpen(false)
}}

Check warning on line 352 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L344-L352

Added lines #L344 - L352 were not covered by tests
>
Deny {denyQuote.isPending && <LoaderIcon className="stroke-1 animate-spin" />}
</Button>
</DenyConfirmDrawer>
<OfferFormDrawer
title="Offer quote"
description="Make an offer to the current holder of this bill"
value={value}
open={offerFormDrawerOpen}
onOpenChange={setOfferFormDrawerOpen}
onSubmit={(data) => {
setOfferFormData(data)
setOfferConfirmDrawerOpen(true)
setOfferFormDrawerOpen(false)
}}
>
<Button className="flex-1" disabled={isFetching || offerQuote.isPending || value.status !== "Pending"}>
Offer {offerQuote.isPending && <LoaderIcon className="stroke-1 animate-spin" />}
</Button>
</OfferFormDrawer>
<Button
className="flex-1"
disabled={isFetching || denyQuote.isPending || value.status !== "Pending"}
variant={value.status !== "Pending" ? "outline" : "destructive"}
>
Deny {denyQuote.isPending && <LoaderIcon className="stroke-1 animate-spin" />}
</Button>
</DenyConfirmDrawer>

Check warning on line 361 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L354-L361

Added lines #L354 - L361 were not covered by tests
) : (
<></>

Check warning on line 363 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L363

Added line #L363 was not covered by tests
)}
{value.status === "Pending" ? (
<OfferFormDrawer
title="Offer quote"
description="Make an offer to the current holder of this bill"
value={value}
open={offerFormDrawerOpen}
onOpenChange={setOfferFormDrawerOpen}
onSubmit={(data) => {
setOfferFormData(data)
setOfferConfirmDrawerOpen(true)
setOfferFormDrawerOpen(false)
}}

Check warning on line 376 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L365-L376

Added lines #L365 - L376 were not covered by tests
>
<Button className="flex-1" disabled={isFetching || offerQuote.isPending || value.status !== "Pending"}>
Offer {offerQuote.isPending && <LoaderIcon className="stroke-1 animate-spin" />}
</Button>
</OfferFormDrawer>

Check warning on line 381 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L378-L381

Added lines #L378 - L381 were not covered by tests
) : (
<></>

Check warning on line 383 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L383

Added line #L383 was not covered by tests
)}

<OfferConfirmDrawer
title="Confirm offering quote"
description="Review your inputs and confirm the offer"
Expand Down Expand Up @@ -399,26 +415,31 @@
</div>
</OfferConfirmDrawer>

<ConfirmDrawer
title="Confirm activating keyset"
description="Are you sure you want to activate the keyset for this quote?"
open={activateKeysetConfirmDrawerOpen}
onOpenChange={setActivateKeysetConfirmDrawerOpen}
onSubmit={() => {
onActivateKeyset()
setActivateKeysetConfirmDrawerOpen(false)
}}
submitButtonText="Yes, activate keyset"
trigger={
<Button
className="flex-1"
disabled={isFetching || activateKeysetMutation.isPending || value.status !== "Accepted"}
variant="default"
>
Activate Keyset {activateKeysetMutation.isPending && <LoaderIcon className="stroke-1 animate-spin" />}
</Button>
}
/>
{value.status === "Accepted" && "keyset_id" in value ? (
<ConfirmDrawer
title="Confirm activating keyset"
description="Are you sure you want to activate the keyset for this quote?"
open={activateKeysetConfirmDrawerOpen}
onOpenChange={setActivateKeysetConfirmDrawerOpen}
onSubmit={() => {
onActivateKeyset()
setActivateKeysetConfirmDrawerOpen(false)
keysetActive = true
}}
submitButtonText="Yes, activate keyset"
trigger={
<Button
className="flex-1"
disabled={isFetching || activateKeysetMutation.isPending || keysetActive}
variant="default"
>
Activate Keyset {activateKeysetMutation.isPending && <LoaderIcon className="stroke-1 animate-spin" />}
</Button>

Check warning on line 437 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L418-L437

Added lines #L418 - L437 were not covered by tests
}
/>

Check warning on line 439 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L439

Added line #L439 was not covered by tests
) : (
<></>

Check warning on line 441 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L441

Added line #L441 was not covered by tests
)}
</div>
)
}
Expand Down Expand Up @@ -565,8 +586,6 @@
function PayeePublicDataCard({ value }: { value?: PayeePublicData }) {
if (!value) return null

console.log("Payee public data", value)

if ("Ident" in value) {
const identData = (value as { Ident: IdentityPublicData }).Ident
return IdentityPublicDataCard({ value: identData })
Expand All @@ -579,6 +598,25 @@
}

function Quote({ value, isFetching }: { value: InfoReply; isFetching: boolean }) {
const shouldFetchKeyset = (value.status === "Offered" || value.status === "Accepted") && "keyset_id" in value

Check warning on line 601 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L601

Added line #L601 was not covered by tests

const keysetId = "keyset_id" in value ? value.keyset_id : ""

Check warning on line 603 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L603

Added line #L603 was not covered by tests

const { data: keysetData } = useQuery({
queryKey: ["keyset", keysetId],
queryFn: () =>
keysetInfo({
path: { keyset_id: keysetId },
}),
enabled: shouldFetchKeyset,
})

Check warning on line 612 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L605-L612

Added lines #L605 - L612 were not covered by tests

let keysetActive = false
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be something like

const keysetActive = keysetData?.data?.active ?? false;

It would also check for null in addition to undefined. Basically, anything that's not { data: { active: true } } would be false, which it looks like you're trying to do here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you ! Yes I will try your approach it seems simpler.

if (keysetData) {
if ("data" in keysetData && keysetData.data !== undefined) {
keysetActive = keysetData.data.active
}
}

Check warning on line 619 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L614-L619

Added lines #L614 - L619 were not covered by tests
return (
<div className="flex flex-col gap-1">
<Table className="my-2">
Expand All @@ -589,6 +627,25 @@
<span className="font-mono">{value.id}</span>
</TableCell>
</TableRow>
{(value.status === "Offered" || value.status === "Accepted") && "keyset_id" in value ? (
<TableRow>
<TableCell className="font-bold">Keyset ID: </TableCell>
<TableCell className="flex items-center gap-2">
{keysetId.length > 0 ? (
<Badge
variant={keysetActive ? "default" : "destructive"}
className={keysetActive ? "bg-blue-500" : "bg-red-500"}

Check warning on line 637 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L630-L637

Added lines #L630 - L637 were not covered by tests
>
{keysetId}
</Badge>

Check warning on line 640 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L639-L640

Added lines #L639 - L640 were not covered by tests
) : (
<></>

Check warning on line 642 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L642

Added line #L642 was not covered by tests
)}
</TableCell>
</TableRow>

Check warning on line 645 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L644-L645

Added lines #L644 - L645 were not covered by tests
) : (
<></>

Check warning on line 647 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L647

Added line #L647 was not covered by tests
)}
<TableRow>
<TableCell className="font-bold">Status: </TableCell>
<TableCell>
Expand All @@ -601,6 +658,18 @@
<TableCell className="font-bold">Sum: </TableCell>
<TableCell>{formatNumber("en", value.bill?.sum)} sat</TableCell>
</TableRow>
{(value.status === "Offered" ||
value.status === "Accepted" ||
value.status === "Rejected" ||
value.status === "OfferExpired") &&
"discounted" in value ? (
<TableRow>
<TableCell className="font-bold">Discounted: </TableCell>
<TableCell>{formatNumber("en", value.discounted)} crsat</TableCell>
</TableRow>

Check warning on line 669 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L661-L669

Added lines #L661 - L669 were not covered by tests
) : (
<></>

Check warning on line 671 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L671

Added line #L671 was not covered by tests
)}
<TableRow>
<TableCell className="font-bold">Maturity date: </TableCell>
<TableCell>
Expand Down Expand Up @@ -646,7 +715,7 @@
</TableBody>
</Table>

<QuoteActions value={value} isFetching={isFetching} />
<QuoteActions value={value} isFetching={isFetching} keysetActive={keysetActive} />

Check warning on line 718 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L718

Added line #L718 was not covered by tests
</div>
)
}
Expand Down
Loading