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: Add network query #214

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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.

4 changes: 4 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { SendInscription } from './components/sendInscriptions';
import AddressDisplay from './components/AddressDisplay';
import { GetAddresses } from './components/bitcoin/GetAddresses.tsx';
import { SendBtc } from './components/bitcoin/SendBtc';
import ChangeNetwork from './components/ChangeNetwork/index.tsx';
import { CreateInscription } from './components/createInscription/index.tsx';
import EtchRunes from './components/EtchRunes';
import MintRunes from './components/MintRunes';
Expand Down Expand Up @@ -151,6 +152,7 @@ function AppWithProviders({ children }: React.PropsWithChildren) {
useEffect(() => {
(async function () {
const res = await Wallet.request('wallet_getAccount', undefined);
console.log('~ getAccount response:', res);

if (res.status === 'error' && res.error.code === (RpcErrorCode.ACCESS_DENIED as number)) {
// The app doesn't have permission to read from this account. Clear
Expand Down Expand Up @@ -228,6 +230,7 @@ function AppWithProviders({ children }: React.PropsWithChildren) {
message: 'Cool app wants to know your addresses!',
addresses: [AddressPurpose.Payment, AddressPurpose.Ordinals, AddressPurpose.Stacks],
});
console.log('~ Connect response:', res);
if (res.status === 'error') {
console.error('Error connecting to wallet, details in terminal.');
console.error(res);
Expand Down Expand Up @@ -298,6 +301,7 @@ const WalletMethods = () => {
<WalletType />
<GetPermissions />
<GetNetwork />
<ChangeNetwork />
<GetAccounts />
</>
);
Expand Down
48 changes: 48 additions & 0 deletions example/src/components/ChangeNetwork/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Button, Card, NativeSelect } from '@mantine/core';
import { useState } from 'react';
import Wallet, { BitcoinNetworkType } from 'sats-connect';

const ChangeNetwork = () => {
const [desiredNetwork, setDesiredNetwork] = useState<BitcoinNetworkType>(
BitcoinNetworkType.Testnet4,
);
const handleChangeNetwork = async () => {
const response = await Wallet.request('wallet_changeNetwork', {
name: desiredNetwork,
});

if (response.status === 'error') {
alert('Error changing network check logs for more info');
console.error(response);
return;
}

alert('Wallet Network changed');
};
return (
<Card>
<h3>Change Network</h3>
<div style={{ marginBottom: 15 }}>
<div>Network</div>
<NativeSelect
defaultValue={desiredNetwork}
onChange={(e) => setDesiredNetwork(e.target.value as BitcoinNetworkType)}
>
<option value={BitcoinNetworkType.Mainnet}>{BitcoinNetworkType.Mainnet}</option>
<option value={BitcoinNetworkType.Testnet}>{BitcoinNetworkType.Testnet}</option>
<option value={BitcoinNetworkType.Testnet4}>{BitcoinNetworkType.Testnet4}</option>
<option value={BitcoinNetworkType.Signet}>{BitcoinNetworkType.Signet}</option>
<option value={BitcoinNetworkType.Regtest}>{BitcoinNetworkType.Regtest}</option>
</NativeSelect>
</div>
<Button
onClick={() => {
handleChangeNetwork().catch(console.error);
}}
>
Change Network
</Button>
</Card>
);
};
export default ChangeNetwork;
Loading
Loading