From b61bb4e98d77adea5c05e2b8b29607df55b0bb5f Mon Sep 17 00:00:00 2001 From: tuanddd Date: Tue, 27 Feb 2024 10:56:15 +0700 Subject: [PATCH] fix: add to watchlist from ticker flow --- src/commands/ticker/index/slash.ts | 3 +- src/commands/watchlist/add/processor.ts | 52 ++++++++++++++----------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/commands/ticker/index/slash.ts b/src/commands/ticker/index/slash.ts index ce9b6d007..547a7ee5a 100644 --- a/src/commands/ticker/index/slash.ts +++ b/src/commands/ticker/index/slash.ts @@ -97,8 +97,7 @@ export const machineConfig: ( return await addToWatchlistFromTicker( interaction, interaction.user.id, - ctx.to, - ctx.baseCoin.id, + ctx, ) }, showOtherTicker: (_interaction, _ev, ctx) => { diff --git a/src/commands/watchlist/add/processor.ts b/src/commands/watchlist/add/processor.ts index d677604ff..87504b103 100644 --- a/src/commands/watchlist/add/processor.ts +++ b/src/commands/watchlist/add/processor.ts @@ -61,16 +61,14 @@ export async function addToWatchlist(i: ButtonInteraction) { export async function addToWatchlistFromTicker( i: ButtonInteraction, userId: string, - symbol: string, - coingeckoId: string, + { to, baseCoin, ...rest }: Record, ) { - if (!i.deferred) await i.deferUpdate().catch(() => null) const msg = i.message as Message const data = await addUserWatchlist( msg, userId, - symbol.toLowerCase(), - coingeckoId, + to.toLowerCase(), + baseCoin.id, ) if (!data) return null @@ -82,24 +80,32 @@ export async function addToWatchlistFromTicker( .join(" ") } - await msg.edit({ - attachments: [], - embeds: [ - getSuccessEmbed({ - title: `${symbolString([symbol])} has been added to the watchlist`, - description: `${getEmoji( - "ANIMATED_POINTING_RIGHT", - true, - )} View watchlist with ${await getSlashCommand( - "wlv", - )} (alias for ${await getSlashCommand("watchlist view")})\n${getEmoji( - "ANIMATED_POINTING_RIGHT", - true, - )} To remove, use ${await getSlashCommand("watchlist remove")}`, - }), - ], - components: [], - }) + return { + initial: "addWatchList", + context: { + to, + baseCoin, + ...rest, + }, + msgOpts: { + files: [], + embeds: [ + getSuccessEmbed({ + title: `${symbolString([to])} has been added to the watchlist`, + description: `${getEmoji( + "ANIMATED_POINTING_RIGHT", + true, + )} View watchlist with ${await getSlashCommand( + "wlv", + )} (alias for ${await getSlashCommand("watchlist view")})\n${getEmoji( + "ANIMATED_POINTING_RIGHT", + true, + )} To remove, use ${await getSlashCommand("watchlist remove")}`, + }), + ], + components: [], + }, + } } export async function addUserWatchlist(