Skip to content

Commit

Permalink
Merge branch 'develop' into origin/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Metroxe committed Dec 22, 2023
2 parents 608c488 + 94fa835 commit 54bb790
Show file tree
Hide file tree
Showing 51 changed files with 3,451 additions and 781 deletions.
15 changes: 15 additions & 0 deletions apps/cli/src/commands/licenses/generate-revenue-report.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Vorpal from "vorpal";
import { generateRevenueReport as generateRevenueReportCore } from "@sentry/core";

/**
* Function to generate the revenue report.
* @param cli - Vorpal instance
*/
export function generateRevenueReport(cli: Vorpal) {
cli
.command('generate-revenue-report', 'Generates the revenue report.')
.action(async function (this: Vorpal.CommandInstance) {
this.log(`Generating revenue report...`);
await generateRevenueReportCore();
});
}
40 changes: 38 additions & 2 deletions apps/cli/src/commands/operator-control/operator-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Vorpal from "vorpal";
import { getSignerFromPrivateKey, operatorRuntime } from "@sentry/core";
import { getSignerFromPrivateKey, operatorRuntime, listOwnersForOperator } from "@sentry/core";

/**
* Starts a runtime of the operator.
Expand All @@ -17,6 +17,7 @@ export function bootOperator(cli: Vorpal) {
message: 'Enter the private key of the operator:',
mask: '*'
};

const { walletKey } = await this.prompt(walletKeyPrompt);

if (!walletKey || walletKey.length < 1) {
Expand All @@ -25,10 +26,45 @@ export function bootOperator(cli: Vorpal) {

const { signer } = getSignerFromPrivateKey(walletKey);

const whitelistPrompt: Vorpal.PromptObject = {
type: 'confirm',
name: 'useWhitelist',
message: 'Do you want to use a whitelist for the operator runtime?',
default: false
};

const { useWhitelist } = await this.prompt(whitelistPrompt);

// If useWhitelist is false, selectedOwners will be undefined
let selectedOwners;
if (useWhitelist) {

const operatorAddress = await signer.getAddress();
const owners = await listOwnersForOperator(operatorAddress);

const ownerPrompt: Vorpal.PromptObject = {
type: 'checkbox',
name: 'selectedOwners',
message: 'Select the owners for the operator to run for:',
choices: [operatorAddress, ...owners]
};

const result = await this.prompt(ownerPrompt);
selectedOwners = result.selectedOwners;

console.log("selectedOwners", selectedOwners);

if (!selectedOwners || selectedOwners.length < 1) {
throw new Error("No owners selected. Please select at least one owner.")
}
}


stopFunction = await operatorRuntime(
signer,
undefined,
(log) => this.log(log)
(log) => this.log(log),
selectedOwners,
);

return new Promise((resolve, reject) => { }); // Keep the command alive
Expand Down
2 changes: 2 additions & 0 deletions apps/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { setOrAddPricingTiersCommand } from './commands/licenses/set-or-add-pric
import { addPromoCode } from './commands/licenses/add-promo-code.js';
import { removePromoCode } from './commands/licenses/remove-promo-code.js';
import { eventListener } from './commands/event-listener.js';
import { generateRevenueReport } from './commands/licenses/generate-revenue-report.js';

const cli = new Vorpal();

Expand Down Expand Up @@ -89,6 +90,7 @@ setReferralDiscountAndRewardPercentages(cli);
setRollupAddress(cli);
toggleAssertionChecking(cli);
totalSupply(cli);
generateRevenueReport(cli);

cli
.delimiter('sentry-node$')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {useSetAtom} from "jotai";
import {AiFillWarning} from "react-icons/ai";
import {useOperator} from "@/features/operator";
import {modalStateAtom, ModalView} from "@/features/modal/ModalManager";
import {XaiButton} from "@sentry/ui";

export function AssignKeysFromNewWallet() {
const setDrawerState = useSetAtom(drawerStateAtom);
Expand All @@ -25,14 +26,14 @@ export function AssignKeysFromNewWallet() {
Add wallets to assign keys to the Sentry
</p>

<button
<XaiButton
onClick={startAssignment}
disabled={isOperatorLoading}
className="flex justify-center items-center gap-1 text-[15px] text-white bg-[#F30919] font-semibold mt-2 px-6 py-3"
fontSize={"15px"}
>
Assign keys from new wallet
<BiLinkExternal className="w-5 h-5"/>
</button>
</XaiButton>

<p className="text-[15px] text-[#525252] mt-2">
Don't own any keys?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {ViewKeysDrawer} from "../home/modals/view-keys/ViewKeysDrawer";
import {ActionsRequiredNotAccruingDrawer} from "../home/modals/actions-required/ActionsRequiredNotAccruingDrawer";
import {ExportSentryDrawer} from "../home/modals/ExportSentryDrawer";
import {ImportSentryDrawer} from "../home/modals/ImportSentryDrawer";
import {WhitelistDrawer} from "@/features/drawer/WhitelistDrawer";

export enum DrawerView {
ActionsRequiredBuy,
ActionsRequiredNotAccruing,
BuyKeys,
ViewKeys,
Whitelist,
ImportSentry,
ExportSentry,
}
Expand All @@ -23,7 +25,7 @@ export function DrawerManager() {

return (
<div
className={classNames("sticky w-[28rem] min-w-[28rem] h-screen relative z-10 bg-white border border-gray-200 overflow-y-scroll", {
className={classNames("w-[28rem] min-w-[28rem] h-screen z-10 bg-white border border-gray-200 overflow-y-scroll", {
"hidden": drawerState === null,
})}
>
Expand All @@ -43,6 +45,10 @@ export function DrawerManager() {
<ViewKeysDrawer/>
)}

{drawerState === DrawerView.Whitelist && (
<WhitelistDrawer/>
)}

{drawerState === DrawerView.ImportSentry && (
<ImportSentryDrawer/>
)}
Expand Down
145 changes: 145 additions & 0 deletions apps/sentry-client-desktop/src/features/drawer/WhitelistDrawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import {useAtomValue, useSetAtom} from "jotai";
import {drawerStateAtom} from "@/features/drawer/DrawerManager";
import {chainStateAtom} from "@/hooks/useChainDataWithCallback";
import {XaiCheckbox} from "@sentry/ui";
import {useEffect, useState} from "react";
import {useStorage} from "@/features/storage";
import {useOperatorRuntime} from "@/hooks/useOperatorRuntime";
import {useOperator} from "@/features/operator";

export function WhitelistDrawer() {
const setDrawerState = useSetAtom(drawerStateAtom);
const {owners} = useAtomValue(chainStateAtom);
const {data, setData} = useStorage();
const [selected, setSelected] = useState<string[]>([]);
const {sentryRunning, stopRuntime} = useOperatorRuntime();
const {publicKey: operatorAddress} = useOperator();

const disableButton = selected.length <= 0 || !stopRuntime;

useEffect(() => {
if (data && data.whitelistedWallets) {
setSelected(data.whitelistedWallets);
}
}, []);

const toggleSelected = (wallet: string) => {
setSelected((prevSelected) => prevSelected.includes(wallet)
? prevSelected.filter((item) => item !== wallet)
: [...prevSelected, wallet]
);
};

const getOperatorItem = () => {
if (operatorAddress) {
return (
<div>
<div
className="p-2 cursor-pointer hover:bg-gray-100"
>
<XaiCheckbox
onClick={() => toggleSelected(operatorAddress)}
condition={selected.includes(operatorAddress)}
>
{operatorAddress}
</XaiCheckbox>
</div>
</div>
)
}
}

const getDropdownItems = () => (
<div>
{owners.map((wallet, i) => (
<div
className="p-2 cursor-pointer hover:bg-gray-100"
key={`whitelist-item-${i}`}
>
<XaiCheckbox
onClick={() => toggleSelected(wallet)}
condition={selected.includes(wallet)}
>
{wallet}
</XaiCheckbox>
</div>
))}
</div>
);

async function handleSubmit() {
await setData({
...data,
whitelistedWallets: selected,
});

setDrawerState(null);
if (stopRuntime) {
void stopRuntime();
}
}

return (
<div className="relative h-full flex flex-col justify-start items-center">
<div
className="w-full h-[4rem] min-h-[4rem] flex flex-row justify-between items-center border-b border-gray-200 text-lg font-semibold px-8">
<p>Allowed Wallet</p>
</div>

<div className="flex-grow overflow-y-scroll max-h-[calc(100vh-4rem)] px-6 pt-[1rem]">
<p className="mb-2 text-[15px]">
Below are the wallets assigned to your Sentry Wallet ({operatorAddress}). Select the wallets
you'd like to enable.
</p>
<p className="mb-4 text-[15px]">
Note: Gas fees will be covered using your Sentry Wallet funds whenever an enabled wallet is eligible
to participate in a challenge.
</p>
<div>
<p className="text-[12px]">Your Sentry Wallet</p>
{getOperatorItem()}
<p className="text-[12px]">Assigned Wallets</p>
{getDropdownItems()}
</div>
</div>

<div className="w-full flex-shrink-0 h-18 bg-white flex flex-col items-center justify-center px-2">
<p className="text-[14px]">
Applying changes will restart your sentry
</p>

<div className="w-full h-16 flex items-center justify-center gap-1">
<button
onClick={() => {
setDrawerState(null)
}}
className="w-full h-auto text-[15px] text-[#F30919] border border-[#F30919] px-4 py-3 font-semibold"
>
Cancel
</button>

{sentryRunning && (
<button
onClick={() => handleSubmit()}
disabled={disableButton}
className={`w-full h-auto bg-[#F30919] text-[15px] border border-[#F30919] text-white px-4 py-3 font-semibold ${disableButton ? "bg-gray-400 border-gray-400 cursor-not-allowed" : ""}`}
>
{stopRuntime ?
<>
Apply
</>
:
<>
Loading...
</>
}
</button>
)}
</div>
</div>
</div>
);
}



16 changes: 6 additions & 10 deletions apps/sentry-client-desktop/src/features/home/GetSentryNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {drawerStateAtom, DrawerView} from "../drawer/DrawerManager";
import {useSetAtom} from "jotai";
import {AiOutlineInfoCircle} from "react-icons/ai";
import {GetSentryNodeTooltip} from "@/features/keys/GetSentryNodeTooltip";
import {XaiButton} from "@sentry/ui";
// import {useState} from "react";

const body = [
Expand All @@ -26,12 +27,6 @@ const body = [

export function GetSentryNode() {
const setDrawerState = useSetAtom(drawerStateAtom);
// const [message, setMessage] = useState("no error");

// (window as any).deeplinks?.updateMessage((_e, mess: any) => {
// console.log("asdfasdfasdfasdf:", mess);
// setMessage(mess);
// });

function getBody() {
return body.map((item, i) => {
Expand Down Expand Up @@ -69,13 +64,14 @@ export function GetSentryNode() {
Purchase a key to begin earning esXAI
</span>
<div className="flex items-center mt-4 gap-[3rem]">
<button
className={`w-[27.25rem] bg-[#F30919] flex justify-center items-center gap-2 text-lg text-white py-5 font-semibold mt-2`}
<XaiButton
onClick={() => setDrawerState(DrawerView.BuyKeys)}
width={"27.25rem"}
>
<RiKey2Line className="w-5 h-5"/>
Purchase Key
</button>
</XaiButton>

<p
className="text-xl text-[#F30919] cursor-pointer font-semibold"
onClick={() => setDrawerState(DrawerView.ViewKeys)}
Expand All @@ -87,7 +83,7 @@ export function GetSentryNode() {
{/* <div>
<span>{JSON.stringify(message)}</span>
</div> */}

<div className="flex flex-row items-center mt-[4.375rem]">
{getBody()}
</div>
Expand Down
Loading

0 comments on commit 54bb790

Please sign in to comment.