-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for wallet type in sats-connect
- Loading branch information
Showing
6 changed files
with
160 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Wallet, { AddressPurpose } from 'sats-connect'; | ||
import { Button, Card } from '../../App.styles'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import styled from 'styled-components'; | ||
|
||
const ErrorMessage = styled.div({ | ||
color: 'red', | ||
}); | ||
|
||
export function GetAccounts() { | ||
const { refetch, error, data, isFetching, isError, isSuccess } = useQuery({ | ||
queryKey: ['getAccounts'], | ||
queryFn: async () => { | ||
const res = await Wallet.request('getAccounts', { | ||
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 accounts</h3> | ||
|
||
<Button | ||
onClick={() => { | ||
refetch().catch(console.error); | ||
}} | ||
> | ||
Get accounts | ||
</Button> | ||
|
||
{(() => { | ||
if (isFetching) { | ||
return <p>Loading...</p>; | ||
} | ||
|
||
if (isError) { | ||
console.error(error); | ||
return <ErrorMessage>Error. Check console for details.</ErrorMessage>; | ||
} | ||
|
||
if (isSuccess) { | ||
console.log(data); | ||
return ( | ||
<div> | ||
<p>Check console for data.</p> | ||
</div> | ||
); | ||
} | ||
})()} | ||
</Card> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Wallet from 'sats-connect'; | ||
import { Button, Card } from '../../App.styles'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import styled from 'styled-components'; | ||
|
||
const ErrorMessage = styled.div({ | ||
color: 'red', | ||
}); | ||
|
||
export function WalletType() { | ||
const { refetch, error, data, isFetching, isError, isSuccess } = useQuery({ | ||
queryKey: ['wallet_getWalletType'], | ||
queryFn: async () => { | ||
const res = await Wallet.request('wallet_getWalletType', undefined); | ||
if (res.status === 'error') { | ||
throw new Error('Error getting wallet type', { cause: res.error }); | ||
} | ||
return res.result; | ||
}, | ||
enabled: false, | ||
}); | ||
|
||
return ( | ||
<Card> | ||
<h3>Wallet type</h3> | ||
|
||
<Button | ||
onClick={() => { | ||
refetch().catch(console.error); | ||
}} | ||
> | ||
Get wallet type | ||
</Button> | ||
|
||
{(() => { | ||
if (isFetching) { | ||
return <p>Loading...</p>; | ||
} | ||
|
||
if (isError) { | ||
console.error(error); | ||
return <ErrorMessage>Error. Check console for details.</ErrorMessage>; | ||
} | ||
|
||
if (isSuccess) { | ||
return ( | ||
<div> | ||
<p>Wallet type: {data}</p> | ||
</div> | ||
); | ||
} | ||
})()} | ||
</Card> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters