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

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.1",
3
+ "version": "1.3.3",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "start": "tsc -b tsconfig.build.json --watch --verbose",
package/src/index.ts CHANGED
@@ -20,7 +20,7 @@ import {PoolManager} from "./stackswap/manager/pool.manager";
20
20
  import {PoxlManager} from "./stackswap/manager/poxl.manager";
21
21
  import {StakingManager} from "./stackswap/manager/staking.manager";
22
22
  import {SwapManager} from "./stackswap/manager/swap.manager";
23
- import {AppConfig, showConnect, UserSession} from "@stacks/connect";
23
+ import {connect, disconnect, isConnected as isWalletConnected, getLocalStorage} from "@stacks/connect";
24
24
  import {LBTCStakingManager} from "./stackswap/manager/lbtcstaking.manager";
25
25
  import {GroupFarmManager} from "./stackswap/manager/groupfarm.manager";
26
26
  import {BridgeManager} from "./stackswap/manager/bridge.manager";
@@ -143,104 +143,117 @@ export class StackswapMainnetAPI implements StackswapAPI{
143
143
  }
144
144
 
145
145
  walletConnect(callback: (err: any, result: any) => void): void {
146
- try {
147
- const appConfig = new AppConfig(['store_write', 'publish_data']);
148
- const userSession = new UserSession({ appConfig });
149
- showConnect({
150
- userSession,
151
- appDetails: {
152
- name: 'Stackswap',
153
- icon: 'https://app.stackswap.org/favicon.ico',
154
- },
155
- redirectTo: '/',
156
- onFinish: () => {
157
- const profile = userSession.loadUserData().profile.stxAddress;
158
- if (this.config.isMainnet()){
159
- this.senderAdderss = profile.mainnet;
160
- } else {
161
- this.senderAdderss = profile.testnet;
162
- }
163
- this.connected = true;
146
+ connect()
147
+ .then((result) => {
148
+ // DEBUG: Log connect() result to understand address selection
149
+ console.log('[walletConnect] connect() raw result:', JSON.stringify(result, null, 2));
164
150
 
165
- callback(null, this.senderAdderss);
166
- },
167
- });
168
- } catch (e) {
169
- callback(e, null);
170
- }
171
- }
151
+ // STX addresses start with 'SP' (mainnet) or 'ST' (testnet)
152
+ const stxAddresses = result.addresses.filter(a =>
153
+ a.address.startsWith('SP') || a.address.startsWith('ST')
154
+ );
172
155
 
156
+ console.log('[walletConnect] STX addresses found:', stxAddresses);
157
+ console.log('[walletConnect] isMainnet:', this.config.isMainnet());
173
158
 
174
- walletConnect2(userSession: UserSession, callback: (err: any, result: any) => void): void {
175
- try {
176
- showConnect({
177
- appDetails: {
178
- name: 'Stackswap',
179
- icon: 'https://app.stackswap.org/favicon.ico',
180
- },
181
- redirectTo: '/',
182
- onFinish: () => {
183
- const profile = userSession.loadUserData().profile.stxAddress;
184
- if (this.config.isMainnet()){
185
- this.senderAdderss = profile.mainnet;
186
- } else {
187
- this.senderAdderss = profile.testnet;
188
- }
189
- this.connected = true;
159
+ const address = this.config.isMainnet()
160
+ ? stxAddresses.find(a => a.address.startsWith('SP'))?.address
161
+ : stxAddresses.find(a => a.address.startsWith('ST'))?.address;
162
+
163
+ console.log('[walletConnect] Selected address:', address);
190
164
 
165
+ if (address) {
166
+ this.senderAdderss = address;
167
+ this.connected = true;
191
168
  callback(null, this.senderAdderss);
192
- },
193
- userSession
169
+ } else {
170
+ callback(new Error('No STX address found'), null);
171
+ }
172
+ })
173
+ .catch((e) => {
174
+ callback(e, null);
194
175
  });
195
- } catch (e) {
196
- callback(e, null);
197
- }
176
+ }
177
+
178
+
179
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
180
+ walletConnect2(_userSession: any, callback: (err: any, result: any) => void): void {
181
+ // Note: userSession is deprecated in @stacks/connect v8, using new connect() API
182
+ this.walletConnect(callback);
198
183
  }
199
184
 
200
185
 
201
186
  getConnectedWallet(callback: (err: any, result: any) => void): void {
202
187
  try {
203
- const appConfig = new AppConfig(['store_write', 'publish_data']);
204
- const userSession = new UserSession({ appConfig });
205
- const profile = userSession.loadUserData().profile.stxAddress;
206
- if (this.config.isMainnet()){
207
- this.senderAdderss = profile.mainnet;
208
- } else {
209
- this.senderAdderss = profile.testnet;
188
+ const storage = getLocalStorage();
189
+ if (!storage || !storage.addresses?.stx?.length) {
190
+ callback(new Error('No connected wallet'), null);
191
+ return;
210
192
  }
211
- this.connected = true;
212
193
 
213
- callback(null, this.senderAdderss);
194
+ const stxAddresses = storage.addresses.stx;
195
+ // SP = mainnet, ST = testnet
196
+ const address = this.config.isMainnet()
197
+ ? stxAddresses.find(a => a.address.startsWith('SP'))?.address
198
+ : stxAddresses.find(a => a.address.startsWith('ST'))?.address;
199
+
200
+ if (address) {
201
+ this.senderAdderss = address;
202
+ this.connected = true;
203
+ callback(null, this.senderAdderss);
204
+ } else {
205
+ callback(new Error('No STX address found'), null);
206
+ }
214
207
  } catch (e) {
215
- callback( e, null);
208
+ callback(e, null);
216
209
  }
217
210
  }
218
211
 
219
212
  signOut(callback: (err: any, result: any) => void): void {
220
213
  try {
221
- const appConfig = new AppConfig(['store_write', 'publish_data']);
222
- const userSession = new UserSession({ appConfig });
223
- userSession.signUserOut();
224
-
214
+ disconnect();
215
+ this.connected = false;
216
+ this.senderAdderss = '';
225
217
  callback(null, 'success');
226
218
  } catch (e) {
227
- callback( e, null);
219
+ callback(e, null);
228
220
  }
229
221
  }
230
222
 
231
223
  isConnected(): boolean {
232
224
  try {
233
- const appConfig = new AppConfig(['store_write', 'publish_data']);
234
- const userSession = new UserSession({ appConfig });
235
- const profile = userSession.loadUserData().profile.stxAddress;
236
- if (this.config.isMainnet()){
237
- this.senderAdderss = profile.mainnet;
238
- } else {
239
- this.senderAdderss = profile.testnet;
225
+ console.log('[isConnected] isWalletConnected():', isWalletConnected());
226
+ if (!isWalletConnected()) {
227
+ return false;
240
228
  }
241
- this.connected = true;
242
- return true;
229
+
230
+ const storage = getLocalStorage();
231
+ console.log('[isConnected] getLocalStorage():', JSON.stringify(storage, null, 2));
232
+
233
+ if (!storage || !storage.addresses?.stx?.length) {
234
+ console.log('[isConnected] No storage or no STX addresses');
235
+ return false;
236
+ }
237
+
238
+ const stxAddresses = storage.addresses.stx;
239
+ console.log('[isConnected] STX addresses:', stxAddresses);
240
+ console.log('[isConnected] isMainnet:', this.config.isMainnet());
241
+
242
+ // SP = mainnet, ST = testnet
243
+ const address = this.config.isMainnet()
244
+ ? stxAddresses.find(a => a.address.startsWith('SP'))?.address
245
+ : stxAddresses.find(a => a.address.startsWith('ST'))?.address;
246
+
247
+ console.log('[isConnected] Selected address:', address);
248
+
249
+ if (address) {
250
+ this.senderAdderss = address;
251
+ this.connected = true;
252
+ return true;
253
+ }
254
+ return false;
243
255
  } catch (e) {
256
+ console.log('[isConnected] Error:', e);
244
257
  return false;
245
258
  }
246
259
  }