Skip to content

Commit

Permalink
Merge branch 'master' into rotorsoft/9507-get-user-feed
Browse files Browse the repository at this point in the history
  • Loading branch information
rotorsoft committed Oct 11, 2024
2 parents 66bfcc4 + 4f2bb56 commit 0adab54
Show file tree
Hide file tree
Showing 38 changed files with 816 additions and 230 deletions.
2 changes: 1 addition & 1 deletion libs/model/src/community/CreateTopic.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function CreateTopic(): Command<
throw new InvalidState(Errors.StakeNotAllowed);
}

if (config.CONTESTS.FLAG_FARCASTER_CONTEST) {
if (config.CONTESTS.FLAG_WEIGHTED_TOPICS) {
// new path: stake or ERC20
if (payload.weighted_voting) {
options = {
Expand Down
6 changes: 3 additions & 3 deletions libs/model/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const {
ETH_RPC,
COSMOS_REGISTRY_API,
REACTION_WEIGHT_OVERRIDE,
FLAG_FARCASTER_CONTEST,
FLAG_WEIGHTED_TOPICS,
ALCHEMY_PRIVATE_APP_KEY,
ALCHEMY_PUBLIC_APP_KEY,
MEMBERSHIP_REFRESH_BATCH_SIZE,
Expand Down Expand Up @@ -85,7 +85,7 @@ export const config = configure(
MAX_USER_POSTS_PER_CONTEST: MAX_USER_POSTS_PER_CONTEST
? parseInt(MAX_USER_POSTS_PER_CONTEST, 10)
: 2,
FLAG_FARCASTER_CONTEST: FLAG_FARCASTER_CONTEST === 'true',
FLAG_WEIGHTED_TOPICS: FLAG_WEIGHTED_TOPICS === 'true',
},
AUTH: {
JWT_SECRET: JWT_SECRET || DEFAULTS.JWT_SECRET,
Expand Down Expand Up @@ -183,7 +183,7 @@ export const config = configure(
CONTESTS: z.object({
MIN_USER_ETH: z.number(),
MAX_USER_POSTS_PER_CONTEST: z.number().int(),
FLAG_FARCASTER_CONTEST: z.boolean(),
FLAG_WEIGHTED_TOPICS: z.boolean(),
}),
AUTH: z
.object({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
export const namespaceFactoryAbi = [
{
type: 'function',
name: 'newSingleERC20Contest',
inputs: [
{ name: 'name', type: 'string', internalType: 'string' },
{ name: 'length', type: 'uint256', internalType: 'uint256' },
{ name: 'winnerShares', type: 'uint256[]', internalType: 'uint256[]' },
{ name: 'token', type: 'address', internalType: 'address' },
{ name: 'voterShare', type: 'uint256', internalType: 'uint256' },
{ name: 'exhangeToken', type: 'address', internalType: 'address' },
],
outputs: [{ name: '', type: 'address', internalType: 'address' }],
stateMutability: 'nonpayable',
},
{
inputs: [],
stateMutability: 'view',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,43 @@ class Contest extends ContractBase {
}
}

async newSingleERC20Contest(
namespaceName: string,
contestInterval: number,
winnerShares: number[],
voteToken: string,
voterShare: number,
walletAddress: string,
exchangeToken: string,
): Promise<string> {
if (!this.initialized || !this.walletEnabled) {
await this.initialize(true);
}

try {
const txReceipt = await this.namespaceFactory.newERC20Contest(
namespaceName,
contestInterval,
winnerShares,
voteToken,
voterShare,
walletAddress,
exchangeToken,
);
// @ts-expect-error StrictNullChecks
const eventLog = txReceipt.logs.find((log) => log.topics[0] == TOPIC_LOG);
const newContestAddress = this.web3.eth.abi.decodeParameters(
['address', 'address', 'uint256', 'bool'],
// @ts-expect-error StrictNullChecks
eventLog.data.toString(),
)['0'] as string;
this.contractAddress = newContestAddress;
return newContestAddress;
} catch (error) {
throw new Error('Failed to initialize contest ' + error);
}
}

/**
* Allows for deposit of contest token(ETH or ERC20) to contest
* @param amount amount in ether to send to contest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,42 @@ class NamespaceFactory extends ContractBase {
return txReceipt;
}

async newERC20Contest(
namespaceName: string,
contestInterval: number,
winnerShares: number[],
voteToken: string,
voterShare: number,
walletAddress: string,
exchangeToken: string,
): Promise<TransactionReceipt> {
if (!this.initialized || !this.walletEnabled) {
await this.initialize(true);
}
const maxFeePerGasEst = await this.estimateGas();
let txReceipt;
try {
txReceipt = await this.contract.methods
.newSingleERC20Contest(
namespaceName,
contestInterval,
winnerShares,
voteToken,
voterShare,
exchangeToken,
)
.send({
from: walletAddress,
type: '0x2',
maxFeePerGas: maxFeePerGasEst?.toString(),
maxPriorityFeePerGas: this.web3.utils.toWei('0.001', 'gwei'),
});
} catch {
throw new Error('Transaction failed');
}
return txReceipt;
}

async getFeeManagerBalance(
namespace: string,
token?: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const buildFlag = (env: string | undefined) => {
const featureFlags = {
contest: buildFlag(process.env.FLAG_CONTEST),
contestDev: buildFlag(process.env.FLAG_CONTEST_DEV),
weightedTopics: buildFlag(process.env.FLAG_WEIGHTED_TOPICS),
knockPushNotifications: buildFlag(
process.env.FLAG_KNOCK_PUSH_NOTIFICATIONS_ENABLED,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const CommunityNotFoundPage = lazy(

const CommonDomainRoutes = ({
contestEnabled,
farcasterContestEnabled,
weightedTopicsEnabled,
tokenizedCommunityEnabled,
}: RouteFeatureFlags) => [
<Route
Expand Down Expand Up @@ -407,7 +407,7 @@ const CommonDomainRoutes = ({
key="/:scope/manage/topics"
path="/:scope/manage/topics"
element={withLayout(
farcasterContestEnabled ? CommunityTopics : CommunityTopicsOld,
weightedTopicsEnabled ? CommunityTopics : CommunityTopicsOld,
{
scoped: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const ProfilePageRedirect = lazy(() => import('views/pages/profile_redirect'));

const CustomDomainRoutes = ({
contestEnabled,
farcasterContestEnabled,
weightedTopicsEnabled,
tokenizedCommunityEnabled,
}: RouteFeatureFlags) => {
return [
Expand Down Expand Up @@ -307,7 +307,7 @@ const CustomDomainRoutes = ({
key="/manage/topics"
path="/manage/topics"
element={withLayout(
farcasterContestEnabled ? CommunityTopics : CommunityTopicsOld,
weightedTopicsEnabled ? CommunityTopics : CommunityTopicsOld,
{
scoped: true,
},
Expand Down
9 changes: 3 additions & 6 deletions packages/commonwealth/client/scripts/navigation/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@ import GeneralRoutes from './GeneralRoutes';

export type RouteFeatureFlags = {
contestEnabled: boolean;
farcasterContestEnabled: boolean;
weightedTopicsEnabled: boolean;
tokenizedCommunityEnabled: boolean;
};

const Router = () => {
const client = OpenFeature.getClient();
const contestEnabled = client.getBooleanValue('contest', false);

const farcasterContestEnabled = client.getBooleanValue(
'farcasterContest',
false,
);
const weightedTopicsEnabled = client.getBooleanValue('weightedTopics', false);

const tokenizedCommunityEnabled = client.getBooleanValue(
'tokenizedCommunity',
Expand All @@ -34,7 +31,7 @@ const Router = () => {

const flags = {
contestEnabled,
farcasterContestEnabled,
weightedTopicsEnabled,
tokenizedCommunityEnabled,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { trpc } from 'utils/trpcClient';

export function useSubscriptionPreferences() {
return trpc.subscription.getSubscriptionPreferences.useQuery({});
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ type BreadcrumbsProps = {
tooltipStr?: string;
};

const handleNavigation = (label, navigate, isParent) => {
if (label === 'Discussions' && isParent) {
navigate(`/discussions`);
}
};
const handleMouseInteraction = (
label: string,
handleInteraction: (event: React.MouseEvent<HTMLSpanElement>) => void,
event: React.MouseEvent<HTMLSpanElement>,
) => {
if (label !== 'Discussions') {
handleInteraction(event);
}
};

export const CWBreadcrumbs = ({
breadcrumbs,
tooltipStr,
Expand All @@ -36,14 +51,19 @@ export const CWBreadcrumbs = ({
placement="bottom"
renderTrigger={(handleInteraction) => (
<CWText
onMouseEnter={handleInteraction}
onMouseLeave={handleInteraction}
onMouseEnter={(event) =>
handleMouseInteraction(label, handleInteraction, event)
}
onMouseLeave={(event) =>
handleMouseInteraction(label, handleInteraction, event)
}
type="caption"
className={clsx({
'disable-active-cursor': index === 0,
'current-text': isCurrent,
'parent-text': !isCurrent,
})}
onClick={() => handleNavigation(label, navigate, isParent)}
>
{truncateText(label)}
</CWText>
Expand Down
6 changes: 6 additions & 0 deletions packages/commonwealth/client/scripts/views/pages/404.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.PageNotFound {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
41 changes: 32 additions & 9 deletions packages/commonwealth/client/scripts/views/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
import React from 'react';
import useUserStore from 'state/ui/user';
import { useAuthModalStore } from '../../state/ui/modals';
import { CWEmptyState } from '../components/component_kit/cw_empty_state';
import { CWButton } from '../components/component_kit/new_designs/CWButton';
import { AuthModal, AuthModalType } from '../modals/AuthModal';
import './404.scss';

type PageNotFoundProps = { title?: string; message?: string };

export const PageNotFound = (props: PageNotFoundProps) => {
const { message } = props;

const user = useUserStore();

const { authModalType, setAuthModalType } = useAuthModalStore();

return (
<CWEmptyState
iconName="cautionCircle"
content={
message ||
`
This page may not be visible to the public.
If it belongs to a private thread or community, try logging in.
<div className="PageNotFound">
<CWEmptyState
iconName="cautionCircle"
content={
message ||
`
This page is private.
Please Sign in to view or join the conversation.
`
}
/>
}
/>
{!user.isLoggedIn && (
<CWButton
buttonType="primary"
label="Sign in"
onClick={() => setAuthModalType(AuthModalType.SignIn)}
/>
)}
<AuthModal
type={AuthModalType.SignIn}
onClose={() => setAuthModalType(undefined)}
isOpen={!!authModalType}
/>
</div>
);
};
Loading

0 comments on commit 0adab54

Please sign in to comment.