Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(SPV-971): Removed deleted tab, added option to add xpub directly #984

Merged
merged 20 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b6c5696
feat(SPV-971): Removed deleted tab, Added option to add xpub directly
Nazarii-4chain Aug 2, 2024
52f345f
Merge branch 'adminV2' into SPV-971/XPubPageAdj
Nazarii-4chain Aug 2, 2024
e5e1b0f
Merge branch 'adminV2' into SPV-971/XPubPageAdj
Nazarii-4chain Aug 12, 2024
e0c2d5b
Merge branch 'adminV2' into SPV-971/XPubPageAdj
Nazarii-4chain Aug 13, 2024
65bf631
Merge branch 'adminV2' of https://github.com/bitcoin-sv/spv-wallet-ad…
Nazarii-4chain Aug 13, 2024
9229f89
Merge branch 'adminV2' into SPV-971/XPubPageAdj
Nazarii-4chain Aug 13, 2024
701f194
feat(SPV-971): Fixed imports
Nazarii-4chain Aug 13, 2024
aba0d2c
Merge branch 'adminV2' into SPV-971/XPubPageAdj
Nazarii-4chain Aug 14, 2024
7546370
Merge branch 'adminV2' into SPV-971/XPubPageAdj
Nazarii-4chain Aug 15, 2024
cdcd912
feat(SPV-971): Added xpub auto-convert function
Nazarii-4chain Aug 16, 2024
f0ce3dd
Merge branch 'adminV2' of https://github.com/bitcoin-sv/spv-wallet-ad…
Nazarii-4chain Aug 16, 2024
3817b90
Merge branch 'adminV2' into SPV-971/XPubPageAdj
Nazarii-4chain Aug 16, 2024
e87c336
Merge branch 'adminV2' into SPV-971/XPubPageAdj
Nazarii-4chain Aug 19, 2024
cc40afc
Merge branch 'adminV2' of https://github.com/bitcoin-sv/spv-wallet-ad…
Nazarii-4chain Aug 20, 2024
cfb5025
Merge remote-tracking branch 'origin/SPV-971/XPubPageAdj' into SPV-97…
Nazarii-4chain Aug 20, 2024
1477080
feat(SPV-971): fix styles issue
Nazarii-4chain Aug 20, 2024
e68c270
Merge branch 'adminV2' into SPV-971/XPubPageAdj
Nazarii-4chain Aug 20, 2024
0aae4f1
Merge branch 'adminV2' of https://github.com/bitcoin-sv/spv-wallet-ad…
Nazarii-4chain Aug 21, 2024
0db38ce
feat(SPV-971): Added validation for xpriv and xpub fields
Nazarii-4chain Aug 27, 2024
34c6bbc
feat(SPV-971): Added additional schema to validate field
Nazarii-4chain Aug 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 35 additions & 23 deletions src/components/AddXpubDialog/AddXpubDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { HD } from '@bsv/sdk';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { CirclePlus } from 'lucide-react';

import React, { useEffect, useState } from 'react';
import React, { useState } from 'react';

import { toast } from 'sonner';

import { useDebounce } from 'use-debounce';

