-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: able to toggle platform notifications
- Loading branch information
Showing
16 changed files
with
269 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
import { useIsMetaMaskReady } from '@/hooks/use-is-meta-mask-ready'; | ||
import { getPlatformInfos, togglePlatform } from '@/utils'; | ||
import { Platform, PlatformInfo } from '@/types'; | ||
|
||
export function useToggleNotifications(deps: React.DependencyList = []) { | ||
const isMetaMaskReady = useIsMetaMaskReady(); | ||
const [platforms, setPlatforms] = React.useState<PlatformInfo[]>([]); | ||
const [isUpdating, setIsUpdating] = React.useState(false); | ||
|
||
const toggle = React.useCallback( | ||
async (platformId: Platform, enabled?: boolean) => { | ||
try { | ||
const platform = platforms.find((p) => p.id === platformId); | ||
const enabled_ = enabled ?? !platform?.enabled; | ||
|
||
if (!platform) { | ||
throw new Error(`Platform ${platformId} not found`); | ||
} | ||
|
||
setIsUpdating(true); | ||
await togglePlatform(platform.id, enabled_); | ||
setPlatforms(await getPlatformInfos()); | ||
} catch (e) { | ||
console.error(e); | ||
} finally { | ||
setIsUpdating(false); | ||
} | ||
}, | ||
[platforms], | ||
); | ||
|
||
React.useEffect(() => { | ||
if (isMetaMaskReady) { | ||
getPlatformInfos().then(setPlatforms); | ||
} | ||
}, [isMetaMaskReady, ...deps]); | ||
|
||
return { | ||
platforms, | ||
toggle, | ||
isUpdating, | ||
}; | ||
} |
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,15 @@ | ||
import React from 'react'; | ||
|
||
import { Notifications } from '@/modules/preferences/notifications'; | ||
|
||
export function Preferences() { | ||
return ( | ||
<div className="max-w-7xl mx-auto"> | ||
<h2 className="text-3xl font-semibold leading-7 text-gray-900 mb-6 mt-12"> | ||
Preferences | ||
</h2> | ||
|
||
<Notifications /> | ||
</div> | ||
); | ||
} |
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,33 @@ | ||
import { useToggleNotifications } from '@/hooks/use-toggle-notifications'; | ||
import { Checkbox } from '@/components/ui/checkbox'; | ||
|
||
export function Notifications() { | ||
const { toggle, platforms } = useToggleNotifications(); | ||
|
||
return ( | ||
<div className="bg-white shadow sm:rounded-lg"> | ||
<div className="px-4 py-5 sm:p-6"> | ||
<h3 className="text-base font-semibold leading-6 text-gray-900"> | ||
Notifications | ||
</h3> | ||
|
||
<div className="mt-2 space-y-2"> | ||
<div className="max-w-xl text-sm text-gray-500"> | ||
Choose which platforms you want to receive notifications on. | ||
</div> | ||
<div className="flex items-center gap-4"> | ||
{platforms.map((platform) => ( | ||
<label key={platform.id} className="flex items-center gap-2"> | ||
<Checkbox | ||
checked={platform.enabled} | ||
onCheckedChange={() => toggle(platform.id)} | ||
/> | ||
{platform.name} | ||
</label> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
export { type GetSnapsResponse, type Snap } from './snap'; | ||
export * from './snap'; |
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
Oops, something went wrong.