Skip to content

Commit

Permalink
Feat/unisat signet (#143)
Browse files Browse the repository at this point in the history
* chore: try unisat signet

* chore: upgrade bob sdk version

* Create chilly-bugs-guess.md
  • Loading branch information
slavastartsev authored Feb 27, 2025
1 parent a878b6f commit 8a7aeef
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-bugs-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@gobob/sats-wagmi": patch
---

Feat/unisat signet
2 changes: 1 addition & 1 deletion packages/sats-wagmi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"dependencies": {
"@bitcoin-js/tiny-secp256k1-asmjs": "^2.2.3",
"@gobob/bob-sdk": "^3.1.4",
"@gobob/bob-sdk": "3.1.7-alpha0",
"@metamask/providers": "^12.0.0",
"@scure/base": "^1.1.6",
"@scure/btc-signer": "^1.3.1",
Expand Down
36 changes: 10 additions & 26 deletions packages/sats-wagmi/src/connectors/unisat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,13 @@ import { PsbtInputAccounts, SatsConnector } from './base';

type WalletNetwork = 'livenet' | 'testnet';

const getLibNetwork = (network: WalletNetwork): Network => {
switch (network) {
case 'livenet':
return Network.mainnet;
case 'testnet':
return Network.testnet;
}
};

const getUnisatNetwork = (network: Network): WalletNetwork => {
switch (network) {
default:
case Network.mainnet:
return 'livenet';
case Network.testnet:
return 'testnet';
}
};
type WalletChain =
| 'BITCOIN_MAINNET'
| 'BITCOIN_TESTNET'
| 'BITCOIN_TESTNET4'
| 'BITCOIN_SIGNET'
| 'FRACTAL_BITCOIN_MAINNET'
| 'FRACTAL_BITCOIN_TESTNET';

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

Expand All @@ -36,7 +25,9 @@ type UniSatBase = {
requestAccounts: () => Promise<string[]>;
getAccounts: () => Promise<string[]>;
getNetwork: () => Promise<WalletNetwork>;
getChain: () => Promise<WalletChain>;
switchNetwork: (network: WalletNetwork) => Promise<void>;
switchChain: (network: WalletChain) => Promise<void>;
getPublicKey: () => Promise<string>;
getBalance: () => Promise<Balance>;
signMessage: (msg: string, type?: 'ecdsa' | 'bip322-simple') => Promise<string>;
Expand Down Expand Up @@ -120,14 +111,7 @@ class UnisatConnector extends SatsConnector {
async connect(): Promise<void> {
const walletSource = this.getSource()!;

const network = await walletSource.getNetwork();
const mappedNetwork = getLibNetwork(network);

if (mappedNetwork !== this.network) {
const expectedNetwork = getUnisatNetwork(this.network);

await walletSource.switchNetwork(expectedNetwork);
}
await walletSource.switchChain('BITCOIN_SIGNET');

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

Expand Down
Loading

0 comments on commit 8a7aeef

Please sign in to comment.