stackswap-front-api-test-02 1.3.3 → 1.3.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stackswap-front-api-test-02",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "start": "tsc -b tsconfig.build.json --watch --verbose",
package/src/index.ts CHANGED
@@ -163,6 +163,10 @@ export class StackswapMainnetAPI implements StackswapAPI{
163
163
  console.log('[walletConnect] Selected address:', address);
164
164
 
165
165
  if (address) {
166
+ // Save current address to localStorage for isConnected() to use
167
+ if (typeof window !== 'undefined' && window.localStorage) {
168
+ window.localStorage.setItem('currentStxAddress', address);
169
+ }
166
170
  this.senderAdderss = address;
167
171
  this.connected = true;
168
172
  callback(null, this.senderAdderss);
@@ -212,6 +216,10 @@ export class StackswapMainnetAPI implements StackswapAPI{
212
216
  signOut(callback: (err: any, result: any) => void): void {
213
217
  try {
214
218
  disconnect();
219
+ // Clear saved current address
220
+ if (typeof window !== 'undefined' && window.localStorage) {
221
+ window.localStorage.removeItem('currentStxAddress');
222
+ }
215
223
  this.connected = false;
216
224
  this.senderAdderss = '';
217
225
  callback(null, 'success');
@@ -227,6 +235,28 @@ export class StackswapMainnetAPI implements StackswapAPI{
227
235
  return false;
228
236
  }
229
237
 
238
+ // First, check if we have a saved current address from walletConnect()
239
+ let savedAddress: string | null = null;
240
+ if (typeof window !== 'undefined' && window.localStorage) {
241
+ savedAddress = window.localStorage.getItem('currentStxAddress');
242
+ console.log('[isConnected] Saved currentStxAddress:', savedAddress);
243
+ }
244
+
245
+ // Validate saved address matches network (SP for mainnet, ST for testnet)
246
+ if (savedAddress) {
247
+ const isValidForNetwork = this.config.isMainnet()
248
+ ? savedAddress.startsWith('SP')
249
+ : savedAddress.startsWith('ST');
250
+
251
+ if (isValidForNetwork) {
252
+ console.log('[isConnected] Using saved address:', savedAddress);
253
+ this.senderAdderss = savedAddress;
254
+ this.connected = true;
255
+ return true;
256
+ }
257
+ }
258
+
259
+ // Fallback: use getLocalStorage() if no saved address
230
260
  const storage = getLocalStorage();
231
261
  console.log('[isConnected] getLocalStorage():', JSON.stringify(storage, null, 2));
232
262