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

feat: add tba support #4130

Merged
merged 27 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f6f0310
fix: checkDispatcherPermissions path
bigint Dec 4, 2023
a7277d5
feat: add tba support
bigint Dec 4, 2023
79b660d
Fix permission check in EnableLensManager
bigint Dec 5, 2023
5b73921
chore: move request above
bigint Dec 5, 2023
5388986
Merge branch 'main' into tba-status
bigint Dec 5, 2023
27c6dc2
Merge branch 'main' into tba-status
bigint Dec 5, 2023
275d1aa
Merge branch 'main' into tba-status
bigint Dec 5, 2023
9c46c93
Merge branch 'main' into tba-status
bigint Dec 5, 2023
6ba1332
Merge branch 'main' into tba-status
bigint Dec 5, 2023
bbde8f7
Merge branch 'main' into tba-status
bigint Dec 5, 2023
816326a
Refactor TBA status logic and remove TBA-specific
bigint Dec 5, 2023
6a8290f
Fix Momoka beta action availability bug
bigint Dec 5, 2023
a55270d
Fix import paths in LensManager, Follow, Unfollow,
bigint Dec 5, 2023
f63d0b3
Merge branch 'main' into tba-status
bigint Dec 5, 2023
072bb14
Merge branch 'main' into tba-status
bigint Dec 5, 2023
7ed3125
Merge branch 'main' into tba-status
bigint Dec 5, 2023
de59858
Refactor TbaStatusProvider and add TbaBadge
bigint Dec 5, 2023
3da5344
fix: typo
bigint Dec 5, 2023
c4b4f1a
Merge branch 'main' into tba-status
bigint Dec 5, 2023
55a0084
Add hydrateTbaStatus to AddProfileManager
bigint Dec 6, 2023
588176d
Merge branch 'main' into tba-status
bigint Dec 6, 2023
29873fa
Merge branch 'main' into tba-status
bigint Dec 7, 2023
81d52ef
Update packages/lib/api/getTbaStatus.ts
bigint Dec 7, 2023
574b668
Merge branch 'main' into tba-status
bigint Dec 7, 2023
ae29b46
Merge branch 'main' into tba-status
bigint Dec 7, 2023
a9d314c
fix: tba status always return true
bigint Dec 7, 2023
d72547d
feat: add ff check
bigint Dec 7, 2023
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
23 changes: 23 additions & 0 deletions apps/web/src/components/Common/Providers/TbaStatusProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { FC } from 'react';

import getTbaStatus from '@hey/lib/api/getTbaStatus';
import { useQuery } from '@tanstack/react-query';
import useProfileStore from 'src/store/persisted/useProfileStore';
import { useTbaStatusStore } from 'src/store/persisted/useTbaStatusStore';

const TbaStatusProvider: FC = () => {
const currentProfile = useProfileStore((state) => state.currentProfile);
const setIsTba = useTbaStatusStore((state) => state.setIsTba);

useQuery({
queryFn: () =>
getTbaStatus(currentProfile?.ownedBy.address, (deployed) =>
setIsTba(deployed)
),
queryKey: ['getTbaStatus', currentProfile?.ownedBy.address]
});

return null;
};

export default TbaStatusProvider;
2 changes: 2 additions & 0 deletions apps/web/src/components/Common/Providers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import LeafwatchProvider from './LeafwatchProvider';
import LensSubscriptionsProvider from './LensSubscriptionsProvider';
import PreferencesProvider from './PreferencesProvider';
import ServiceWorkerProvider from './ServiceWorkerProvider';
import TbaStatusProvider from './TbaStatusProvider';
import Web3Provider from './Web3Provider';

