@1sat/react 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SigmaCallback.d.ts +25 -0
- package/dist/SigmaCallback.d.ts.map +1 -0
- package/dist/context.d.ts +57 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/hooks.d.ts +186 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +137 -16
- package/dist/wallet-context.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface SigmaCallbackProps {
|
|
3
|
+
/** Where to redirect after successful auth (default: '/') */
|
|
4
|
+
redirectTo?: string;
|
|
5
|
+
/** Server-side route that exchanges code for tokens (default: /api/auth/sigma/callback) */
|
|
6
|
+
serverCallbackUrl?: string;
|
|
7
|
+
/** Custom loading content */
|
|
8
|
+
loadingContent?: ReactNode;
|
|
9
|
+
/** Custom error render */
|
|
10
|
+
renderError?: (error: string, goBack: () => void) => ReactNode;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Generic Sigma OAuth callback page component.
|
|
14
|
+
*
|
|
15
|
+
* Place this as the default export of your callback route page:
|
|
16
|
+
* ```tsx
|
|
17
|
+
* // app/auth/sigma/callback/page.tsx
|
|
18
|
+
* import { SigmaCallback } from '@1sat/react'
|
|
19
|
+
* export default function Page() {
|
|
20
|
+
* return <SigmaCallback redirectTo="/dashboard" />
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function SigmaCallback({ redirectTo, serverCallbackUrl, loadingContent, renderError, }: SigmaCallbackProps): import("react/jsx-runtime").JSX.Element;
|
|
25
|
+
//# sourceMappingURL=SigmaCallback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SigmaCallback.d.ts","sourceRoot":"","sources":["../src/SigmaCallback.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAA;AAI3D,MAAM,WAAW,kBAAkB;IAClC,6DAA6D;IAC7D,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,2FAA2F;IAC3F,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,6BAA6B;IAC7B,cAAc,CAAC,EAAE,SAAS,CAAA;IAC1B,0BAA0B;IAC1B,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,KAAK,SAAS,CAAA;CAC9D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,EAC7B,UAAgB,EAChB,iBAA8C,EAC9C,cAAc,EACd,WAAW,GACX,EAAE,kBAAkB,2CAoGpB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type ConnectResult, type OneSatProvider as OneSatProviderInterface } from '@1sat/connect';
|
|
2
|
+
import { type ReactNode } from 'react';
|
|
3
|
+
export interface OneSatContextValue {
|
|
4
|
+
/** The underlying provider instance */
|
|
5
|
+
provider: OneSatProviderInterface | null;
|
|
6
|
+
/** Whether the wallet is connected */
|
|
7
|
+
isConnected: boolean;
|
|
8
|
+
/** Whether a connection is in progress */
|
|
9
|
+
isConnecting: boolean;
|
|
10
|
+
/** The payment address (if connected) */
|
|
11
|
+
paymentAddress: string | null;
|
|
12
|
+
/** The ordinal address (if connected) */
|
|
13
|
+
ordinalAddress: string | null;
|
|
14
|
+
/** The identity public key (if connected) */
|
|
15
|
+
identityPubKey: string | null;
|
|
16
|
+
/** Connect to the wallet */
|
|
17
|
+
connect: () => Promise<ConnectResult>;
|
|
18
|
+
/** Disconnect from the wallet */
|
|
19
|
+
disconnect: () => Promise<void>;
|
|
20
|
+
/** Any connection error */
|
|
21
|
+
error: Error | null;
|
|
22
|
+
}
|
|
23
|
+
export interface OneSatProviderProps {
|
|
24
|
+
/** Name of the dApp (shown in approval popup) */
|
|
25
|
+
appName?: string;
|
|
26
|
+
/** Base URL for the wallet popup (default: https://1sat.market) */
|
|
27
|
+
popupUrl?: string;
|
|
28
|
+
/** Request timeout in milliseconds (default: 300000 = 5 minutes) */
|
|
29
|
+
timeout?: number;
|
|
30
|
+
/** Network to use (default: main) */
|
|
31
|
+
network?: 'main' | 'test';
|
|
32
|
+
/** Children to render */
|
|
33
|
+
children: ReactNode;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* React provider for 1Sat wallet functionality
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```tsx
|
|
40
|
+
* import { OneSatProvider } from '@1sat/react'
|
|
41
|
+
*
|
|
42
|
+
* function App() {
|
|
43
|
+
* return (
|
|
44
|
+
* <OneSatProvider appName="My dApp">
|
|
45
|
+
* <MyApp />
|
|
46
|
+
* </OneSatProvider>
|
|
47
|
+
* )
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function OneSatProvider({ appName, popupUrl, timeout, network, children, }: OneSatProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
52
|
+
/**
|
|
53
|
+
* Hook to access the 1Sat context
|
|
54
|
+
* @throws Error if used outside of OneSatProvider
|
|
55
|
+
*/
|
|
56
|
+
export declare function useOneSatContext(): OneSatContextValue;
|
|
57
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":"AAEA,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,cAAc,IAAI,uBAAuB,EAE9C,MAAM,eAAe,CAAA;AACtB,OAAO,EACN,KAAK,SAAS,EAOd,MAAM,OAAO,CAAA;AAEd,MAAM,WAAW,kBAAkB;IAClC,uCAAuC;IACvC,QAAQ,EAAE,uBAAuB,GAAG,IAAI,CAAA;IACxC,sCAAsC;IACtC,WAAW,EAAE,OAAO,CAAA;IACpB,0CAA0C;IAC1C,YAAY,EAAE,OAAO,CAAA;IACrB,yCAAyC;IACzC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,yCAAyC;IACzC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,6CAA6C;IAC7C,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,4BAA4B;IAC5B,OAAO,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,CAAA;IACrC,iCAAiC;IACjC,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/B,2BAA2B;IAC3B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACnB;AAID,MAAM,WAAW,mBAAmB;IACnC,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACzB,yBAAyB;IACzB,QAAQ,EAAE,SAAS,CAAA;CACnB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,EAC9B,OAAO,EACP,QAAQ,EACR,OAAO,EACP,OAAO,EACP,QAAQ,GACR,EAAE,mBAAmB,2CAqGrB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,kBAAkB,CAMrD"}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { CancelListingRequest, CreateListingRequest, InscribeRequest, OrdinalOutput, PurchaseListingRequest, SendOrdinalsRequest, SignTransactionRequest, TokenOutput, TransferTokenRequest, Utxo } from '@1sat/connect';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to get the wallet balance
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* function Balance() {
|
|
8
|
+
* const { satoshis, isLoading } = useBalance()
|
|
9
|
+
* if (isLoading) return <span>Loading...</span>
|
|
10
|
+
* return <span>{satoshis} sats</span>
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function useBalance(): {
|
|
15
|
+
satoshis: number;
|
|
16
|
+
usd: number;
|
|
17
|
+
isLoading: boolean;
|
|
18
|
+
error: Error | null;
|
|
19
|
+
refetch: () => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Hook to get ordinals from the wallet
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* function Gallery() {
|
|
27
|
+
* const { ordinals, isLoading } = useOrdinals()
|
|
28
|
+
* if (isLoading) return <span>Loading...</span>
|
|
29
|
+
* return ordinals.map(ord => <div key={ord.outpoint}>{ord.origin}</div>)
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function useOrdinals(limit?: number, offset?: number): {
|
|
34
|
+
ordinals: OrdinalOutput[];
|
|
35
|
+
isLoading: boolean;
|
|
36
|
+
error: Error | null;
|
|
37
|
+
refetch: () => Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Hook to get tokens from the wallet
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* function Tokens() {
|
|
45
|
+
* const { tokens, isLoading } = useTokens()
|
|
46
|
+
* if (isLoading) return <span>Loading...</span>
|
|
47
|
+
* return tokens.map(t => <div key={t.outpoint}>{t.symbol}: {t.amount}</div>)
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function useTokens(limit?: number, offset?: number): {
|
|
52
|
+
tokens: TokenOutput[];
|
|
53
|
+
isLoading: boolean;
|
|
54
|
+
error: Error | null;
|
|
55
|
+
refetch: () => Promise<void>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Hook to get payment UTXOs from the wallet
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```tsx
|
|
62
|
+
* function Utxos() {
|
|
63
|
+
* const { utxos, refetch } = useUtxos()
|
|
64
|
+
* return <span>{utxos.length} UTXOs available</span>
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function useUtxos(): {
|
|
69
|
+
utxos: Utxo[];
|
|
70
|
+
isLoading: boolean;
|
|
71
|
+
error: Error | null;
|
|
72
|
+
refetch: () => Promise<void>;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Hook for signing transactions
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```tsx
|
|
79
|
+
* const { signTransaction, isLoading } = useSignTransaction()
|
|
80
|
+
* const result = await signTransaction({ rawtx, description: 'Send payment' })
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function useSignTransaction(): {
|
|
84
|
+
signTransaction: (request: SignTransactionRequest) => Promise<import("@1sat/connect").SignTransactionResult>;
|
|
85
|
+
isLoading: boolean;
|
|
86
|
+
error: Error | null;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Hook for signing messages (BSM)
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```tsx
|
|
93
|
+
* const { signMessage, isLoading } = useSignMessage()
|
|
94
|
+
* const result = await signMessage('Hello, World!')
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function useSignMessage(): {
|
|
98
|
+
signMessage: (message: string) => Promise<import("@1sat/connect").SignMessageResult>;
|
|
99
|
+
isLoading: boolean;
|
|
100
|
+
error: Error | null;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Hook for inscribing ordinals
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```tsx
|
|
107
|
+
* const { inscribe, isLoading } = useInscribe()
|
|
108
|
+
* const result = await inscribe({ dataB64, contentType: 'text/plain' })
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare function useInscribe(): {
|
|
112
|
+
inscribe: (request: InscribeRequest) => Promise<import("@1sat/connect").InscribeResult>;
|
|
113
|
+
isLoading: boolean;
|
|
114
|
+
error: Error | null;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Hook for sending ordinals
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```tsx
|
|
121
|
+
* const { sendOrdinals, isLoading } = useSendOrdinals()
|
|
122
|
+
* await sendOrdinals({ outpoints: ['txid_0'], destinationAddress: 'addr' })
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare function useSendOrdinals(): {
|
|
126
|
+
sendOrdinals: (request: SendOrdinalsRequest) => Promise<import("@1sat/connect").SendResult>;
|
|
127
|
+
isLoading: boolean;
|
|
128
|
+
error: Error | null;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Hook for transferring tokens (BSV20/21)
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```tsx
|
|
135
|
+
* const { transferToken, isLoading } = useTransferToken()
|
|
136
|
+
* await transferToken({ tokenId: 'origin_0', amount: '100', destinationAddress: 'addr' })
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare function useTransferToken(): {
|
|
140
|
+
transferToken: (request: TransferTokenRequest) => Promise<import("@1sat/connect").SendResult>;
|
|
141
|
+
isLoading: boolean;
|
|
142
|
+
error: Error | null;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Hook for creating marketplace listings
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```tsx
|
|
149
|
+
* const { createListing, isLoading } = useCreateListing()
|
|
150
|
+
* await createListing({ outpoints: ['txid_0'], priceSatoshis: 100000 })
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare function useCreateListing(): {
|
|
154
|
+
createListing: (request: CreateListingRequest) => Promise<import("@1sat/connect").ListingResult>;
|
|
155
|
+
isLoading: boolean;
|
|
156
|
+
error: Error | null;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Hook for purchasing a listed ordinal
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```tsx
|
|
163
|
+
* const { purchaseListing, isLoading } = usePurchaseListing()
|
|
164
|
+
* await purchaseListing({ listingOutpoint: 'txid_0' })
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export declare function usePurchaseListing(): {
|
|
168
|
+
purchaseListing: (request: PurchaseListingRequest) => Promise<import("@1sat/connect").SendResult>;
|
|
169
|
+
isLoading: boolean;
|
|
170
|
+
error: Error | null;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Hook for cancelling marketplace listings
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```tsx
|
|
177
|
+
* const { cancelListing, isLoading } = useCancelListing()
|
|
178
|
+
* await cancelListing({ listingOutpoints: ['txid_0'] })
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export declare function useCancelListing(): {
|
|
182
|
+
cancelListing: (request: CancelListingRequest) => Promise<import("@1sat/connect").SendResult>;
|
|
183
|
+
isLoading: boolean;
|
|
184
|
+
error: Error | null;
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEX,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAEf,aAAa,EACb,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,WAAW,EACX,oBAAoB,EACpB,IAAI,EACJ,MAAM,eAAe,CAAA;AA6CtB;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU;;;;;;EAkCzB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;;;;;EAgC1D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;;;;;EAgCxD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ;;;;;EA4BvB;AAID;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB;;;;EASjC;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc;;;;EAO7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW;;;;EAO1B;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe;;;;EAS9B;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB;;;;EAS/B;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB;;;;EAS/B;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB;;;;EASjC;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB;;;;EAS/B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from '@1sat/connect';
|
|
2
2
|
export { WalletProvider, useWallet, type WalletContextValue, type WalletProviderProps, type WalletStatus, } from './wallet-context';
|
|
3
|
+
export { SigmaCallback, type SigmaCallbackProps } from './SigmaCallback';
|
|
3
4
|
export { ConnectButton, type ConnectButtonProps } from './ConnectButton';
|
|
4
5
|
export { WalletSelector, type WalletSelectorProps, type WalletSelectorProviderInfo, type WalletSelectorRenderProps, } from './WalletSelector';
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAA;AAG7B,OAAO,EACN,cAAc,EACd,SAAS,EACT,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,YAAY,GACjB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,EACN,cAAc,EACd,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,GAC9B,MAAM,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAA;AAG7B,OAAO,EACN,cAAc,EACd,SAAS,EACT,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,YAAY,GACjB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAGxE,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,EACN,cAAc,EACd,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,GAC9B,MAAM,kBAAkB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,8 @@ export * from "@1sat/connect";
|
|
|
6
6
|
// src/wallet-context.tsx
|
|
7
7
|
import {
|
|
8
8
|
connectWallet,
|
|
9
|
-
getAvailableProviders
|
|
9
|
+
getAvailableProviders,
|
|
10
|
+
reconnectSigma
|
|
10
11
|
} from "@1sat/connect";
|
|
11
12
|
import {
|
|
12
13
|
createContext,
|
|
@@ -103,30 +104,50 @@ function WalletProvider({
|
|
|
103
104
|
}, [availableProviders, providers, applyResult]);
|
|
104
105
|
const mountRef = useRef({
|
|
105
106
|
autoDetect,
|
|
107
|
+
providers,
|
|
106
108
|
availableProviders,
|
|
107
109
|
connect,
|
|
108
110
|
applyResult
|
|
109
111
|
});
|
|
110
|
-
mountRef.current = {
|
|
112
|
+
mountRef.current = {
|
|
113
|
+
autoDetect,
|
|
114
|
+
providers,
|
|
115
|
+
availableProviders,
|
|
116
|
+
connect,
|
|
117
|
+
applyResult
|
|
118
|
+
};
|
|
111
119
|
useEffect(() => {
|
|
112
120
|
const {
|
|
113
121
|
autoDetect: auto,
|
|
114
|
-
|
|
122
|
+
providers: providerConfigs,
|
|
123
|
+
availableProviders: available,
|
|
115
124
|
connect: doConnect,
|
|
116
125
|
applyResult: apply
|
|
117
126
|
} = mountRef.current;
|
|
118
127
|
const stored = loadStored();
|
|
119
128
|
if (stored) {
|
|
120
129
|
setStatus("connecting");
|
|
121
|
-
|
|
130
|
+
if (stored.providerType === "sigma" && stored.bapId) {
|
|
131
|
+
const sigmaConfig = providerConfigs?.find((p) => p.type === "sigma" && ("clientId" in p));
|
|
132
|
+
if (sigmaConfig) {
|
|
133
|
+
reconnectSigma(sigmaConfig, stored.bapId).then(apply).catch(() => {
|
|
134
|
+
clearStored();
|
|
135
|
+
if (auto)
|
|
136
|
+
doConnect();
|
|
137
|
+
else
|
|
138
|
+
setStatus("selecting");
|
|
139
|
+
});
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const provider = available.find((p) => p.type === stored.providerType);
|
|
122
144
|
if (provider) {
|
|
123
145
|
provider.connect().then(apply).catch(() => {
|
|
124
146
|
clearStored();
|
|
125
|
-
if (auto)
|
|
147
|
+
if (auto)
|
|
126
148
|
doConnect();
|
|
127
|
-
|
|
149
|
+
else
|
|
128
150
|
setStatus("selecting");
|
|
129
|
-
}
|
|
130
151
|
});
|
|
131
152
|
return;
|
|
132
153
|
}
|
|
@@ -168,8 +189,107 @@ function useWallet() {
|
|
|
168
189
|
}
|
|
169
190
|
return ctx;
|
|
170
191
|
}
|
|
192
|
+
// src/SigmaCallback.tsx
|
|
193
|
+
import { completeSigmaOAuth, isSigmaCallback } from "@1sat/connect";
|
|
194
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
195
|
+
import { jsx as jsx2, jsxs, Fragment } from "react/jsx-runtime";
|
|
196
|
+
"use client";
|
|
197
|
+
var STORAGE_KEY2 = "onesat_wallet_provider";
|
|
198
|
+
function SigmaCallback({
|
|
199
|
+
redirectTo = "/",
|
|
200
|
+
serverCallbackUrl = "/api/auth/sigma/callback",
|
|
201
|
+
loadingContent,
|
|
202
|
+
renderError
|
|
203
|
+
}) {
|
|
204
|
+
const [error, setError] = useState2(null);
|
|
205
|
+
useEffect2(() => {
|
|
206
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
207
|
+
if (!isSigmaCallback(searchParams)) {
|
|
208
|
+
setError("Invalid callback — missing or mismatched OAuth parameters.");
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
completeSigmaOAuth(searchParams, serverCallbackUrl).then((result) => {
|
|
212
|
+
localStorage.setItem(STORAGE_KEY2, JSON.stringify({
|
|
213
|
+
providerType: "sigma",
|
|
214
|
+
identityKey: result.pubkey,
|
|
215
|
+
bapId: result.bapId,
|
|
216
|
+
user: result.user,
|
|
217
|
+
accessToken: result.accessToken
|
|
218
|
+
}));
|
|
219
|
+
window.location.href = redirectTo;
|
|
220
|
+
}).catch((err) => {
|
|
221
|
+
console.error("Sigma OAuth callback error:", err);
|
|
222
|
+
setError(err instanceof Error ? err.message : "Authentication failed");
|
|
223
|
+
});
|
|
224
|
+
}, [redirectTo, serverCallbackUrl]);
|
|
225
|
+
if (error) {
|
|
226
|
+
if (renderError) {
|
|
227
|
+
return /* @__PURE__ */ jsx2(Fragment, {
|
|
228
|
+
children: renderError(error, () => {
|
|
229
|
+
window.location.href = "/";
|
|
230
|
+
})
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
return /* @__PURE__ */ jsx2("div", {
|
|
234
|
+
style: {
|
|
235
|
+
display: "flex",
|
|
236
|
+
minHeight: "100vh",
|
|
237
|
+
alignItems: "center",
|
|
238
|
+
justifyContent: "center",
|
|
239
|
+
padding: "1rem"
|
|
240
|
+
},
|
|
241
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
242
|
+
style: { maxWidth: "28rem", width: "100%" },
|
|
243
|
+
children: [
|
|
244
|
+
/* @__PURE__ */ jsx2("h2", {
|
|
245
|
+
style: {
|
|
246
|
+
fontSize: "1.125rem",
|
|
247
|
+
fontWeight: 600,
|
|
248
|
+
marginBottom: "0.5rem"
|
|
249
|
+
},
|
|
250
|
+
children: "Authentication Error"
|
|
251
|
+
}),
|
|
252
|
+
/* @__PURE__ */ jsx2("p", {
|
|
253
|
+
style: { fontSize: "0.875rem", color: "#666" },
|
|
254
|
+
children: error
|
|
255
|
+
}),
|
|
256
|
+
/* @__PURE__ */ jsx2("button", {
|
|
257
|
+
type: "button",
|
|
258
|
+
onClick: () => {
|
|
259
|
+
window.location.href = "/";
|
|
260
|
+
},
|
|
261
|
+
style: {
|
|
262
|
+
marginTop: "1rem",
|
|
263
|
+
padding: "0.5rem 1rem",
|
|
264
|
+
fontSize: "0.875rem",
|
|
265
|
+
cursor: "pointer"
|
|
266
|
+
},
|
|
267
|
+
children: "Go Back"
|
|
268
|
+
})
|
|
269
|
+
]
|
|
270
|
+
})
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
if (loadingContent) {
|
|
274
|
+
return /* @__PURE__ */ jsx2(Fragment, {
|
|
275
|
+
children: loadingContent
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
return /* @__PURE__ */ jsx2("div", {
|
|
279
|
+
style: {
|
|
280
|
+
display: "flex",
|
|
281
|
+
minHeight: "100vh",
|
|
282
|
+
alignItems: "center",
|
|
283
|
+
justifyContent: "center"
|
|
284
|
+
},
|
|
285
|
+
children: /* @__PURE__ */ jsx2("p", {
|
|
286
|
+
style: { color: "#666" },
|
|
287
|
+
children: "Connecting wallet..."
|
|
288
|
+
})
|
|
289
|
+
});
|
|
290
|
+
}
|
|
171
291
|
// src/ConnectButton.tsx
|
|
172
|
-
import { jsx as
|
|
292
|
+
import { jsx as jsx3, Fragment as Fragment2 } from "react/jsx-runtime";
|
|
173
293
|
"use client";
|
|
174
294
|
function truncateIdentityKey(key) {
|
|
175
295
|
if (key.length <= 12)
|
|
@@ -213,7 +333,7 @@ function ConnectButton({
|
|
|
213
333
|
}
|
|
214
334
|
};
|
|
215
335
|
if (children) {
|
|
216
|
-
return /* @__PURE__ */
|
|
336
|
+
return /* @__PURE__ */ jsx3(Fragment2, {
|
|
217
337
|
children: children({
|
|
218
338
|
isConnected,
|
|
219
339
|
isConnecting,
|
|
@@ -224,7 +344,7 @@ function ConnectButton({
|
|
|
224
344
|
});
|
|
225
345
|
}
|
|
226
346
|
if (isConnecting) {
|
|
227
|
-
return /* @__PURE__ */
|
|
347
|
+
return /* @__PURE__ */ jsx3("button", {
|
|
228
348
|
className,
|
|
229
349
|
style,
|
|
230
350
|
disabled: true,
|
|
@@ -234,7 +354,7 @@ function ConnectButton({
|
|
|
234
354
|
}
|
|
235
355
|
if (isConnected) {
|
|
236
356
|
const label = typeof connectedLabel === "function" ? connectedLabel(identityKey ?? "") : connectedLabel ?? truncateIdentityKey(identityKey ?? "");
|
|
237
|
-
return /* @__PURE__ */
|
|
357
|
+
return /* @__PURE__ */ jsx3("button", {
|
|
238
358
|
className,
|
|
239
359
|
style,
|
|
240
360
|
onClick: disconnectOnClick ? disconnect : undefined,
|
|
@@ -242,7 +362,7 @@ function ConnectButton({
|
|
|
242
362
|
children: label
|
|
243
363
|
});
|
|
244
364
|
}
|
|
245
|
-
return /* @__PURE__ */
|
|
365
|
+
return /* @__PURE__ */ jsx3("button", {
|
|
246
366
|
className,
|
|
247
367
|
style,
|
|
248
368
|
onClick: connect,
|
|
@@ -251,12 +371,12 @@ function ConnectButton({
|
|
|
251
371
|
});
|
|
252
372
|
}
|
|
253
373
|
// src/WalletSelector.tsx
|
|
254
|
-
import { useCallback as useCallback2, useState as
|
|
255
|
-
import { jsx as
|
|
374
|
+
import { useCallback as useCallback2, useState as useState3 } from "react";
|
|
375
|
+
import { jsx as jsx4, Fragment as Fragment3 } from "react/jsx-runtime";
|
|
256
376
|
"use client";
|
|
257
377
|
function WalletSelector({ onClose, children }) {
|
|
258
378
|
const { availableProviders, connect, error } = useWallet();
|
|
259
|
-
const [connectingType, setConnectingType] =
|
|
379
|
+
const [connectingType, setConnectingType] = useState3(null);
|
|
260
380
|
const handleConnect = useCallback2(async (providerType) => {
|
|
261
381
|
setConnectingType(providerType);
|
|
262
382
|
try {
|
|
@@ -274,7 +394,7 @@ function WalletSelector({ onClose, children }) {
|
|
|
274
394
|
isConnecting: connectingType === p.type,
|
|
275
395
|
connect: () => handleConnect(p.type)
|
|
276
396
|
}));
|
|
277
|
-
return /* @__PURE__ */
|
|
397
|
+
return /* @__PURE__ */ jsx4(Fragment3, {
|
|
278
398
|
children: children({ providers, error })
|
|
279
399
|
});
|
|
280
400
|
}
|
|
@@ -282,5 +402,6 @@ export {
|
|
|
282
402
|
useWallet,
|
|
283
403
|
WalletSelector,
|
|
284
404
|
WalletProvider,
|
|
405
|
+
SigmaCallback,
|
|
285
406
|
ConnectButton
|
|
286
407
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-context.d.ts","sourceRoot":"","sources":["../src/wallet-context.tsx"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"wallet-context.d.ts","sourceRoot":"","sources":["../src/wallet-context.tsx"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,iBAAiB,EAGtB,KAAK,oBAAoB,EAIzB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,EACN,KAAK,SAAS,EAQd,MAAM,OAAO,CAAA;AAEd,MAAM,MAAM,YAAY,GACrB,cAAc,GACd,WAAW,GACX,WAAW,GACX,YAAY,GACZ,WAAW,CAAA;AAEd,MAAM,WAAW,kBAAkB;IAClC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAA;IAC9B,MAAM,EAAE,YAAY,CAAA;IACpB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,kBAAkB,EAAE,iBAAiB,EAAE,CAAA;IACvC,OAAO,EAAE,CAAC,YAAY,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACjD,UAAU,EAAE,MAAM,IAAI,CAAA;IACtB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACnB;AAED,MAAM,WAAW,mBAAmB;IACnC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,SAAS,CAAC,EAAE,oBAAoB,EAAE,CAAA;IAClC,QAAQ,EAAE,SAAS,CAAA;CACnB;AAyCD,wBAAgB,cAAc,CAAC,EAC9B,UAAiB,EACjB,SAAS,EACT,QAAQ,GACR,EAAE,mBAAmB,2CAsKrB;AAED,wBAAgB,SAAS,IAAI,kBAAkB,CAM9C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1sat/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "React hooks and components for 1Sat wallet integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"keywords": ["1sat", "bsv", "ordinals", "wallet", "sdk", "react", "hooks"],
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@1sat/connect": "0.0.
|
|
22
|
+
"@1sat/connect": "0.0.11"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@bsv/sdk": "^2.0.0",
|