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

Add 5% fee to prizes on FE #6878

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use canister_tracing_macros::trace;
use chat_events::MessageContentInternal;
use escrow_canister::deposit_subaccount;
use ic_cdk::api::call::CallResult;
use tracing::error;
use types::icrc1::Account;
use types::{
icrc1, Achievement, CanisterId, Chat, CompletedCryptoTransaction, CryptoTransaction, MessageContentInitial, MessageId,
Expand Down Expand Up @@ -329,8 +330,14 @@ fn prepare(
let oc_fee = (total_prizes * PRIZE_FEE_PERCENT as u128) / 100;
let total_amount_to_send_old = total_prizes + total_transfer_fees;
let total_amount_to_send = total_prizes + total_transfer_fees + oc_fee;

if t.units() != total_amount_to_send && t.units() != total_amount_to_send_old {
let transaction_amount = t.units();

if transaction_amount != total_amount_to_send && transaction_amount != total_amount_to_send_old {
error!(
?total_amount_to_send,
?transaction_amount,
"Expected vs Actual prize transfer"
);
return InvalidRequest("Transaction amount must equal total prizes + total fees".to_string());
}

Expand Down
6 changes: 6 additions & 0 deletions dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@
"candid": "",
"type": "custom",
"wasm": "./wasms/icrc_ledger.wasm.gz"
},
"bot_api_gateway": {
"build": "",
"candid": "",
"type": "custom",
"wasm": "wasms/bot_api_gateway.wasm.gz"
}
},
"networks": {
Expand Down
1 change: 1 addition & 0 deletions frontend/app/src/components/Hoverable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
<style lang="scss">
.noselect {
@include no_user_select();
margin: auto;

&.fill {
width: 100%;
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/src/components/home/ChatEvent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@
on:retrySend={retrySend}
on:editMessage={editEvent}
on:upgrade
on:verifyHumanity
on:claimDailyChit
on:forward
on:expandMessage
on:collapseMessage
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/src/components/home/ChatMessage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@
on:removePreview
on:registerVote={registerVote}
on:upgrade
on:verifyHumanity
on:claimDailyChit
on:startVideoCall
on:expandMessage />

Expand Down
9 changes: 8 additions & 1 deletion frontend/app/src/components/home/ChatMessageContent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@
text={i18nKey(failed ? "p2pSwap.failedToCreateMessage" : "p2pSwap.creatingYourMessage")}
{failed} />
{:else if content.kind === "prize_content"}
<PrizeContent on:upgrade chatId={messageContext.chatId} {messageId} {content} {me} />
<PrizeContent
on:upgrade
on:verifyHumanity
on:claimDailyChit
chatId={messageContext.chatId}
{messageId}
{content}
{me} />
{:else if content.kind === "p2p_swap_content"}
<P2PSwapContent
on:upgrade
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/src/components/home/CurrentChat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@
on:replyTo={replyTo}
on:chatWith
on:upgrade
on:verifyHumanity
on:claimDailyChit
on:forward
on:retrySend
on:startVideoCall
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/src/components/home/CurrentChatMessages.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@
on:expandMessage={() => toggleMessageExpansion(evt, true)}
on:collapseMessage={() => toggleMessageExpansion(evt, false)}
on:upgrade
on:verifyHumanity
on:claimDailyChit
on:forward
on:retrySend
on:startVideoCall
Expand Down
21 changes: 17 additions & 4 deletions frontend/app/src/components/home/Home.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
import { chitPopup } from "../../stores/settings";
import AccessGateEvaluator from "./access/AccessGateEvaluator.svelte";
import SetPinNumberModal from "./profile/SetPinNumberModal.svelte";
import VerifyHumanity from "./profile/VerifyHumanity.svelte";

type ViewProfileConfig = {
userId: string;
Expand Down Expand Up @@ -168,6 +169,7 @@

type ModalType =
| { kind: "none" }
| { kind: "verify_humanity" }
| { kind: "select_chat" }
| { kind: "suspended" }
| { kind: "no_access" }
Expand Down Expand Up @@ -1156,6 +1158,14 @@
$pinNumberStore?.reject();
}

function verifyHumanity() {
modal = { kind: "verify_humanity" };
}

function claimDailyChit() {
modal = { kind: "claim_daily_chit" };
}

$: bgHeight = $dimensions.height * 0.9;
$: bgClip = (($dimensions.height - 32) / bgHeight) * 361;
</script>
Expand All @@ -1182,9 +1192,7 @@
on:leaveCommunity={triggerConfirm}
on:deleteCommunity={triggerConfirm}
on:upgrade={upgrade}
on:claimDailyChit={() => {
modal = { kind: "claim_daily_chit" };
}} />
on:claimDailyChit={claimDailyChit} />
{/if}

{#if $layoutStore.showLeft}
Expand Down Expand Up @@ -1223,6 +1231,8 @@
on:showGroupMembers={showGroupMembers}
on:joinGroup={joinGroup}
on:upgrade={upgrade}
on:verifyHumanity={verifyHumanity}
on:claimDailyChit={claimDailyChit}
on:toggleMuteNotifications={toggleMuteNotifications}
on:goToMessageIndex={goToMessageIndex}
on:forward={forwardMessage}
Expand All @@ -1242,7 +1252,8 @@
on:editCommunity={editCommunity}
on:deleteCommunity={triggerConfirm}
on:newChannel={newChannel}
on:groupCreated={groupCreated} />
on:groupCreated={groupCreated}
on:verifyHumanity={verifyHumanity} />
</main>

{#if $anonUser}
Expand Down Expand Up @@ -1325,6 +1336,8 @@
<DailyChitModal on:leaderboard={leaderboard} on:close={closeModal} />
{:else if modal.kind === "challenge"}
<ChallengeModal on:close={closeModal} />
{:else if modal.kind === "verify_humanity"}
<VerifyHumanity on:close={closeModal} on:success={closeModal} />
{/if}
</Overlay>
{/if}
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/src/components/home/MiddlePanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
on:chatWith
on:joinGroup
on:upgrade
on:verifyHumanity
on:claimDailyChit
on:toggleMuteNotifications
on:goToMessageIndex
on:convertGroupToCommunity
Expand Down
122 changes: 109 additions & 13 deletions frontend/app/src/components/home/PrizeContent.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
<script lang="ts">
import Button from "../Button.svelte";
import Diamond from "../icons/Diamond.svelte";
import type { ChatIdentifier, OpenChat, PrizeContent } from "openchat-client";
import { currentUser as user, isDiamond, cryptoLookup } from "openchat-client";
import {
type ChatIdentifier,
type DiamondMembershipStatus,
type OpenChat,
type PrizeContent,
chitStateStore,
} from "openchat-client";
import {
currentUser as user,
isDiamond,
isLifetimeDiamond,
cryptoLookup,
} from "openchat-client";
import { _ } from "svelte-i18n";
import Clock from "svelte-material-icons/Clock.svelte";
import ButtonGroup from "../ButtonGroup.svelte";
Expand All @@ -15,6 +25,10 @@
import { claimsStore } from "../../stores/claims";
import { i18nKey } from "../../i18n/i18n";
import Translatable from "../Translatable.svelte";
import Badges from "./profile/Badges.svelte";
import Diamond from "../icons/Diamond.svelte";
import Human from "../icons/Human.svelte";
import Streak from "./profile/Streak.svelte";

const client = getContext<OpenChat>("client");
const dispatch = createEventDispatcher();
Expand All @@ -33,19 +47,31 @@
$: claimedByYou = content.winners.includes($user.userId);
$: finished = $now500 >= Number(content.endDate);
$: allClaimed = content.prizesRemaining <= 0;
$: disabled = finished || claimedByYou || allClaimed;
$: disabled = finished || claimedByYou || allClaimed || !userEligible;
$: timeRemaining = finished
? $_("prizes.finished")
: client.formatTimeRemaining($now500, Number(content.endDate));

$: diamondStatus = (
content.lifetimeDiamondOnly ? "lifetime" : content.diamondOnly ? "active" : "inactive"
) as DiamondMembershipStatus["kind"];

$: restrictedPrize =
content.diamondOnly ||
content.lifetimeDiamondOnly ||
content.uniquePersonOnly ||
content.streakOnly > 0;

$: userEligible =
(!content.diamondOnly || $isDiamond) &&
(!content.lifetimeDiamondOnly || $isLifetimeDiamond) &&
(!content.uniquePersonOnly || $user.isUniquePerson) &&
content.streakOnly <= $chitStateStore.streak;

let progressWidth = 0;

function claim(e: MouseEvent) {
if (e.isTrusted && chatId.kind !== "direct_chat" && !me) {
if (!$isDiamond && content.diamondOnly) {
dispatch("upgrade");
return;
}
if (e.isTrusted && chatId.kind !== "direct_chat" && !me && userEligible) {
claimsStore.add(messageId);
client
.claimPrize(chatId, messageId)
Expand All @@ -57,6 +83,18 @@
.finally(() => claimsStore.delete(messageId));
}
}

function onDiamondClick() {
dispatch("upgrade");
}

function onUniquePersonClick() {
dispatch("verifyHumanity");
}

function onStreakClick() {
dispatch("claimDailyChit");
}
</script>

<div class={`prize ${content.token}`}>
Expand All @@ -70,8 +108,11 @@
{timeRemaining}
{/if}
</span>
{#if content.diamondOnly}
<Diamond y={0} size={"1em"} />
{#if restrictedPrize}
<Badges
{diamondStatus}
uniquePerson={content.uniquePersonOnly}
streak={content.streakOnly} />
{/if}
</div>
<div class="prize-coin">
Expand All @@ -85,7 +126,44 @@
</div>
{/if}
{#if !me}
<div class="click"><Translatable resourceKey={i18nKey("prizes.click")} /></div>
{#if restrictedPrize}
<div class="restricted">
<Translatable resourceKey={i18nKey("prizes.restrictedMessage")} />
{#if content.diamondOnly || content.lifetimeDiamondOnly}
<div on:click={onDiamondClick}>
<div>
<Diamond
status={content.lifetimeDiamondOnly ? "lifetime" : "active"} />
</div>
<Translatable
resourceKey={i18nKey(
"prizes." +
(content.lifetimeDiamondOnly
? "lifetimeDiamondMembership"
: "diamondMembership"),
)} />
</div>
{/if}
{#if content.uniquePersonOnly}
<div on:click={onUniquePersonClick}>
<div><Human uniquePerson={content.uniquePersonOnly} /></div>
<Translatable resourceKey={i18nKey("prizes.uniquePerson")} />
</div>
{/if}
{#if content.streakOnly > 0}
<div on:click={onStreakClick}>
<div><Streak days={content.streakOnly} /></div>
<Translatable
resourceKey={i18nKey("prizes.streakFull", {
n: content.streakOnly,
})} />
</div>
{/if}
</div>
{/if}
{#if userEligible}
<div class="click"><Translatable resourceKey={i18nKey("prizes.click")} /></div>
{/if}
{:else if finished}
<div class="click"><Translatable resourceKey={i18nKey("prizes.prizeFinished")} /></div>
{:else}
Expand Down Expand Up @@ -202,7 +280,8 @@
}

.click,
.caption {
.caption,
.restricted {
@include font(book, normal, fs-80);
margin-bottom: $sp4;
}
Expand Down Expand Up @@ -245,4 +324,21 @@
width: 100%;
}
}

.restricted {
display: flex;
flex-direction: column;
gap: $sp2;

div {
display: flex;
flex-direction: row;
gap: $sp3;
cursor: pointer;

:first-child {
width: $sp5;
}
}
}
</style>
Loading
Loading