From 3663ee57f3e3d83a03ca105e0dda11cd94f68c98 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Wed, 14 Jun 2023 20:00:16 -0500 Subject: [PATCH] Add testnet warning (#880) * Add testnet warning * Add watermarks to posts * Call the test environment the Sandbox --- src/lib/constants.ts | 24 +++++++++++++--- src/state/models/session.ts | 8 ++++++ src/view/com/pager/FeedsTabBarMobile.tsx | 4 ++- src/view/com/post-thread/PostThreadItem.tsx | 3 ++ src/view/com/posts/FeedItem.tsx | 2 ++ src/view/com/util/PostSandboxWarning.tsx | 32 +++++++++++++++++++++ src/view/shell/desktop/RightNav.tsx | 17 ++++++++--- 7 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 src/view/com/util/PostSandboxWarning.tsx diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 0a69569095..0a8c32cd63 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -10,6 +10,22 @@ export const MAX_GRAPHEME_LENGTH = 300 // but increasing limit per user feedback export const MAX_ALT_TEXT = 1000 +export function IS_LOCAL_DEV(url: string) { + return url.includes('localhost') +} + +export function IS_STAGING(url: string) { + return !IS_LOCAL_DEV(url) && !IS_PROD(url) +} + +export function IS_PROD(url: string) { + // NOTE + // until open federation, "production" is defined as the main server + // this definition will not work once federation is enabled! + // -prf + return url.startsWith('https://bsky.social') +} + export const PROD_TEAM_HANDLES = [ 'jay.bsky.social', 'pfrazee.com', @@ -43,14 +59,14 @@ export async function DEFAULT_FEEDS( serviceUrl: string, resolveHandle: (name: string) => Promise, ) { - if (serviceUrl.includes('localhost')) { + if (IS_LOCAL_DEV(serviceUrl)) { // local dev const aliceDid = await resolveHandle('alice.test') return { pinned: [`at://${aliceDid}/app.bsky.feed.generator/alice-favs`], saved: [`at://${aliceDid}/app.bsky.feed.generator/alice-favs`], } - } else if (serviceUrl.includes('staging')) { + } else if (IS_STAGING(serviceUrl)) { // staging return { pinned: [STAGING_DEFAULT_FEED('whats-hot')], @@ -90,9 +106,9 @@ export const STAGING_LINK_META_PROXY = export const PROD_LINK_META_PROXY = 'https://cardyb.bsky.app/v1/extract?url=' export function LINK_META_PROXY(serviceUrl: string) { - if (serviceUrl.includes('localhost')) { + if (IS_LOCAL_DEV(serviceUrl)) { return STAGING_LINK_META_PROXY - } else if (serviceUrl.includes('staging')) { + } else if (IS_STAGING(serviceUrl)) { return STAGING_LINK_META_PROXY } else { return PROD_LINK_META_PROXY diff --git a/src/state/models/session.ts b/src/state/models/session.ts index aa9c97750e..57082b818c 100644 --- a/src/state/models/session.ts +++ b/src/state/models/session.ts @@ -10,6 +10,7 @@ import {isObj, hasProp} from 'lib/type-guards' import {networkRetry} from 'lib/async/retry' import {z} from 'zod' import {RootStoreModel} from './root-store' +import {IS_PROD} from 'lib/constants' export type ServiceDescription = DescribeServer.OutputSchema @@ -104,6 +105,13 @@ export class SessionModel { return this.accounts.filter(acct => acct.did !== this.data?.did) } + get isSandbox() { + if (!this.data) { + return false + } + return !IS_PROD(this.data.service) + } + serialize(): unknown { return { data: this.data, diff --git a/src/view/com/pager/FeedsTabBarMobile.tsx b/src/view/com/pager/FeedsTabBarMobile.tsx index 9c7138815a..6211735679 100644 --- a/src/view/com/pager/FeedsTabBarMobile.tsx +++ b/src/view/com/pager/FeedsTabBarMobile.tsx @@ -62,7 +62,9 @@ export const FeedsTabBar = observer( /> - Bluesky + + {store.session.isSandbox ? 'SANDBOX' : 'Bluesky'} + + )} + diff --git a/src/view/com/posts/FeedItem.tsx b/src/view/com/posts/FeedItem.tsx index c79d4c4e35..7854035f8c 100644 --- a/src/view/com/posts/FeedItem.tsx +++ b/src/view/com/posts/FeedItem.tsx @@ -19,6 +19,7 @@ import {PostHider} from '../util/moderation/PostHider' import {ContentHider} from '../util/moderation/ContentHider' import {ImageHider} from '../util/moderation/ImageHider' import {RichText} from '../util/text/RichText' +import {PostSandboxWarning} from '../util/PostSandboxWarning' import * as Toast from '../util/Toast' import {UserAvatar} from '../util/UserAvatar' import {s} from 'lib/styles' @@ -245,6 +246,7 @@ export const FeedItem = observer(function ({ )} + diff --git a/src/view/com/util/PostSandboxWarning.tsx b/src/view/com/util/PostSandboxWarning.tsx new file mode 100644 index 0000000000..54495aa9bb --- /dev/null +++ b/src/view/com/util/PostSandboxWarning.tsx @@ -0,0 +1,32 @@ +import React from 'react' +import {StyleSheet, View} from 'react-native' +import {Text} from './text/Text' +import {useStores} from 'state/index' +import {usePalette} from 'lib/hooks/usePalette' + +export function PostSandboxWarning() { + const store = useStores() + const pal = usePalette('default') + if (store.session.isSandbox) { + return ( + + + SANDBOX + + + ) + } + return null +} + +const styles = StyleSheet.create({ + container: { + position: 'absolute', + top: 6, + right: 10, + }, + text: { + fontWeight: 'bold', + opacity: 0.07, + }, +}) diff --git a/src/view/shell/desktop/RightNav.tsx b/src/view/shell/desktop/RightNav.tsx index 8f6b2d486c..c38c0371a3 100644 --- a/src/view/shell/desktop/RightNav.tsx +++ b/src/view/shell/desktop/RightNav.tsx @@ -15,15 +15,24 @@ import {formatCount} from 'view/com/util/numeric/format' export const DesktopRightNav = observer(function DesktopRightNav() { const store = useStores() const pal = usePalette('default') + const palError = usePalette('error') return ( {store.session.hasSession && } - - Welcome to Bluesky! This is a beta application that's still in - development. - + {store.session.isSandbox ? ( + + + SANDBOX. Posts and accounts are not permanent. + + + ) : ( + + Welcome to Bluesky! This is a beta application that's still in + development. + + )}