Skip to content

Commit 8a7aeef

Browse files
Feat/unisat signet (#143)
* chore: try unisat signet * chore: upgrade bob sdk version * Create chilly-bugs-guess.md
1 parent a878b6f commit 8a7aeef

File tree

4 files changed

+231
-34
lines changed

4 files changed

+231
-34
lines changed

.changeset/chilly-bugs-guess.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@gobob/sats-wagmi": patch
3+
---
4+
5+
Feat/unisat signet

packages/sats-wagmi/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
},
5050
"dependencies": {
5151
"@bitcoin-js/tiny-secp256k1-asmjs": "^2.2.3",
52-
"@gobob/bob-sdk": "^3.1.4",
52+
"@gobob/bob-sdk": "3.1.7-alpha0",
5353
"@metamask/providers": "^12.0.0",
5454
"@scure/base": "^1.1.6",
5555
"@scure/btc-signer": "^1.3.1",

packages/sats-wagmi/src/connectors/unisat.ts

+10-26
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,13 @@ import { PsbtInputAccounts, SatsConnector } from './base';
66

77
type WalletNetwork = 'livenet' | 'testnet';
88

9-
const getLibNetwork = (network: WalletNetwork): Network => {
10-
switch (network) {
11-
case 'livenet':
12-
return Network.mainnet;
13-
case 'testnet':
14-
return Network.testnet;
15-
}
16-
};
17-
18-
const getUnisatNetwork = (network: Network): WalletNetwork => {
19-
switch (network) {
20-
default:
21-
case Network.mainnet:
22-
return 'livenet';
23-
case Network.testnet:
24-
return 'testnet';
25-
}
26-
};
9+
type WalletChain =
10+
| 'BITCOIN_MAINNET'
11+
| 'BITCOIN_TESTNET'
12+
| 'BITCOIN_TESTNET4'
13+
| 'BITCOIN_SIGNET'
14+
| 'FRACTAL_BITCOIN_MAINNET'
15+
| 'FRACTAL_BITCOIN_TESTNET';
2716

2817
type AccountsChangedEvent = (event: 'accountsChanged', handler: (accounts: Array<string>) => void) => void;
2918

@@ -36,7 +25,9 @@ type UniSatBase = {
3625
requestAccounts: () => Promise<string[]>;
3726
getAccounts: () => Promise<string[]>;
3827
getNetwork: () => Promise<WalletNetwork>;
28+
getChain: () => Promise<WalletChain>;
3929
switchNetwork: (network: WalletNetwork) => Promise<void>;
30+
switchChain: (network: WalletChain) => Promise<void>;
4031
getPublicKey: () => Promise<string>;
4132
getBalance: () => Promise<Balance>;
4233
signMessage: (msg: string, type?: 'ecdsa' | 'bip322-simple') => Promise<string>;
@@ -120,14 +111,7 @@ class UnisatConnector extends SatsConnector {
120111
async connect(): Promise<void> {
121112
const walletSource = this.getSource()!;
122113

123-
const network = await walletSource.getNetwork();
124-
const mappedNetwork = getLibNetwork(network);
125-
126-
if (mappedNetwork !== this.network) {
127-
const expectedNetwork = getUnisatNetwork(this.network);
128-
129-
await walletSource.switchNetwork(expectedNetwork);
130-
}
114+
await walletSource.switchChain('BITCOIN_SIGNET');
131115

132116
const [accounts, publicKey] = await Promise.all([walletSource.requestAccounts(), walletSource.getPublicKey()]);
133117

0 commit comments

Comments
 (0)