Skip to content

Commit

Permalink
Create edit evm functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Jul 3, 2024
1 parent e35f796 commit fe2f7aa
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
GH_NEXT_PUBLIC_SPACE_IDS=0xd25962422081e4086fbce5ae5b6232c6
GH_NEXT_PUBLIC_MAIN_CHAT_ID=0x22379846e332920ee808735a978c7008
GH_NEXT_PUBLIC_CONTEST_CHAT_ID=0x850f0f5c0c244eba16425a464b0becfc
GH_NEXT_PUBLIC_CONTEST_NAME="\$SRT MEME CONTEST"
GH_NEXT_PUBLIC_CONTEST_NAME=\$SRT MEME CONTEST
GH_NEXT_PUBLIC_CONTEST_END_TIME=1720023760162
GH_NEXT_PUBLIC_AMP_ID=40d4174295c7edf657fc3bedf2748549
GH_NEXT_PUBLIC_COMMUNITY_HUB_ID=12455
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/LinkEvmAddressModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function LinkEvmAddressModal(
}}
/>
<Button isLoading={isLoading} size='lg' type='submit'>
Submit
Save
</Button>
</form>
</Modal>
Expand Down
17 changes: 14 additions & 3 deletions src/hooks/useLinkedEvmAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,21 @@ export default function useLinkedEvmAddress(
const usedLinkedIdentity = address ? linkedIdentity : myLinkedIdentity
const usedLoading = address ? isLoadingMainAddress : isLoadingMy

const evmProviders = usedLinkedIdentity?.externalProviders.filter(
(identity) => identity.provider === IdentityProvider.Evm
)
let latestEvmAddress = ''
let latestEvmCreatedTime = 0
evmProviders?.forEach((provider) => {
const currentCreated = new Date(provider.createdAtTime).getTime()
if (currentCreated > latestEvmCreatedTime) {
latestEvmAddress = provider.externalId
latestEvmCreatedTime = currentCreated
}
})

return {
evmAddress: usedLinkedIdentity?.externalProviders.find(
(identity) => identity.provider === IdentityProvider.Evm
)?.externalId,
evmAddress: latestEvmAddress,
isLoading: usedLoading,
}
}
29 changes: 28 additions & 1 deletion src/modules/telegram/AirdropPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import Tokens from '@/assets/graphics/airdrop/tokens.png'
import AddressAvatar from '@/components/AddressAvatar'
import Button from '@/components/Button'
import Card from '@/components/Card'
import LinkText from '@/components/LinkText'
import Name from '@/components/Name'
import { CommonEVMLoginContent } from '@/components/auth/common/evm/CommonEvmModalContent'
import LayoutWithBottomNavigation from '@/components/layouts/LayoutWithBottomNavigation'
import LinkEvmAddressModal from '@/components/modals/LinkEvmAddressModal'
import Modal, { ModalFunctionalityProps } from '@/components/modals/Modal'
import SubsocialProfileModal from '@/components/subsocial-profile/SubsocialProfileModal'
import useIsModerationAdmin from '@/hooks/useIsModerationAdmin'
import useLinkedEvmAddress from '@/hooks/useLinkedEvmAddress'
import useTgNoScroll from '@/hooks/useTgNoScroll'
import PointsWidget from '@/modules/points/PointsWidget'
import { useSendEvent } from '@/stores/analytics'
import { useMyMainAddress } from '@/stores/my-account'
import { truncateAddress } from '@/utils/account'
import Image from 'next/image'
import { useState } from 'react'
import { RiPencilFill } from 'react-icons/ri'
Expand All @@ -27,6 +31,7 @@ export default function AirdropPage() {
const [openAddEvmModal, setOpenAddEvmModal] = useState(false)
const myAddress = useMyMainAddress()
const sendEvent = useSendEvent()
const { evmAddress } = useLinkedEvmAddress()

return (
<LayoutWithBottomNavigation withFixedHeight className='relative'>
Expand Down Expand Up @@ -59,6 +64,28 @@ export default function AirdropPage() {
<RiPencilFill />
</Button>
</div>
{evmAddress && (
<Card className='mx-4 -mt-1 flex w-full items-center justify-between gap-4 p-4 py-3'>
<div className='flex flex-col gap-1'>
<span className='text-sm font-medium text-text-muted'>
My EVM Address
</span>
<span className='font-semibold'>
{truncateAddress(evmAddress ?? '')}
</span>
</div>
<LinkText
variant='primary'
className='mr-1'
onClick={() => {
sendEvent('edit_evm_address_click')
setOpenAddEvmModal(true)
}}
>
Edit
</LinkText>
</Card>
)}
{isAdmin && (
<div className='flex flex-col gap-2'>
<Button
Expand Down Expand Up @@ -96,7 +123,7 @@ export default function AirdropPage() {
closeModal={() => setOpenProfileModal(false)}
isOpen={openProfileModal}
/>
<AddEvmProviderModal
<LinkEvmAddressModal
isOpen={openAddEvmModal}
closeModal={() => setOpenAddEvmModal(false)}
/>
Expand Down
80 changes: 80 additions & 0 deletions src/services/datahub/generated-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,25 @@ export type FindSpacesWithFilterResponseDto = {
total?: Maybe<Scalars['Int']['output']>
}

export type FindTasksFilter = {
address: Scalars['String']['input']
completed?: InputMaybe<Scalars['Boolean']['input']>
}

export type FindTasksResponseDto = {
__typename?: 'FindTasksResponseDto'
data: Array<GamificationTask>
offset?: Maybe<Scalars['Int']['output']>
pageSize?: Maybe<Scalars['Int']['output']>
total?: Maybe<Scalars['Int']['output']>
}

export type FindTasksWithFilterArgs = {
filter: FindTasksFilter
offset?: InputMaybe<Scalars['Int']['input']>
pageSize?: InputMaybe<Scalars['Int']['input']>
}

export type GamificationEntranceDailyRewardsSequence = {
__typename?: 'GamificationEntranceDailyRewardsSequence'
active: Scalars['Boolean']['output']
Expand All @@ -570,6 +589,55 @@ export type GamificationEntranceDailyRewardsSequence = {
totalSequenceRewardPoints: Scalars['String']['output']
}

export type GamificationTask = {
__typename?: 'GamificationTask'
claimed: Scalars['Boolean']['output']
claimedAt?: Maybe<Scalars['DateTime']['output']>
completed: Scalars['Boolean']['output']
completedAt?: Maybe<Scalars['DateTime']['output']>
createdAt?: Maybe<Scalars['DateTime']['output']>
id: Scalars['String']['output']
linkedIdentity: LinkedIdentity
metadata?: Maybe<GamificationTaskMetadata>
name: GamificationTaskName
periodicityConfig?: Maybe<Scalars['String']['output']>
periodicityType: GamificationTaskPeriodicity
rewardPoints: Scalars['String']['output']
startedAt?: Maybe<Scalars['DateTime']['output']>
tag: Scalars['String']['output']
updatedAt?: Maybe<Scalars['DateTime']['output']>
validityTimeRange: GamificationTaskValidityTimeRange
/** Week number or day timestamp without time */
validityTimeRangeValue?: Maybe<Scalars['Int']['output']>
}

export type GamificationTaskMetadata = {
__typename?: 'GamificationTaskMetadata'
claimedRewardPoints: Scalars['String']['output']
likesNumberToAchieve?: Maybe<Scalars['String']['output']>
referralsNumberToAchieve?: Maybe<Scalars['Int']['output']>
telegramChannelToJoin?: Maybe<Scalars['String']['output']>
userExternalProvider?: Maybe<IdentityProvider>
userExternalProviderId?: Maybe<Scalars['String']['output']>
}

export enum GamificationTaskName {
JoinTelegramChannel = 'JOIN_TELEGRAM_CHANNEL',
JoinTwitter = 'JOIN_TWITTER',
}

export enum GamificationTaskPeriodicity {
Daily = 'DAILY',
Onetime = 'ONETIME',
Weekly = 'WEEKLY',
}

export enum GamificationTaskValidityTimeRange {
Day = 'DAY',
Infinite = 'INFINITE',
Week = 'WEEK',
}

export type GetModeratorByInput = {
substrateAccountAddress: Scalars['String']['input']
}
Expand Down Expand Up @@ -1054,6 +1122,7 @@ export type Query = {
gamificationEntranceDailyRewardSequence?: Maybe<GamificationEntranceDailyRewardsSequence>
gamificationTappingActivityStatsByDate: TappingActivityStatsByDateResponseDto
gamificationTappingEnergyState?: Maybe<TappingEnergyStateResponseDto>
gamificationTasks: FindTasksResponseDto
isBalanceSufficientForSocialAction: IsBalanceSufficientForSocialActionResponse
linkedIdentity?: Maybe<LinkedIdentity>
moderationBlockedResourceIds: Array<Scalars['String']['output']>
Expand Down Expand Up @@ -1167,6 +1236,10 @@ export type QueryGamificationTappingEnergyStateArgs = {
args: TappingEnergyStateInput
}

export type QueryGamificationTasksArgs = {
args: FindTasksWithFilterArgs
}

export type QueryIsBalanceSufficientForSocialActionArgs = {
args: IsBalanceSufficientForSocialActionInput
}
Expand Down Expand Up @@ -1383,6 +1456,10 @@ export enum ServiceMessageStatusCode {
ExpiredEntranceDailyRewardClaimForbidden = 'EXPIRED_ENTRANCE_DAILY_REWARD_CLAIM_FORBIDDEN',
Forbidden = 'FORBIDDEN',
FutureEntranceDailyRewardClaimForbidden = 'FUTURE_ENTRANCE_DAILY_REWARD_CLAIM_FORBIDDEN',
GamificationTaskClaimFailedDuplicatedClaim = 'GAMIFICATION_TASK_CLAIM_FAILED_DUPLICATED_CLAIM',
GamificationTaskClaimFailedInvalidData = 'GAMIFICATION_TASK_CLAIM_FAILED_INVALID_DATA',
GamificationTaskClaimFailedNotCompleted = 'GAMIFICATION_TASK_CLAIM_FAILED_NOT_COMPLETED',
GamificationTaskClaimSuccessCompleted = 'GAMIFICATION_TASK_CLAIM_SUCCESS_COMPLETED',
Info = 'INFO',
InsufficientBalance = 'INSUFFICIENT_BALANCE',
InternalServerError = 'INTERNAL_SERVER_ERROR',
Expand Down Expand Up @@ -1460,6 +1537,7 @@ export enum SocialCallName {
SynthFarcasterCreateSuperLikeFromReaction = 'synth_farcaster_create_super_like_from_reaction',
SynthGamificationAddTappingActivityStates = 'synth_gamification_add_tapping_activity_states',
SynthGamificationClaimEntranceDailyReward = 'synth_gamification_claim_entrance_daily_reward',
SynthGamificationClaimTask = 'synth_gamification_claim_task',
SynthInitLinkedIdentity = 'synth_init_linked_identity',
SynthModerationAddCtxToOrganization = 'synth_moderation_add_ctx_to_organization',
SynthModerationAddDefaultCtxToModerator = 'synth_moderation_add_default_ctx_to_moderator',
Expand Down Expand Up @@ -2168,6 +2246,7 @@ export type GetLinkedIdentitiesQuery = {
username?: string | null
provider: IdentityProvider
enabled: boolean
createdAtTime: any
}> | null
} | null
}
Expand Down Expand Up @@ -3115,6 +3194,7 @@ export const GetLinkedIdentities = gql`
username
provider
enabled
createdAtTime
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/services/datahub/identity/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type Identity = {
provider: IdentityProvider
externalId: string
username?: string | null
createdAtTime: string
}[]
}

Expand All @@ -27,6 +28,7 @@ const GET_LINKED_IDENTITIES = gql`
username
provider
enabled
createdAtTime
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/services/datahub/identity/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ export const useAddExternalProviderToIdentity = mutationWrapper(
reloadEveryIntervalUntilLinkedIdentityFound(
(identity) =>
!!identity?.externalProviders.find(
// @ts-expect-error different provider for IdentityProvider, one from generated type, one from sdk
(p) => p.provider === externalProvider.provider
(p) =>
// @ts-expect-error different provider for IdentityProvider, one from generated type, one from sdk
p.provider === externalProvider.provider &&
p.externalId === externalProvider.id
)
)
},
Expand Down

0 comments on commit fe2f7aa

Please sign in to comment.