import React from 'react'
import { useAuthUser } from '~/src/contexts/AuthUser'
import { useInterceptor } from './useInterceptor'
/**
* Setup axios interceptors to work with auth
*/
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
import { Pubkey } from '@cosmjs/amino' | |
import { Uint64 } from '@cosmjs/math' | |
import { decodePubkey } from '@cosmjs/proto-signing' | |
import { assert } from '@cosmjs/utils' | |
import { stride } from '@stride/proto' | |
import { BaseAccount, ModuleAccount } from 'cosmjs-types/cosmos/auth/v1beta1/auth' | |
import { | |
BaseVestingAccount, | |
ContinuousVestingAccount, | |
DelayedVestingAccount, |
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
import { intervalToDuration, isAfter, eachDayOfInterval, addMonths } from 'date-fns' | |
const remaining = intervalToDuration({ | |
start: now, | |
end: target | |
}) | |
const days = | |
remaining.months && remaining.days | |
? remaining.days + |
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
export const getServerSideProps = withPageAuthRequired({ | |
async getServerSideProps(ctx) { | |
const whitelisted = ['your@email.com'] | |
const session = getSession(ctx.req, ctx.res) | |
if (!whitelisted.includes(session.user.email)) { | |
return { | |
redirect: { | |
destination: '/logout', |
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
import { useEffect, useRef } from 'react' | |
// useEffect that runs on mount and works with Suspense / Fast Refresh | |
const useMount = (fn: () => void) => { | |
const isMountedRef = useRef(false) | |
useEffect(() => { | |
if (isMountedRef.current) return | |
isMountedRef.current = true | |
fn() |
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
import { delay } from './time' | |
export async function poll<T = any>(callback: () => Promise<T>, condition: (t: T) => boolean, ms: number): Promise<T> { | |
let first = true | |
while (true) { | |
const data = first ? await callback() : await delay(ms).then(callback) | |
if (condition(data) === true) { | |
return data |
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
import React, { useState, useEffect } from 'react' | |
interface MemoizeProps<T, Y extends unknown> { | |
value: () => T | |
dependencies: Y[] | |
} | |
const Memoize = ({ value, dependencies }) => { | |
const [state, setState] = useState(value) | |
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
const { pathname } = useRouter() | |
const active: Record<string, boolean> = useMemo(() => { | |
return [ | |
{ key: 'home', url: '/' }, | |
{ key: 'about', url: '/about' }, | |
{ key: 'contact', url: '/contact' } | |
].reduce((object, link) => { | |
object[link.key] = pathname === link.url | |
return object |
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
export function mergeRefs<T>(...refs: Ref<T>[]) { | |
return (value: T) => { | |
refs.forEach((ref) => { | |
if (typeof ref === 'function') { | |
ref(value) | |
} else if (ref.current) { | |
ref.current = value | |
} | |
}) | |
} |
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
import React, { useMemo } from 'react' | |
import ReactDOM from 'react-dom' | |
import styled from 'styled-components' | |
import { usePopper } from 'react-popper' | |
import type { Placement, Offsets } from '@popperjs/core' | |
import { useStateRef, useUpdateEffect, useDocumentListener, useOutsideClick } from '~/src/hooks' | |
import { theme } from '~/src/theme' | |
interface Props { |