From c3bfb0af336b8af217a79f335fb8a9bf5101c3fb Mon Sep 17 00:00:00 2001 From: ahiipsa Date: Wed, 16 Aug 2023 00:16:25 +0400 Subject: [PATCH] Updated the text for the "/connect" command --- src/modules/walletconnect/index.ts | 49 ++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/src/modules/walletconnect/index.ts b/src/modules/walletconnect/index.ts index 69b2b65b..e8f4c22f 100644 --- a/src/modules/walletconnect/index.ts +++ b/src/modules/walletconnect/index.ts @@ -44,7 +44,8 @@ export class WalletConnect { } public isSupportedEvent(ctx: OnMessageContext) { - return (ctx.hasCommand('get') || ctx.hasCommand('send') || ctx.hasCommand('pools') || ctx.hasCommand('connect')); + const commands = ['get', 'send', 'pools', 'connect', 'connecthex'] + return commands.find((command) => ctx.hasCommand(command)); } public async onEvent(ctx: OnMessageContext) { @@ -60,6 +61,11 @@ export class WalletConnect { return; } + if (ctx.hasCommand('connecthex')) { + this.connecthex(ctx) + return; + } + if (ctx.hasCommand('pools')) { let keyboard = new InlineKeyboard().webApp( "Open", @@ -89,10 +95,10 @@ export class WalletConnect { ctx.reply('Unsupported command'); } - async connect(ctx: OnMessageContext) { + async requestProposal() { const signClient = await getSignClient(); - const { uri, approval } = await signClient.connect({ + return signClient.connect({ requiredNamespaces: { eip155: { methods: [ @@ -126,16 +132,41 @@ export class WalletConnect { } }, }) + } + async connect(ctx: OnMessageContext) { + const { uri, approval } = await this.requestProposal(); const qrImgBuffer = await generateWcQr(uri || '', 480); const message = await ctx.replyWithPhoto(new InputFile(qrImgBuffer, `wallet_connect_${Date.now()}.png`), { - caption: 'Scan QR code with a WalletConnect-compatible wallet' + caption: 'Scan this QR Code to use Wallet Connect with your MetaMask / Gnosis Safe / Timeless wallets\n\nEnter /connecthex to see Web Address', + parse_mode: 'Markdown' }); - const uriMessage = await ctx.reply(`Copy URI: - -\`${uri}\` `, {parse_mode: 'Markdown'}); + try { + const session = await approval(); + + sessionMap[ctx.from.id] = session.topic; + + ctx.api.deleteMessage(ctx.chat.id, message.message_id); + ctx.reply('wallet connected: ' + getUserAddr(session)); + } catch (ex) { + ctx.api.deleteMessage(ctx.chat.id, message.message_id); + if (ex instanceof Error) { + this.logger.error('error wc connect ' + ex.message) + if (ex.message === PROPOSAL_EXPIRY_MESSAGE) { + return; + } + + ctx.reply('Error while connection'); + } + } + } + + async connecthex(ctx: OnMessageContext) { + const {uri, approval} = await this.requestProposal(); + + const message = await ctx.reply(`Copy this connection link to use Wallet Connect with your MetaMask / Gnosis Safe / Timeless wallets:\n\n\`${uri}\` `, {parse_mode: 'Markdown'}); try { const session = await approval(); @@ -143,11 +174,9 @@ export class WalletConnect { sessionMap[ctx.from.id] = session.topic; ctx.api.deleteMessage(ctx.chat.id, message.message_id); - ctx.api.deleteMessage(ctx.chat.id, uriMessage.message_id); ctx.reply('wallet connected: ' + getUserAddr(session)); } catch (ex) { ctx.api.deleteMessage(ctx.chat.id, message.message_id); - ctx.api.deleteMessage(ctx.chat.id, uriMessage.message_id); if (ex instanceof Error) { this.logger.error('error wc connect ' + ex.message) if (ex.message === PROPOSAL_EXPIRY_MESSAGE) { @@ -159,6 +188,8 @@ export class WalletConnect { } } + + async send(ctx: OnMessageContext, addr: string, amount: string) { const signClient = await getSignClient(); const userId = ctx.from.id;