Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the text for the "/connect" command #106

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions src/modules/walletconnect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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",
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -126,28 +132,51 @@ 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();

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) {
Expand All @@ -159,6 +188,8 @@ export class WalletConnect {
}
}



async send(ctx: OnMessageContext, addr: string, amount: string) {
const signClient = await getSignClient();
const userId = ctx.from.id;
Expand Down