stackswap-front-api-test-02 1.3.1 → 1.3.2
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/esm/index.d.ts +1 -2
- package/dist/esm/index.js +52 -71
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +51 -70
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
- package/src/index.ts +65 -71
package/package.json
CHANGED
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 {
|
|
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,103 +143,97 @@ export class StackswapMainnetAPI implements StackswapAPI{
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
walletConnect(callback: (err: any, result: any) => void): void {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (this.config.isMainnet()){
|
|
159
|
-
this.senderAdderss = profile.mainnet;
|
|
160
|
-
} else {
|
|
161
|
-
this.senderAdderss = profile.testnet;
|
|
162
|
-
}
|
|
146
|
+
connect()
|
|
147
|
+
.then((result) => {
|
|
148
|
+
// STX addresses start with 'SP' (mainnet) or 'ST' (testnet)
|
|
149
|
+
const stxAddresses = result.addresses.filter(a =>
|
|
150
|
+
a.address.startsWith('SP') || a.address.startsWith('ST')
|
|
151
|
+
);
|
|
152
|
+
const address = this.config.isMainnet()
|
|
153
|
+
? stxAddresses.find(a => a.address.startsWith('SP'))?.address
|
|
154
|
+
: stxAddresses.find(a => a.address.startsWith('ST'))?.address;
|
|
155
|
+
|
|
156
|
+
if (address) {
|
|
157
|
+
this.senderAdderss = address;
|
|
163
158
|
this.connected = true;
|
|
164
|
-
|
|
165
159
|
callback(null, this.senderAdderss);
|
|
166
|
-
}
|
|
160
|
+
} else {
|
|
161
|
+
callback(new Error('No STX address found'), null);
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
.catch((e) => {
|
|
165
|
+
callback(e, null);
|
|
167
166
|
});
|
|
168
|
-
} catch (e) {
|
|
169
|
-
callback(e, null);
|
|
170
|
-
}
|
|
171
167
|
}
|
|
172
168
|
|
|
173
169
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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;
|
|
190
|
-
|
|
191
|
-
callback(null, this.senderAdderss);
|
|
192
|
-
},
|
|
193
|
-
userSession
|
|
194
|
-
});
|
|
195
|
-
} catch (e) {
|
|
196
|
-
callback(e, null);
|
|
197
|
-
}
|
|
170
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
171
|
+
walletConnect2(_userSession: any, callback: (err: any, result: any) => void): void {
|
|
172
|
+
// Note: userSession is deprecated in @stacks/connect v8, using new connect() API
|
|
173
|
+
this.walletConnect(callback);
|
|
198
174
|
}
|
|
199
175
|
|
|
200
176
|
|
|
201
177
|
getConnectedWallet(callback: (err: any, result: any) => void): void {
|
|
202
178
|
try {
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
this.senderAdderss = profile.mainnet;
|
|
208
|
-
} else {
|
|
209
|
-
this.senderAdderss = profile.testnet;
|
|
179
|
+
const storage = getLocalStorage();
|
|
180
|
+
if (!storage || !storage.addresses?.stx?.length) {
|
|
181
|
+
callback(new Error('No connected wallet'), null);
|
|
182
|
+
return;
|
|
210
183
|
}
|
|
211
|
-
this.connected = true;
|
|
212
184
|
|
|
213
|
-
|
|
185
|
+
const stxAddresses = storage.addresses.stx;
|
|
186
|
+
// SP = mainnet, ST = testnet
|
|
187
|
+
const address = this.config.isMainnet()
|
|
188
|
+
? stxAddresses.find(a => a.address.startsWith('SP'))?.address
|
|
189
|
+
: stxAddresses.find(a => a.address.startsWith('ST'))?.address;
|
|
190
|
+
|
|
191
|
+
if (address) {
|
|
192
|
+
this.senderAdderss = address;
|
|
193
|
+
this.connected = true;
|
|
194
|
+
callback(null, this.senderAdderss);
|
|
195
|
+
} else {
|
|
196
|
+
callback(new Error('No STX address found'), null);
|
|
197
|
+
}
|
|
214
198
|
} catch (e) {
|
|
215
|
-
callback(
|
|
199
|
+
callback(e, null);
|
|
216
200
|
}
|
|
217
201
|
}
|
|
218
202
|
|
|
219
203
|
signOut(callback: (err: any, result: any) => void): void {
|
|
220
204
|
try {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
205
|
+
disconnect();
|
|
206
|
+
this.connected = false;
|
|
207
|
+
this.senderAdderss = '';
|
|
225
208
|
callback(null, 'success');
|
|
226
209
|
} catch (e) {
|
|
227
|
-
callback(
|
|
210
|
+
callback(e, null);
|
|
228
211
|
}
|
|
229
212
|
}
|
|
230
213
|
|
|
231
214
|
isConnected(): boolean {
|
|
232
215
|
try {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const profile = userSession.loadUserData().profile.stxAddress;
|
|
236
|
-
if (this.config.isMainnet()){
|
|
237
|
-
this.senderAdderss = profile.mainnet;
|
|
238
|
-
} else {
|
|
239
|
-
this.senderAdderss = profile.testnet;
|
|
216
|
+
if (!isWalletConnected()) {
|
|
217
|
+
return false;
|
|
240
218
|
}
|
|
241
|
-
|
|
242
|
-
|
|
219
|
+
|
|
220
|
+
const storage = getLocalStorage();
|
|
221
|
+
if (!storage || !storage.addresses?.stx?.length) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const stxAddresses = storage.addresses.stx;
|
|
226
|
+
// SP = mainnet, ST = testnet
|
|
227
|
+
const address = this.config.isMainnet()
|
|
228
|
+
? stxAddresses.find(a => a.address.startsWith('SP'))?.address
|
|
229
|
+
: stxAddresses.find(a => a.address.startsWith('ST'))?.address;
|
|
230
|
+
|
|
231
|
+
if (address) {
|
|
232
|
+
this.senderAdderss = address;
|
|
233
|
+
this.connected = true;
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
return false;
|
|
243
237
|
} catch (e) {
|
|
244
238
|
return false;
|
|
245
239
|
}
|