Skip to content

Commit

Permalink
Merge pull request #515 from us3r-network/u3-dev
Browse files Browse the repository at this point in the history
beta.20240201
  • Loading branch information
Tonyce authored Feb 1, 2024
2 parents 573c8fe + 3563f84 commit c582b99
Show file tree
Hide file tree
Showing 28 changed files with 1,119 additions and 107 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/u3-firebase-hosting-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ name: Deploy u3 to Firebase Hosting on merge
branches:
- u3
- u3-dev
- u3-pwa
jobs:
prod_build_and_deploy:
if: github.ref == 'refs/heads/u3'
Expand Down Expand Up @@ -46,6 +47,7 @@ jobs:
REACT_APP_CASTER_NFT_FIXED_PRICE_STRATEGY: "${{ vars.REACT_APP_CASTER_NFT_FIXED_PRICE_STRATEGY }}"
REACT_APP_CASTER_NFT_CHAIN_ID: "${{ vars.REACT_APP_CASTER_NFT_CHAIN_ID }}"
REACT_APP_CASTER_NFT_RECIPIENT_ADDRESS: "${{ vars.REACT_APP_CASTER_NFT_RECIPIENT_ADDRESS }}"
REACT_APP_VAPID_PUBLIC_KEY: "${{ vars.REACT_APP_VAPID_PUBLIC_KEY }}"
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
Expand Down Expand Up @@ -92,6 +94,7 @@ jobs:
REACT_APP_CASTER_NFT_FIXED_PRICE_STRATEGY: "${{ vars.REACT_APP_CASTER_NFT_FIXED_PRICE_STRATEGY }}"
REACT_APP_CASTER_NFT_CHAIN_ID: "${{ vars.REACT_APP_CASTER_NFT_CHAIN_ID }}"
REACT_APP_CASTER_NFT_RECIPIENT_ADDRESS: "${{ vars.REACT_APP_CASTER_NFT_RECIPIENT_ADDRESS }}"
REACT_APP_VAPID_PUBLIC_KEY: "${{ vars.REACT_APP_VAPID_PUBLIC_KEY }}"
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
Expand All @@ -100,3 +103,50 @@ jobs:
projectId: us3r-network
target: u3-dev
entryPoint: "./apps/u3/"
pwa_build_and_deploy:
if: github.ref == 'refs/heads/u3-pwa'
runs-on: ubuntu-latest
environment:
name: development
url: https://dev.u3.xyz
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "20"
- run: |
cd apps/u3
yarn install --ignore-engines
yarn build
env:
CI: false
REACT_APP_NAME: "U3 DEV"
NODE_OPTIONS: "--max_old_space_size=4096"
REACT_APP_API_BASE_URL: "${{ vars.REACT_APP_API_BASE_URL }}"
REACT_APP_S3_API_BASE_URL: "${{ vars.REACT_APP_S3_API_BASE_URL }}"
REACT_APP_US3R_UPLOAD_IMAGE_ENDPOINT: "${{ vars.REACT_APP_US3R_UPLOAD_IMAGE_ENDPOINT }}"
REACT_APP_CERAMIC_HOST: "${{ vars.REACT_APP_CERAMIC_HOST }}"
REACT_APP_CHROME_EXTENSION_URL: "${{ vars.REACT_APP_CHROME_EXTENSION_URL }}"
REACT_APP_API_SOCIAL_URL: "${{ vars.REACT_APP_API_SOCIAL_URL }}"
REACT_APP_XMTP_ENV: "${{ vars.REACT_APP_XMTP_ENV }}"
REACT_APP_LENS_ENV: "${{ vars.REACT_APP_LENS_ENV }}"
REACT_APP_FARCASTER_HUB_URL: "${{ vars.REACT_APP_FARCASTER_HUB_URL }}"
REACT_APP_FARCASTER_NETWORK: "${{ vars.REACT_APP_FARCASTER_NETWORK }}"
REACT_APP_NFT_STORAGE_API_KEY: "${{ vars.REACT_APP_NFT_STORAGE_API_KEY }}"
REACT_APP_DAPP_NFT_TO_MINT: "${{ vars.REACT_APP_DAPP_NFT_TO_MINT }}"
REACT_APP_DAPP_NFT_FIXED_PRICE_STRATEGY: "${{ vars.REACT_APP_DAPP_NFT_FIXED_PRICE_STRATEGY }}"
REACT_APP_DAPP_NFT_CHAIN_ID: "${{ vars.REACT_APP_DAPP_NFT_CHAIN_ID }}"
REACT_APP_DAPP_NFT_RECIPIENT_ADDRESS: "${{ vars.REACT_APP_DAPP_NFT_RECIPIENT_ADDRESS }}"
REACT_APP_CASTER_NFT_TO_MINT: "${{ vars.REACT_APP_CASTER_NFT_TO_MINT }}"
REACT_APP_CASTER_NFT_FIXED_PRICE_STRATEGY: "${{ vars.REACT_APP_CASTER_NFT_FIXED_PRICE_STRATEGY }}"
REACT_APP_CASTER_NFT_CHAIN_ID: "${{ vars.REACT_APP_CASTER_NFT_CHAIN_ID }}"
REACT_APP_CASTER_NFT_RECIPIENT_ADDRESS: "${{ vars.REACT_APP_CASTER_NFT_RECIPIENT_ADDRESS }}"
REACT_APP_VAPID_PUBLIC_KEY: "${{ vars.REACT_APP_VAPID_PUBLIC_KEY }}"
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_US3R_NETWORK }}"
channelId: live
projectId: us3r-network
target: u3-pwa
entryPoint: "./apps/u3/"
2 changes: 2 additions & 0 deletions apps/u3/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ REACT_APP_CASTER_NFT_RECIPIENT_ADDRESS = 0x885d0069e238C7929F0351689A9493fECad9
# REACT_APP_CASTER_NFT_FIXED_PRICE_STRATEGY = 0x04E2516A2c207E84a1839755675dfd8eF6302F0a
# REACT_APP_CASTER_NFT_CHAIN_ID = 999
# REACT_APP_CASTER_NFT_RECIPIENT_ADDRESS = 0x885d0069e238C7929F0351689A9493fECad952Fe