const lensApolloClient = apolloClient(authLink);
Expand All @@ -38,6 +39,7 @@ const Providers = ({ children }: { children: ReactNode }) => {
<LensSubscriptionsProvider />
<QueryClientProvider client={queryClient}>
<PreferencesProvider />
<TbaStatusProvider />
<FeaturedGroupsProvider />
<LivepeerConfig client={livepeerClient} theme={getLivepeerTheme}>
<ThemeProvider attribute="class" defaultTheme="light">
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/Profile/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import ProfileMenu from './Menu';
import MutualFollowers from './MutualFollowers';
import MutualFollowersList from './MutualFollowers/List';
import ScamWarning from './ScamWarning';
import TbaBadge from './TbaBadge';

interface DetailsProps {
profile: Profile;
Expand Down Expand Up @@ -103,6 +104,7 @@ const Details: FC<DetailsProps> = ({ profile }) => {
<CheckBadgeIcon className="text-brand-500 h-6 w-6" />
</Tooltip>
) : null}
<TbaBadge profile={profile} />
{hasMisused(profile.id) ? (
<Tooltip content={misuseDetails?.type}>
<ExclamationCircleIcon className="h-6 w-6 text-red-500" />
Expand Down
41 changes: 41 additions & 0 deletions apps/web/src/components/Profile/TbaBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { Profile } from '@hey/lens';
import type { FC } from 'react';

import { STATIC_IMAGES_URL } from '@hey/data/constants';
import getTbaStatus from '@hey/lib/api/getTbaStatus';
import { Tooltip } from '@hey/ui';
import isFeatureEnabled from '@lib/isFeatureEnabled';
import { useQuery } from '@tanstack/react-query';

interface TbaBadgeProps {
profile: Profile;
}

const TbaBadge: FC<TbaBadgeProps> = ({ profile }) => {
const { data: isTba } = useQuery({
queryFn: () => getTbaStatus(profile.ownedBy.address),
queryKey: ['getTbaStatus', profile.ownedBy.address]
});

if (!isTba) {
return null;
}

if (!isFeatureEnabled('tba')) {
return null;
}

return (
<Tooltip content="Token Bounded Account">
<img
alt="Token Bounded Account"
className="h-6 w-6"
height={24}
src={`${STATIC_IMAGES_URL}/brands/tba.svg`}
width={24}
/>
</Tooltip>
);
};

export default TbaBadge;
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useState } from 'react';
import toast from 'react-hot-toast';
import { useNonceStore } from 'src/store/non-persisted/useNonceStore';
import useProfileStore from 'src/store/persisted/useProfileStore';
import { hydrateTbaStatus } from 'src/store/persisted/useTbaStatusStore';
import { useContractWrite, useSignTypedData } from 'wagmi';

interface ToggleLensManagerProps {
Expand All @@ -36,6 +37,8 @@ const ToggleLensManager: FC<ToggleLensManagerProps> = ({
(state) => state.setLensHubOnchainSigNonce
);
const [isLoading, setIsLoading] = useState(false);

const { isTba } = hydrateTbaStatus();
const { canBroadcast, canUseSignless } =
checkDispatcherPermissions(currentProfile);

Expand Down Expand Up @@ -94,7 +97,7 @@ const ToggleLensManager: FC<ToggleLensManagerProps> = ({
switchToGivenConfig
];

if (canBroadcast) {
if (!isTba && canBroadcast) {
const { data } = await broadcastOnchain({
variables: { request: { id, signature } }
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import toast from 'react-hot-toast';
import useHandleWrongNetwork from 'src/hooks/useHandleWrongNetwork';
import { useNonceStore } from 'src/store/non-persisted/useNonceStore';
import useProfileStore from 'src/store/persisted/useProfileStore';
import { hydrateTbaStatus } from 'src/store/persisted/useTbaStatusStore';
import { isAddress } from 'viem';
import { useContractWrite, useSignTypedData } from 'wagmi';

Expand All @@ -42,6 +43,8 @@ const AddProfileManager: FC<AddProfileManagerProps> = ({
const [isLoading, setIsLoading] = useState(false);

const handleWrongNetwork = useHandleWrongNetwork();

const { isTba } = hydrateTbaStatus();
const { canBroadcast } = checkDispatcherPermissions(currentProfile);

const onCompleted = (__typename?: 'RelayError' | 'RelaySuccess') => {
Expand Down Expand Up @@ -99,7 +102,7 @@ const AddProfileManager: FC<AddProfileManagerProps> = ({
switchToGivenConfig
];

if (canBroadcast) {
if (!isTba && canBroadcast) {
const signature = await signTypedDataAsync(getSignature(typedData));
const { data } = await broadcastOnchain({
variables: { request: { id, signature } }
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/store/persisted/useAuthStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export const useAuthStore = create(
(value) =>
value !== IndexDB.AlgorithmStore &&
value !== IndexDB.VerifiedMembersStore &&
value !== IndexDB.FeaturedGroupsStore
value !== IndexDB.FeaturedGroupsStore &&
value !== IndexDB.TBAStore
);
await delMany(allIndexedDBStores);
}
Expand Down
30 changes: 30 additions & 0 deletions apps/web/src/store/persisted/useTbaStatusStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { IndexDB } from '@hey/data/storage';
import { create } from 'zustand';
import { persist } from 'zustand/middleware';

import createIdbStorage from '../lib/createIdbStorage';

interface TbaStatusState {
hydrateTbaStatus: () => { isTba: boolean };
isTba: boolean;
setIsTba: (isTba: boolean) => void;
}

export const useTbaStatusStore = create(
persist<TbaStatusState>(
(set, get) => ({
hydrateTbaStatus: () => {
return { isTba: get().isTba };
},
isTba: false,
setIsTba: (isTba) => set(() => ({ isTba }))
}),
{
name: IndexDB.TBAStore,
storage: createIdbStorage()
}
)
);

export const hydrateTbaStatus = () =>
useTbaStatusStore.getState().hydrateTbaStatus();
1 change: 1 addition & 0 deletions packages/data/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export const IndexDB = {
FeaturedGroupsStore: 'featuredgroups.store',
FeatureFlagsStore: 'featureflags.store',
ProfileStore: 'profile.store',
TBAStore: 'tba.store',
VerifiedMembersStore: 'verifiedmembers.store'
};
31 changes: 31 additions & 0 deletions packages/lib/api/getTbaStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { HEY_API_URL } from '@hey/data/constants';
import axios from 'axios';

/**
* Get TBA status of an address
* @param address address
* @param callbackFn callback function
* @returns TBA status
*/
const getTbaStatus = async (
address: string,
callbackFn?: (deployed: boolean) => void
): Promise<boolean> => {
if (!address) {
return false;
}

try {
const response = await axios.get(`${HEY_API_URL}/tba/deployed`, {
params: { address }
});
const { data } = response;
callbackFn?.(data?.deployed || false);

return data?.deployed || false;
} catch (error) {
throw error;
}
};

export default getTbaStatus;
Loading