Skip to content

Commit

Permalink
feat: add requestLogin api
Browse files Browse the repository at this point in the history
  • Loading branch information
swkatmask committed Mar 23, 2024
1 parent df51410 commit 6683fd2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/plugin-infra/src/site-adaptor/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface __SiteAdaptorContext__ {
publishPost: ((mediaObjects: Array<string | Blob>, options?: any) => Promise<string | null>) | undefined
getSearchedKeyword: (() => string) | undefined
connectPersona: () => Promise<void>
requestLogin?: (...args: any[]) => void
}
export let lastRecognizedProfile: __SiteAdaptorContext__['lastRecognizedProfile']
export let currentVisitingProfile: __SiteAdaptorContext__['currentVisitingProfile']
Expand All @@ -33,6 +34,7 @@ export let postMessage: __SiteAdaptorContext__['postMessage']
export let publishPost: __SiteAdaptorContext__['publishPost']
export let getSearchedKeyword: __SiteAdaptorContext__['getSearchedKeyword']
export let connectPersona: __SiteAdaptorContext__['connectPersona']
export let requestLogin: __SiteAdaptorContext__['requestLogin']
export function __setSiteAdaptorContext__(value: __SiteAdaptorContext__) {
;({
lastRecognizedProfile,
Expand All @@ -48,5 +50,6 @@ export function __setSiteAdaptorContext__(value: __SiteAdaptorContext__) {
publishPost,
getSearchedKeyword,
connectPersona,
requestLogin,
} = value)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { usePostInfoDetails } from '@masknet/plugin-infra/content-script'
import { ActionButton, makeStyles } from '@masknet/theme'
import { Box } from '@mui/material'
import { useRedPacketTrans } from '../../locales/index.js'

const useStyles = makeStyles()((theme) => {
return {
footer: {
padding: theme.spacing(1.5),
},
}
})

interface OperationFooterProps {
onRequest?(): void
}
export function RequestLoginFooter({ onRequest }: OperationFooterProps) {
const { classes } = useStyles()
const t = useRedPacketTrans()
const source = usePostInfoDetails.source()

return (
<Box className={classes.footer}>
<ActionButton fullWidth variant="roundedDark" onClick={onRequest}>
{t.connect_to_platform({ platform: source! })}
</ActionButton>
</Box>
)
}
16 changes: 12 additions & 4 deletions packages/plugins/RedPacket/src/SiteAdaptor/RedPacket/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useLastRecognizedIdentity, usePostInfoDetails, usePostLink } from '@masknet/plugin-infra/content-script'
import { share } from '@masknet/plugin-infra/content-script/context'
import { requestLogin, share } from '@masknet/plugin-infra/content-script/context'
import { LoadingStatus, TransactionConfirmModal } from '@masknet/shared'
import { EMPTY_LIST, EnhanceableSite, NetworkPluginID, Sniffings } from '@masknet/shared-base'
import { makeStyles, parseColor } from '@masknet/theme'
import type { HappyRedPacketV4 } from '@masknet/web3-contracts/types/HappyRedPacketV4.js'
import { useChainContext, useNetwork, useNetworkContext } from '@masknet/web3-hooks-base'
import { EVMChainResolver, FireflyRedPacket } from '@masknet/web3-providers'
import { RedPacketStatus, type RedPacketJSONPayload, type FireflyRedPacketAPI } from '@masknet/web3-providers/types'
import { RedPacketStatus, type FireflyRedPacketAPI, type RedPacketJSONPayload } from '@masknet/web3-providers/types'
import { TokenType, formatBalance, isZero } from '@masknet/web3-shared-base'
import { ChainId } from '@masknet/web3-shared-evm'
import { Card, Grow, Stack, Typography } from '@mui/material'
Expand All @@ -18,6 +18,7 @@ import { useClaimCallback } from '../hooks/useClaimCallback.js'
import { useRedPacketContract } from '../hooks/useRedPacketContract.js'
import { useRefundCallback } from '../hooks/useRefundCallback.js'
import { OperationFooter } from './OperationFooter.js'
import { RequestLoginFooter } from './RequestLoginFooter.js'
import { useRedPacketCover } from './useRedPacketCover.js'

const useStyles = makeStyles<{ outdated: boolean }>()((theme, { outdated }) => {
Expand Down Expand Up @@ -422,7 +423,9 @@ export const RedPacket = memo(function RedPacket({ payload }: RedPacketProps) {
</div>
}
</Card>
{outdated ? null : (
{outdated ?
null
: myProfileId ?
<OperationFooter
chainId={payloadChainId}
canClaim={canClaim}
Expand All @@ -432,7 +435,12 @@ export const RedPacket = memo(function RedPacket({ payload }: RedPacketProps) {
onShare={handleShare}
onClaimOrRefund={onClaimOrRefund}
/>
)}
: <RequestLoginFooter
onRequest={() => {
requestLogin?.(source)
}}
/>
}
</>
)
})
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/RedPacket/src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,6 @@
"no_claim_data": "No claims yet for this Lucky Drop",
"no_claim_history_data": "No Lucky Drops claimed",
"no_sent_history_data": "<div>No Lucky Drops posted.</div> <div>Select 🎁 when you compose a post to start your first drop.<div>",
"post_on": "Post on"
"post_on": "Post on",
"connect_to_platform": "Connect to {{ platform }}"
}

0 comments on commit 6683fd2

Please sign in to comment.