import { Button } from '@/components/ui';
import {
Dialog,
Expand All @@ -28,9 +26,9 @@ interface AddXpubDialogProps {
}

export const AddXpubDialog = ({ className }: AddXpubDialogProps) => {
const [isOpen, setIsOpen] = useState(false);
const [xPriv, setXPriv] = useState<string>('');
const [xPub, setXPub] = useState<string>('');
const [debouncedXPriv] = useDebounce(xPriv, 500);
const queryClient = useQueryClient();

const { spvWalletClient } = useSpvWalletClient();
Expand All @@ -47,20 +45,15 @@ export const AddXpubDialog = ({ className }: AddXpubDialogProps) => {
setXPriv(event.target.value);
};

useEffect(() => {
setXPub('');
if (!xPriv) return;
const handleXPubChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setXPub(event.target.value);
};

try {
const xPrivHD = HD.fromString(debouncedXPriv);
const xPubString = xPrivHD.toPublic().toString();
setXPub(xPubString);
toast.success('Converted xPriv to xPub');
} catch (error) {
toast.error('Unable to convert xPriv to xPub');
setXPub('');
}
}, [debouncedXPriv]);
const handeDialogToggle = () => {
setIsOpen((prev) => !prev);
setXPriv('');
setXPub('');
};

const onSubmit = async () => {
if (!xPub) return;
Expand All @@ -75,8 +68,22 @@ export const AddXpubDialog = ({ className }: AddXpubDialogProps) => {
errorWrapper(error);
}
};

const onGet = () => {
dorzepowski marked this conversation as resolved.
Show resolved Hide resolved
if (!xPriv) return;

try {
const xPrivHD = HD.fromString(xPriv);
const xPubString = xPrivHD.toPublic().toString();
setXPub(xPubString);
toast.success('Converted xPriv to xPub');
} catch (error) {
toast.error('Unable to convert xPriv to xPub');
setXPub('');
}
};
return (
<Dialog>
<Dialog open={isOpen} onOpenChange={handeDialogToggle}>
<DialogTrigger asChild className={className}>
<Button size="sm" variant="secondary" className="h-10 gap-1">
<CirclePlus className="mr-1" size={16} />
Expand All @@ -86,20 +93,25 @@ export const AddXpubDialog = ({ className }: AddXpubDialogProps) => {
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>Add xPub</DialogTitle>
<DialogDescription>Register a new xPub here.</DialogDescription>
<DialogDescription>Get xpub from xpriv</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="grid grid-cols-4 items-center gap-4">
<div className="grid grid-cols-[1fr_8fr_2fr] items-center gap-4">
<Label htmlFor="xPriv" className="text-right">
xPriv
</Label>
<Input id="xPriv" placeholder="xprv..." value={xPriv} onChange={handleXPrivChange} className="col-span-3" />
<Input id="xPriv" placeholder="xprv..." value={xPriv} onChange={handleXPrivChange} className="" />
<Button variant="secondary" onClick={onGet}>
Get
</Button>
</div>
<div className="grid grid-cols-4 items-center gap-4">
<div className="flex justify-center text-gray-400 text-xs">Or put xpub directly</div>

<div className="grid grid-cols-[1fr_10fr] items-center gap-4">
dorzepowski marked this conversation as resolved.
Show resolved Hide resolved
<Label htmlFor="xPub" className="text-right">
xPub
</Label>
<Input id="xPub" readOnly value={xPub} className="col-span-3" />
<Input id="xPub" value={xPub} onChange={handleXPubChange} className="" />
dorzepowski marked this conversation as resolved.
Show resolved Hide resolved
dorzepowski marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
<DialogFooter>
Expand Down
8 changes: 1 addition & 7 deletions src/routes/admin/_admin.xpub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@/components';
import { useSpvWalletClient } from '@/contexts';

import { addStatusField, getDeletedElements, xPubQueryOptions } from '@/utils';
import { addStatusField, xPubQueryOptions } from '@/utils';

export const Route = createFileRoute('/admin/_admin/xpub')({
validateSearch: z.object({
Expand All @@ -44,8 +44,6 @@ export function Xpub() {

const mappedXpubs = addStatusField(xpubs);

const deletedXpubs = getDeletedElements(mappedXpubs);

// TODO: Add server pagination for xpubs when search and count will be merged

return (
Expand All @@ -54,7 +52,6 @@ export function Xpub() {
<div className="flex items-center justify-between">
<TabsList>
<TabsTrigger value="all">All</TabsTrigger>
<TabsTrigger value="deleted">Deleted</TabsTrigger>
</TabsList>
<div className="flex">
<AddXpubDialog className="mr-3" />
Expand All @@ -64,9 +61,6 @@ export function Xpub() {
<TabsContent value="all">
<XpubsTabContent xpubs={mappedXpubs} />
</TabsContent>
<TabsContent value="deleted">
<XpubsTabContent xpubs={deletedXpubs} />
</TabsContent>
</Tabs>
<Toaster position="bottom-center" />
</>
Expand Down