Skip to content

Commit

Permalink
feat: add disclaimer button logic
Browse files Browse the repository at this point in the history
  • Loading branch information
CumpsD committed Feb 5, 2024
1 parent 36f9213 commit 9afbf6a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
4 changes: 2 additions & 2 deletions swappy-bot/Commands/Quote/Quote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ private static MessageComponent BuildIntroButtons(
return new ComponentBuilder()
.WithButton(
"Swap",
$"swap-step1-{stateId}",
$"swap-step1-{stateId}-false",
ButtonStyle.Primary,
swapEmoji,
disabled: !swapEnabled)
.WithButton(
"Disclaimer",
$"disclaimer-{stateId}",
$"disclaimer-initial-{stateId}",
ButtonStyle.Secondary,
disclaimerEmoji,
disabled: !swapEnabled)
Expand Down
52 changes: 39 additions & 13 deletions swappy-bot/Commands/Swap/Swap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ public async Task Disclaimer(
await DeferAsync(ephemeral: true);

await ModifyOriginalResponseAsync(x =>
x.Components = BuildIntroButtons(stateId, false));
x.Components = BuildIntroButtons(
stateId,
swapEnabled: false,
addDisclaimer: true,
fromDisclaimer: true));

var buttons = BuildIntroButtons(
stateId,
Expand Down Expand Up @@ -552,7 +556,12 @@ await Context.Channel.SendMessageAsync(

swapState.DestinationAddress = address;

var swapButtons = BuildSwapButtons("swap-step6", stateId, true);
var swapButtons = BuildSwapButtons(
"swap-step6",
stateId,
enabled: true,
addDisclaimer: true,
fromDisclaimer: false);

await Context.Channel.SendMessageAsync(
$"You are ready to perform a swap from **{assetFrom.Name} ({assetFrom.Ticker})** to **{assetTo.Name} ({assetTo.Ticker})**.\n" +
Expand Down Expand Up @@ -595,9 +604,17 @@ public async Task DisclaimerFinal(
await ModifyOriginalResponseAsync(x =>
x.Components = BuildSwapButtons(
"swap-step6",
stateId));
stateId,
enabled: false,
addDisclaimer: false,
fromDisclaimer: false));

var swapButtons = BuildSwapButtons("swap-step6", stateId, true, false);
var swapButtons = BuildSwapButtons(
"swap-step6",
stateId,
enabled: true,
addDisclaimer: false,
fromDisclaimer: true);

await Context.Channel.SendMessageAsync(
"This Discord Bot, `swappy!`, is offered as an unofficial open-source tool ([github.com/CumpsD/swappy](https://github.com/CumpsD/swappy)) to perform non-custodial swaps over the [Chainflip Protocol](https://chainflip.io).\n\n" +
Expand All @@ -613,9 +630,10 @@ await Context.Channel.SendMessageAsync(
stateId);
}

[ComponentInteraction("swap-step6-ok-*")]
[ComponentInteraction("swap-step6-ok-*-*")]
public async Task SwapStep6Approve(
string stateId)
string stateId,
bool fromDisclaimer)
{
await DeferAsync(ephemeral: true);

Expand All @@ -626,7 +644,10 @@ public async Task SwapStep6Approve(
await ModifyOriginalResponseAsync(x =>
x.Components = BuildSwapButtons(
"swap-step6",
stateId));
stateId,
enabled: false,
addDisclaimer: !fromDisclaimer,
fromDisclaimer: false));

await Context.Channel.SendMessageAsync(
"ℹ️ Chainflip is generating a **Deposit Address** for your swap, please wait a few seconds.");
Expand Down Expand Up @@ -748,9 +769,10 @@ await notificationChannel.SendMessageAsync(
$"Use `/swap` to use my services as well. 😎");
}

[ComponentInteraction("swap-step6-nok-*")]
[ComponentInteraction("swap-step6-nok-*-*")]
public async Task SwapStep6Cancel(
string stateId)
string stateId,
bool fromDisclaimer)
{
await DeferAsync(ephemeral: true);

Expand All @@ -761,7 +783,10 @@ public async Task SwapStep6Cancel(
await ModifyOriginalResponseAsync(x =>
x.Components = BuildSwapButtons(
"swap-step6",
stateId));
stateId,
enabled: false,
addDisclaimer: !fromDisclaimer,
fromDisclaimer: false));

await Context.Channel.SendMessageAsync(
"You **cancelled** your swap. No worries, feel free to type `/swap` in the main channel and come back any time! 😎");
Expand Down Expand Up @@ -872,20 +897,21 @@ private static MessageComponent BuildSwapButtons(
string id,
string stateId,
bool enabled = false,
bool addDisclaimer = true)
bool addDisclaimer = true,
bool fromDisclaimer = false)
{
var swapEmoji = new Emoji("🚀");

var builder = new ComponentBuilder()
.WithButton(
"Swap!",
$"{id}-ok-{stateId}",
$"{id}-ok-{stateId}-{fromDisclaimer}",
ButtonStyle.Success,
swapEmoji,
disabled: !enabled)
.WithButton(
"Cancel",
$"{id}-nok-{stateId}",
$"{id}-nok-{stateId}-{fromDisclaimer}",
ButtonStyle.Danger,
disabled: !enabled);

Expand Down

0 comments on commit 9afbf6a

Please sign in to comment.