-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3c7bd1
commit 99fb117
Showing
487 changed files
with
6,475 additions
and
6,823 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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,74 @@ | ||
import { useEffect } from 'react'; | ||
|
||
import { useLatestRef } from './use-latest-ref'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
type FunctionArguments<T extends Function> = T extends (...args: infer R) => any ? R : never; | ||
type AddEventListener = FunctionArguments<typeof document.addEventListener>; | ||
|
||
let _window: Window | undefined = undefined; | ||
|
||
// Note: Accessing "window" in IE11 is somewhat expensive, and calling "typeof window" | ||
// hits a memory leak, whereas aliasing it and calling "typeof _window" does not. | ||
// Caching the window value at the file scope lets us minimize the impact. | ||
try { | ||
_window = window; | ||
} catch (e) { | ||
/* no-op */ | ||
} | ||
|
||
/** | ||
* Helper to get the window object. The helper will make sure to use a cached variable | ||
* of "window", to avoid overhead and memory leaks in IE11. | ||
*/ | ||
function getWindow(node?: HTMLElement | null): Window | undefined { | ||
return node?.ownerDocument?.defaultView ?? _window; | ||
} | ||
|
||
/** | ||
* Check if we can use the DOM. Useful for SSR purposes | ||
*/ | ||
function checkIsBrowser() { | ||
const _window = getWindow(); | ||
return Boolean( | ||
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation | ||
typeof _window !== 'undefined' && _window.document && _window.document.createElement | ||
); | ||
} | ||
|
||
const isBrowser = checkIsBrowser(); | ||
|
||
/** | ||
* React hook to manage browser event listeners | ||
* | ||
* @param event the event name | ||
* @param handler the event handler function to execute | ||
* @param doc the dom environment to execute against (defaults to `document`) | ||
* @param options the event listener options | ||
*/ | ||
export function useEventListener( | ||
event: keyof WindowEventMap, | ||
handler: (event: any) => void, | ||
doc: Document | null = isBrowser ? document : null, | ||
options?: AddEventListener[2] | ||
) { | ||
const savedHandler = useLatestRef(handler); | ||
|
||
useEffect(() => { | ||
if (!doc) return; | ||
|
||
const listener = (event: any) => { | ||
savedHandler.current(event); | ||
}; | ||
|
||
doc.addEventListener(event, listener, options); | ||
|
||
return () => { | ||
doc.removeEventListener(event, listener, options); | ||
}; | ||
}, [event, doc, options, savedHandler]); | ||
|
||
return () => { | ||
doc?.removeEventListener(event, savedHandler.current, options); | ||
}; | ||
} |
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,17 @@ | ||
import { useEffect, useRef } from 'react'; | ||
|
||
/** | ||
* React hook to persist any value between renders, | ||
* but keeps it up-to-date if it changes. | ||
* | ||
* @param value the value or function to persist | ||
*/ | ||
export function useLatestRef<T>(value: T) { | ||
const ref = useRef(value); | ||
|
||
useEffect(() => { | ||
ref.current = value; | ||
}, [value]); | ||
|
||
return ref; | ||
} |
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 was deleted.
Oops, something went wrong.
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,35 @@ | ||
// TypeScript port of https://github.com/DavidWells/safe-await/ | ||
|
||
// Native Error types https://mzl.la/2Veh3TR | ||
const nativeExceptions = [ | ||
EvalError, | ||
RangeError, | ||
ReferenceError, | ||
SyntaxError, | ||
TypeError, | ||
URIError, | ||
].filter(except => typeof except === 'function'); | ||
|
||
function throwNative(error: Error) { | ||
for (const Exception of nativeExceptions) { | ||
if (error instanceof Exception) throw error; | ||
} | ||
} | ||
|
||
export async function safeAwait<T>(promise: Promise<T>, finallyFn?: () => void) { | ||
return promise | ||
.then(data => { | ||
if (data instanceof Error) { | ||
throwNative(data); | ||
return [data] as readonly [Error]; | ||
} | ||
return [undefined, data] as const; | ||
}) | ||
.catch((error: Error) => { | ||
throwNative(error); | ||
return [error] as const; | ||
}) | ||
.finally(() => { | ||
if (finallyFn) finallyFn(); | ||
}); | ||
} |
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,14 +1,12 @@ | ||
import { memo } from 'react'; | ||
|
||
import { BoxProps } from '@stacks/ui'; | ||
|
||
import { AccountAvatar } from '@app/components/account/account-avatar/account-avatar'; | ||
|
||
interface AccountAvatarItemProps extends BoxProps { | ||
interface AccountAvatarItemProps { | ||
publicKey: string; | ||
index: number; | ||
name: string; | ||
} | ||
export const AccountAvatarItem = memo(({ name, publicKey, index }: AccountAvatarItemProps) => { | ||
return <AccountAvatar name={name} publicKey={publicKey} index={index} />; | ||
return <AccountAvatar index={index} name={name} publicKey={publicKey} />; | ||
}); |
Oops, something went wrong.