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

Add getAddresses #169

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion example/package-lock.json

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

12 changes: 10 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { GetRunesBalance } from './components/GetRunesBalance';
import { SendInscription } from './components/sendInscriptions';

import AddressDisplay from './components/AddressDisplay';
import { GetAddresses } from './components/bitcoin/GetAddresses.tsx';
import { SendBtc } from './components/bitcoin/SendBtc';
import EtchRunes from './components/EtchRunes';
import MintRunes from './components/MintRunes';
Expand Down Expand Up @@ -161,8 +162,9 @@ const WalletMethods = () => {
addresses={[...btcAddressInfo, ...stxAddressInfo]}
onDisconnect={onDisconnect}
/>
<GetAccounts />
<GetAddresses />
<WalletType />
<GetAccounts />
</>
);
};
Expand Down Expand Up @@ -235,7 +237,13 @@ const router = createBrowserRouter(
),
);

const queryClient = new QueryClient();
const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: false,
},
},
});

const theme = createTheme({
primaryColor: 'orange',
Expand Down
6 changes: 3 additions & 3 deletions example/src/components/bitcoin/GetAccounts.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Wallet, { AddressPurpose } from 'sats-connect';
import { Button, Card } from '../../App.styles';
import { useQuery } from '@tanstack/react-query';
import Wallet, { AddressPurpose } from 'sats-connect';
import styled from 'styled-components';
import { Button, Card } from '../../App.styles';

const ErrorMessage = styled.div({
color: 'red',
Expand All @@ -24,7 +24,7 @@ export function GetAccounts() {

return (
<Card>
<h3>Get accounts</h3>
<h3>[Legacy] Get accounts</h3>

<Button
onClick={() => {
Expand Down
59 changes: 59 additions & 0 deletions example/src/components/bitcoin/GetAddresses.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useQuery } from '@tanstack/react-query';
import Wallet, { AddressPurpose } from 'sats-connect';
import styled from 'styled-components';
import { Button, Card } from '../../App.styles';

const ErrorMessage = styled.div({
color: 'red',
});

export function GetAddresses() {
const { refetch, error, data, isFetching, isError, isSuccess } = useQuery({
queryKey: ['getAddresses'],
queryFn: async () => {
const res = await Wallet.request('getAddresses', {
purposes: [AddressPurpose.Payment, AddressPurpose.Ordinals, AddressPurpose.Stacks],
});
if (res.status === 'error') {
throw new Error('Error getting wallet type', { cause: res.error });
}
return res.result;
},
enabled: false,
});

return (
<Card>
<h3>Get addresses</h3>

<Button
onClick={() => {
refetch().catch(console.error);
}}
>
Get addresses
</Button>

{(() => {
if (isFetching) {
return <p>Loading...</p>;
}

if (isError) {
console.error(error);
console.error(error.cause);
return <ErrorMessage>Error. Check console for details.</ErrorMessage>;
}

if (isSuccess) {
console.log(data);
return (
<div>
<p>Check console for data.</p>
</div>
);
}
})()}
</Card>
);
}
5 changes: 3 additions & 2 deletions example/src/components/wallet/WalletType.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Wallet from 'sats-connect';
import { Button, Card } from '../../App.styles';
import { useQuery } from '@tanstack/react-query';
import Wallet from 'sats-connect';
import styled from 'styled-components';
import { Button, Card } from '../../App.styles';

const ErrorMessage = styled.div({
color: 'red',
Expand Down Expand Up @@ -39,6 +39,7 @@ export function WalletType() {

if (isError) {
console.error(error);
console.error(error.cause);
return <ErrorMessage>Error. Check console for details.</ErrorMessage>;
}

Expand Down
Loading