Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const connect = async (): Promise => {
// Check if connection is already established
if (!walletConnector.connected) {
createConnector();
// create new session
await walletConnector.createSession();
// get uri for QR Code modal
const uri = walletConnector.uri;
// display QR Code modal
WalletConnectQRCodeModal.open(uri, () => {
console.log('QR Code Modal closed');
});
subscribe();
} else {
await walletConnector.killSession();
}
};
await this.setState({ walletConnector });
// check if already connected
if (!walletConnector.connected) {
// create new session
await walletConnector.createSession();
// get uri for QR Code modal
const uri = walletConnector.uri;
// console log the uri for development
console.log(uri); // tslint:disable-line
// display QR Code modal
WalletConnectQRCodeModal.open(uri, () => {
console.log("QR Code Modal closed"); // tslint:disable-line
});
}
// subscribe to events
await this.subscribeToEvents();
};
public subscribeToEvents = () => {
switchMap(() => {
const result = new Subject();
const uri = this.connector.uri;
console.log(uri);
let ignoreClose = false;
// display QR Code modal
WalletConnectQRCodeModal.open(uri, () => {
if (!ignoreClose) {
result.error(Errors.REJECTED_BY_USER);
}
});
// hack to make QR code window above ng-bootstrap windows
document.getElementById("walletconnect-qrcode-modal").style.zIndex =
"9999999999";
this.connector.on("connect", (error, payload) => {
if (error) {
result.error(error);
}
ignoreClose = true;
// Close QR Code Modal
WalletConnectQRCodeModal.close();
this.wc.on('connect', (err: Error | null, payload: any) => {
if (err) {
this.emit('error', err)
return
}
this.connected = true
if (this.qrcode) {
WCQRCode.close() // Close QR Code Modal
}
// Handle session update
this.updateState(payload.params[0])
// Emit connect event
this.emit('connect')
})
this.wc.on('connect', (err: Error | null, payload: any) => {
if (err) {
this.emit('error', err)
return
}
this.connected = true
if (this.qrcode) {
WCQRCode.close() // Close QR Code Modal
}
// Handle session update
this.updateState(payload.params[0])
// Emit connect event
this.emit('connect')
})
wc.on('connect', (error, payload) => {
if (this.qrcode) {
WalletConnectQRCodeModal.close()
}
if (error) {
this.isConnecting = false
return reject(error)
}
this.isConnecting = false
this.connected = true
if (payload) {
// Handle session update
this.updateState(payload.params[0])
}
// Emit connect event
this.emit('connect')
this.triggerConnect(wc)
walletConnector.on('connect', (error: string) => {
if (error) {
console.log('Error on connect:' + error);
}
// Close QR Code Modal
WalletConnectQRCodeModal.close();
});
.then(() => {
if (this.qrcode) {
WalletConnectQRCodeModal.open(wc.uri, () => {
reject(new Error('User closed WalletConnect modal'))
})
}
wc.on('connect', (error, payload) => {
if (this.qrcode) {
WalletConnectQRCodeModal.close()
}
if (error) {
this.isConnecting = false
return reject(error)
}
this.isConnecting = false
this.connected = true
if (payload) {
// Handle session update
this.connector.on("connect", (error, payload) => {
if (error) {
result.error(error);
}
ignoreClose = true;
// Close QR Code Modal
WalletConnectQRCodeModal.close();
result.next(true);
});
return result;
public openQRCode () {
const uri = this.wc ? this.wc.uri : ''
if (uri) {
WCQRCode.open(uri, () => {
this.emit('error', new Error('User close WalletConnect QR Code modal'))
})
}
}
public create () {