REACT_APP_VAPID_PUBLIC_KEY = BGMGngE6KTyCIbeBwtNLSObcu0IZM_QH8PVd4c4M5trYPonjjXGDM3aIhqFLIWFRyEF7XiHGB0CBcclsQTSWJoM
3 changes: 3 additions & 0 deletions apps/u3/.firebaserc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
],
"u3-dev": [
"us3r-u3-dev"
],
"u3-pwa": [
"us3r-u3-pwa"
]
}
}
Expand Down
1 change: 1 addition & 0 deletions apps/u3/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"unfollowed",
"unpinup",
"upsert",
"Upvote",
"viem",
"Warpcast",
"Whatsnew",
Expand Down
15 changes: 15 additions & 0 deletions apps/u3/firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
"destination": "/index.html"
}
]
},
{
"target": "u3-pwa",
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
]
}
4 changes: 3 additions & 1 deletion apps/u3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
"@noble/ed25519": "^2.0.0",
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-tooltip": "^1.0.7",
"@rainbow-me/rainbowkit": "^1.3.1",
"@react-spring/web": "^9.6.1",
Expand Down Expand Up @@ -122,7 +124,7 @@
},
"scripts": {
"start": "craco start",
"build": "craco build",
"build": "craco build NODE_OPTIONS=--max-old-space-size=4096",
"build:report": "craco build --report",
"test": "craco test",
"eject": "react-scripts eject",
Expand Down
12 changes: 12 additions & 0 deletions apps/u3/public/service-worker-dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable */

// listen for push event
self.addEventListener('push', (event) => {
let { title, body, icon } = event.data.json();
if (!title || title === 'undefined') title = 'U3 - Your Web3 Gateway';
if (!body) return;
self.registration.showNotification(title, {
body,
icon: icon || `logo192.png`,
});
});
12 changes: 12 additions & 0 deletions apps/u3/public/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable */

// listen for push event
self.addEventListener('push', (event) => {
let { title, body, icon } = event.data.json();
if (!title || title === 'undefined') title = 'U3 - Your Web3 Gateway';
if (!body) return;
self.registration.showNotification(title, {
body,
icon: icon || `logo192.png`,
});
});
25 changes: 25 additions & 0 deletions apps/u3/src/components/common/icons/DegenTip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export default function DegenTip({ className }: { className: string }) {
return (
<svg
width="789"
height="668"
viewBox="0 0 789 668"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className={className}
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M115.185 411.477L118.367 469.444C118.575 473.392 120.055 477.107 122.552 480.15C140.007 501.282 218.264 575.014 394.616 575.014C570.968 575.014 648.278 502.234 666.38 480.544C669.108 477.27 670.68 473.206 670.934 468.933L674.089 411.517C695.084 399.997 716.758 386.98 716.758 386.98C750.835 368.518 788.866 395.038 788.935 433.936C789.051 496.87 739.877 561.545 673.548 602.301C598.758 648.258 487.117 667.324 394.664 667.324C302.211 667.324 190.57 648.258 115.78 602.301C49.4513 561.545 0.277187 496.893 0.392781 433.936C0.462138 395.038 38.4929 368.518 72.5702 386.98C72.5702 386.98 94.207 399.965 115.185 411.477Z"
fill="#A36EFD"
/>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M394.641 0.113525C538.834 0.113525 577.929 3.48079 636.558 10.2154H636.535C663.561 13.3272 685.224 33.438 683.212 60.6782L661.616 354.872C654.858 356.83 647.488 359.303 639.223 362.077C595.905 376.615 527.997 399.404 394.64 399.404C261.283 399.404 193.376 376.615 150.057 362.077C141.784 359.3 134.407 356.825 127.643 354.866L106.047 60.6782C104.059 33.438 125.652 12.8395 152.724 10.2154C210.637 4.59548 270.932 0.113525 394.641 0.113525ZM137.991 495.835L138.067 496.869L139.557 497.212C139.024 496.748 138.502 496.289 137.991 495.835ZM649.85 497.178L651.193 496.869L651.262 495.928C650.8 496.341 650.329 496.757 649.85 497.178Z"
fill="#A36EFD"
/>
</svg>
);
}
4 changes: 4 additions & 0 deletions apps/u3/src/components/notification/NotificationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import LensIcon from '../common/icons/LensIcon';
import FarcasterIcon from '../common/icons/FarcasterIcon';
import Loading from '../common/loading/Loading';
import { useNav } from '../../contexts/NavCtx';
// import { NotificationSettingsGroup } from './PushNotificationsToogleBtn';

export default function NotificationModal() {
const { openNotificationModal, setOpenNotificationModal } = useNav();
Expand All @@ -27,6 +28,9 @@ export default function NotificationModal() {
<Body>
<Header>
<Title>Notifications</Title>
{/* <div className="text-[white] flex gap-[100px] w-[100px] overflow-hidden whitespace-nowrap">
<NotificationSettingsGroup />
</div> */}
<ModalCloseBtn onClick={() => setOpenNotificationModal(false)} />
</Header>
{notifications && notifications.length > 0 && (
Expand Down
182 changes: 182 additions & 0 deletions apps/u3/src/components/notification/PushNotificationsToogleBtn.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import { useEffect, useState } from 'react';
import { toast } from 'react-toastify';
import WebPushService from '@/utils/pwa/WebPushService';
import { sendNotification } from '@/utils/pwa/notification';
import {
NotificationSetting,
NotificationSettingType,
} from '@/services/notification/types/notification-settings';
import useLogin from '@/hooks/shared/useLogin';
import {
addNotificationSetting,
fethNotificationSettings,
updateNotificationSetting,
} from '@/services/notification/api/notification-settings';
import { ApiRespCode } from '@/services/shared/types';
import { useFarcasterCtx } from '@/contexts/social/FarcasterCtx';
import Switch from '../common/switch/Switch';
import ColorButton from '../common/button/ColorButton';

export function NotificationSettingsGroup() {
const {
currFid,
isConnected: isLoginFarcaster,
currUserInfo: farcasterUserInfo,
openFarcasterQR,
} = useFarcasterCtx();
const { isLogin } = useLogin();
const [settings, setSettings] = useState<NotificationSetting[]>([]);
const [loadingTypes, setLoadingTypes] = useState<NotificationSettingType[]>(
[]
);
const [settingsLoading, setSettingsLoading] = useState(true);
useEffect(() => {
if (isLogin) {
setSettingsLoading(true);
fethNotificationSettings()
.then((res) => {
setSettings(res?.data?.data || []);
})
.catch((err) => {
console.log(err);
setSettings([]);
})
.finally(() => {
setSettingsLoading(false);
});
} else {
setSettings([]);
setSettingsLoading(false);
}
}, [isLogin]);

const upsertSetting = async (setting: Partial<NotificationSetting>) => {
if (!isLogin) return;
const index = settings.findIndex((s) => s.type === setting.type);

try {
setLoadingTypes((prev) => {
if (prev.includes(setting.type)) return prev;
return [...prev, setting.type];
});
if (index >= 0 && settings[index]?.id) {
// update
const res = await updateNotificationSetting(settings[index].id, {
...settings[index],
...setting,
});
if (res.data.code === ApiRespCode.SUCCESS) {
setSettings((prev) => {
return [
...prev.slice(0, index),
{
...prev[index],
...setting,
},
...prev.slice(index + 1),
] as NotificationSetting[];
});
}
} else {
// add
const res = await addNotificationSetting({
type: setting.type,
...setting,
});
if (res.data.code === ApiRespCode.SUCCESS) {
setSettings((prev) => {
return [...prev, res.data.data] as NotificationSetting[];
});
}
}
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
throw error;
} finally {
setLoadingTypes((prev) => {
if (prev.includes(setting.type)) {
return prev.filter((t) => t !== setting.type);
}
return prev;
});
}
};

const webpushSubscribed = settings.some(
(setting) =>
setting.type === NotificationSettingType.WEB_PUSH &&
setting?.enable === true &&
!!setting?.subscription
);

const webpushLoading = loadingTypes.includes(
NotificationSettingType.WEB_PUSH
);
const webpushDisabled = settingsLoading || webpushLoading;

const handlePushChange = async (checked: boolean) => {
try {
if (!checked) {
const payload = await WebPushService.unsubscribe();
await upsertSetting({
type: NotificationSettingType.WEB_PUSH,
fid: currFid ? String(currFid) : undefined,
enable: false,
subscription: payload ? JSON.stringify(payload) : undefined,
});
} else {
if (!WebPushService.hasPermission()) {
await WebPushService.requestPermission();
}
let subscription = await WebPushService.getSubscription();
if (!subscription) {
subscription = await WebPushService.subscribe();
}

await upsertSetting({
type: NotificationSettingType.WEB_PUSH,
fid: currFid ? String(currFid) : undefined,
enable: true,
subscription: JSON.stringify(subscription),
});
sendNotification(`Subscribed to notifications`);
}
} catch (error) {
toast.error(error.message);
console.error(error);
}
};

return (
// <div>
// <p>Web Push</p>
<>
<Switch
onColor="#5057AA"
disabled={webpushDisabled}
checked={webpushSubscribed}
onChange={handlePushChange}
/>
{(() => {
if (webpushLoading) {
if (webpushSubscribed) {
return 'Unsubscribing...';
}
return 'Subscribing...';
}
return 'Subscribe Notifications';
})()}

{/* {!(isLoginFarcaster && farcasterUserInfo) && (
<ColorButton
className="h-[24px] text-[12px] font-normal"
onClick={() => openFarcasterQR()}
>
Login Farcaster
</ColorButton>
)} */}
</>
// </div>
);
}
Loading

0 comments on commit c582b99

Please sign in to comment.