-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Viewing Coin Trending in Twitter (Trade Plugin) (#1458)
* chore: define the trader plugin * chore: TypedMessage & TypedMessageCashTrending + chore: add TypedMessageAnchor + chore: parse tweet into TypedMessage + chore: add TypedMessageCashTrending + chore: add PostDummy + chore: render TypedMessageCashTrending + fix: renderCompoundMessage * chore(ui): add TrendingView * chore: integrate with APIs * chore: support WholePostVisibility * chore: inject page inspector * chore: add UI components + chore: add PriceChangedTable + chore: add TickersTable + chore: add MarketCapRank + chore: add PriceChart + chore: add Skeleton & PriceChartDaysControl * chore: integrate with CMC apis * refactor: better UX * fix: build error * chore: inject post dummy according to the WholePostVisibility settings * chore: add MAX options into PriceChart * chore: support WholePostVisibility * chore: check availability before displaying TrendingView * refactor: use URLSearchParams * refactor: resolve reviews
- Loading branch information
1 parent
be30f62
commit d2179ec
Showing
67 changed files
with
3,367 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react' | ||
import { PluginUI, PluginConfig } from '../../plugins/plugin' | ||
|
||
export interface PageInspectorProps {} | ||
|
||
export function PageInspector(props: PageInspectorProps) { | ||
return ( | ||
<> | ||
{[...PluginUI.values()].map((x) => ( | ||
<PluginPageInspectorForEach key={x.identifier} config={x} /> | ||
))} | ||
</> | ||
) | ||
} | ||
|
||
function PluginPageInspectorForEach({ config }: { config: PluginConfig }) { | ||
const F = config.pageInspector | ||
if (typeof F === 'function') return <F /> | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { useEffect, useMemo } from 'react' | ||
import { usePostInfoDetails } from '../DataSource/usePostInfo' | ||
import { DefaultTypedMessageRenderer } from './TypedMessageRenderer' | ||
import { PluginUI } from '../../plugins/plugin' | ||
import { makeTypedMessageCompound, isTypedMessageSuspended, isTypedMessageKnown } from '../../protocols/typed-message' | ||
import { useValueRef } from '../../utils/hooks/useValueRef' | ||
import { currentPostReplacementScopeSettings, PostReplacementScope } from '../../settings/settings' | ||
import { makeStyles, Theme } from '@material-ui/core' | ||
|
||
const useStlyes = makeStyles((theme: Theme) => ({ | ||
root: { | ||
overflowWrap: 'break-word', | ||
}, | ||
})) | ||
|
||
export interface PostReplacerProps { | ||
zip?: () => void | ||
unzip?: () => void | ||
} | ||
|
||
export function PostReplacer(props: PostReplacerProps) { | ||
const classes = useStlyes() | ||
const postContent = usePostInfoDetails('postContent') | ||
const postMessage = usePostInfoDetails('postMessage') | ||
const postPayload = usePostInfoDetails('postPayload') | ||
const postRepalcementScope = useValueRef(currentPostReplacementScopeSettings) | ||
|
||
const plugins = [...PluginUI.values()] | ||
const processedPostMessage = useMemo( | ||
() => plugins.reduce((x, plugin) => plugin.messageProcessor?.(x) ?? x, postMessage), | ||
[plugins.map((x) => x.identifier).join(), postContent], | ||
) | ||
const shouldReplacePost = | ||
// replace all posts | ||
postRepalcementScope === PostReplacementScope.all || | ||
// replace posts which enhanced by plugins | ||
(postRepalcementScope === PostReplacementScope.enhancedOnly && | ||
processedPostMessage.items.some((x) => !isTypedMessageKnown(x))) || | ||
// replace posts which encrypted by maskbook | ||
(postRepalcementScope === PostReplacementScope.encryptedOnly && postPayload.ok) | ||
|
||
// zip/unzip original post | ||
useEffect(() => { | ||
if (shouldReplacePost) props.zip?.() | ||
else props.unzip?.() | ||
}, [shouldReplacePost]) | ||
|
||
return shouldReplacePost ? ( | ||
<span className={classes.root}> | ||
<DefaultTypedMessageRenderer | ||
message={makeTypedMessageCompound( | ||
processedPostMessage.items.filter((x) => !isTypedMessageSuspended(x)), | ||
)} | ||
/> | ||
</span> | ||
) : null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.