export * from ~/utils

This commit is contained in:
gawlk
2023-08-18 19:55:31 +02:00
committed by Paul Miller
parent 6cd5d0cb53
commit c01c9cc7f7
35 changed files with 61 additions and 55 deletions

View File

@@ -19,7 +19,7 @@ import {
} from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import { createDeepSignal } from "~/utils/deepSignal";
import { createDeepSignal } from "~/utils";
export const THREE_COLUMNS =
"grid grid-cols-[auto,1fr,auto] gap-4 py-2 px-2 border-b border-neutral-800 last:border-b-0";

View File

@@ -9,8 +9,7 @@ import on from "~/assets/icons/upload-channel.svg";
import { AmountFiat, AmountSats } from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import { generateGradient } from "~/utils/gradientHash";
import { timeAgo } from "~/utils/prettyPrintTime";
import { generateGradient, timeAgo } from "~/utils";
export const ActivityAmount: ParentComponent<{
amount: string;

View File

@@ -4,7 +4,7 @@ import bolt from "~/assets/icons/bolt.svg";
import chain from "~/assets/icons/chain.svg";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import { satsToUsd } from "~/utils/conversions";
import { satsToUsd } from "~/utils";
function prettyPrintAmount(n?: number | bigint): string {
if (!n || n.valueOf() === 0) {

View File

@@ -3,7 +3,7 @@ import { createMemo, Match, ParentComponent, Show, Switch } from "solid-js";
import { AmountEditable, Card, VStack } from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import { satsToUsd } from "~/utils/conversions";
import { satsToUsd } from "~/utils";
const noop = () => {
// do nothing

View File

@@ -20,7 +20,7 @@ import { useI18n } from "~/i18n/context";
import { Network } from "~/logic/mutinyWalletSetup";
import { useMegaStore } from "~/state/megaStore";
import { DIALOG_CONTENT, DIALOG_POSITIONER } from "~/styles/dialogs";
import { satsToUsd, usdToSats } from "~/utils/conversions";
import { satsToUsd, usdToSats } from "~/utils";
function fiatInputSanitizer(input: string): string {
// Make sure only numbers and a single decimal point are allowed

View File

@@ -2,7 +2,7 @@ import { Show } from "solid-js";
import { QRCodeSVG } from "solid-qr-code";
import { useI18n } from "~/i18n/context";
import { useCopy } from "~/utils/useCopy";
import { useCopy } from "~/utils";
export function CopyableQR(props: { value: string }) {
const i18n = useI18n();

View File

@@ -4,7 +4,7 @@ import { A } from "solid-start";
import { Button, InfoBox, SimpleDialog, TextField } from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import eify from "~/utils/eify";
import { eify } from "~/utils";
export function DecryptDialog() {
const i18n = useI18n();

View File

@@ -4,7 +4,7 @@ import { createSignal } from "solid-js";
import { Button, ConfirmDialog, showToast } from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import eify from "~/utils/eify";
import { eify } from "~/utils";
export function DeleteEverything(props: { emergency?: boolean }) {
const i18n = useI18n();

View File

@@ -32,10 +32,13 @@ import {
import { useI18n } from "~/i18n/context";
import { Network } from "~/logic/mutinyWalletSetup";
import { useMegaStore } from "~/state/megaStore";
import mempoolTxUrl from "~/utils/mempoolTxUrl";
import { prettyPrintTime } from "~/utils/prettyPrintTime";
import { MutinyTagItem, tagToMutinyTag } from "~/utils/tags";
import { useCopy } from "~/utils/useCopy";
import {
mempoolTxUrl,
MutinyTagItem,
prettyPrintTime,
tagToMutinyTag,
useCopy
} from "~/utils";
interface ChannelClosure {
channel_id: string;

View File

@@ -15,8 +15,7 @@ import {
} from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import { downloadTextFile } from "~/utils/download";
import eify from "~/utils/eify";
import { downloadTextFile, eify } from "~/utils";
export function ImportExport(props: { emergency?: boolean }) {
const i18n = useI18n();

View File

@@ -8,7 +8,7 @@ import shareBlack from "~/assets/icons/share-black.svg";
import { AmountFiat, AmountSats, TruncateMiddle } from "~/components";
import { useI18n } from "~/i18n/context";
import { ReceiveFlavor } from "~/routes/Receive";
import { useCopy } from "~/utils/useCopy";
import { useCopy } from "~/utils";
function KindIndicator(props: { kind: ReceiveFlavor }) {
const i18n = useI18n();

View File

@@ -26,8 +26,7 @@ import {
import { useI18n } from "~/i18n/context";
import { Network } from "~/logic/mutinyWalletSetup";
import { useMegaStore } from "~/state/megaStore";
import eify from "~/utils/eify";
import mempoolTxUrl from "~/utils/mempoolTxUrl";
import { eify, mempoolTxUrl } from "~/utils";
// TODO: hopefully I don't have to maintain this type forever but I don't know how to pass it around otherwise
type RefetchPeersType = (

View File

@@ -2,7 +2,7 @@ import { MutinyWallet } from "@mutinywallet/mutiny-wasm";
import { Button, InnerCard, NiceP, VStack } from "~/components";
import { useI18n } from "~/i18n/context";
import { downloadTextFile } from "~/utils/download";
import { downloadTextFile } from "~/utils";
export function Logs() {
const i18n = useI18n();

View File

@@ -17,9 +17,7 @@ import redClose from "~/assets/icons/red-close.svg";
import { ActivityAmount, Card, InfoBox, VStack } from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import { createDeepSignal } from "~/utils/deepSignal";
import eify from "~/utils/eify";
import { formatExpiration } from "~/utils/prettyPrintTime";
import { createDeepSignal, eify, formatExpiration } from "~/utils";
type PendingItem = {
id: string;

View File

@@ -2,7 +2,7 @@ import { createMemo, createSignal, For, Match, Switch } from "solid-js";
import copyIcon from "~/assets/icons/copy.svg";
import { useI18n } from "~/i18n/context";
import { useCopy } from "~/utils/useCopy";
import { useCopy } from "~/utils";
export function SeedWords(props: {
words: string;

View File

@@ -7,7 +7,7 @@ import shareBlack from "~/assets/icons/share-black.svg";
import shareIcon from "~/assets/icons/share.svg";
import { Card, JsonModal, VStack } from "~/components";
import { useI18n } from "~/i18n/context";
import { useCopy } from "~/utils/useCopy";
import { useCopy } from "~/utils";
const STYLE =
"px-4 py-2 rounded-xl border-2 border-white flex gap-2 items-center font-semibold hover:text-m-blue transition-colors";

View File

@@ -6,7 +6,7 @@ import { createMemo, createSignal, For, onMount, Show } from "solid-js";
import { TinyButton } from "~/components";
import { useMegaStore } from "~/state/megaStore";
import { MutinyTagItem, sortByLastUsed } from "~/utils/tags";
import { MutinyTagItem, sortByLastUsed } from "~/utils";
const createLabelValue = (label: string): Partial<MutinyTagItem> => {
return { name: label, kind: "Contact" };

View File

@@ -23,8 +23,7 @@ import down from "~/assets/icons/down.svg";
import { DecryptDialog, LoadingIndicator } from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import { generateGradient } from "~/utils/gradientHash";
import { MutinyTagItem } from "~/utils/tags";
import { generateGradient, MutinyTagItem } from "~/utils";
export const SmallHeader: ParentComponent<{ class?: string }> = (props) => {
return (

View File

@@ -1,6 +1,6 @@
import initWaila, { PaymentParams } from "@mutinywallet/waila-wasm";
import { Result } from "~/utils/typescript";
import { Result } from "~/utils";
// Make sure we've initialzied waila before we try to use it
await initWaila();

View File

@@ -22,7 +22,7 @@ import {
} from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import { gradientsPerContact } from "~/utils/gradientHash";
import { gradientsPerContact } from "~/utils";
function ContactRow() {
const i18n = useI18n();

View File

@@ -26,7 +26,7 @@ import {
VStack
} from "~/components/layout";
import { useI18n } from "~/i18n/context";
import eify from "~/utils/eify";
import { eify } from "~/utils";
const FEEDBACK_API = import.meta.env.VITE_FEEDBACK;

View File

@@ -46,10 +46,12 @@ import { useI18n } from "~/i18n/context";
import { matchError } from "~/logic/errorDispatch";
import { Network } from "~/logic/mutinyWalletSetup";
import { useMegaStore } from "~/state/megaStore";
import eify from "~/utils/eify";
import mempoolTxUrl from "~/utils/mempoolTxUrl";
import { objectToSearchParams } from "~/utils/objectToSearchParams";
import { MutinyTagItem } from "~/utils/tags";
import {
eify,
mempoolTxUrl,
MutinyTagItem,
objectToSearchParams
} from "~/utils";
type OnChainTx = {
transaction: {

View File

@@ -41,8 +41,7 @@ import {
import { useI18n } from "~/i18n/context";
import { Network } from "~/logic/mutinyWalletSetup";
import { useMegaStore } from "~/state/megaStore";
import { getRedshifted, setRedshifted } from "~/utils/fakeLabels";
import mempoolTxUrl from "~/utils/mempoolTxUrl";
import { getRedshifted, mempoolTxUrl, setRedshifted } from "~/utils";
type ShiftOption = "utxo" | "lightning";

View File

@@ -46,9 +46,7 @@ import { useI18n } from "~/i18n/context";
import { Network } from "~/logic/mutinyWalletSetup";
import { ParsedParams, toParsedParams } from "~/logic/waila";
import { useMegaStore } from "~/state/megaStore";
import eify from "~/utils/eify";
import mempoolTxUrl from "~/utils/mempoolTxUrl";
import { MutinyTagItem } from "~/utils/tags";
import { eify, mempoolTxUrl, MutinyTagItem } from "~/utils";
import { FeedbackLink } from "./Feedback";

View File

@@ -35,8 +35,7 @@ import { useI18n } from "~/i18n/context";
import { Network } from "~/logic/mutinyWalletSetup";
import { MethodChooser, SendSource } from "~/routes/Send";
import { useMegaStore } from "~/state/megaStore";
import eify from "~/utils/eify";
import mempoolTxUrl from "~/utils/mempoolTxUrl";
import { eify, mempoolTxUrl } from "~/utils";
const CHANNEL_FEE_ESTIMATE_ADDRESS =
"bc1qf7546vg73ddsjznzq57z3e8jdn6gtw6au576j07kt6d9j7nz8mzsyn6lgf";

View File

@@ -23,7 +23,7 @@ import {
} from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import eify from "~/utils/eify";
import { eify } from "~/utils";
function Nwc() {
const i18n = useI18n();

View File

@@ -17,8 +17,7 @@ import {
} from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import eify from "~/utils/eify";
import { timeout } from "~/utils/timeout";
import { eify, timeout } from "~/utils";
type EncryptPasswordForm = {
existingPassword: string;

View File

@@ -27,8 +27,7 @@ import {
} from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import eify from "~/utils/eify";
import { subscriptionValid } from "~/utils/subscriptions";
import { eify, subscriptionValid } from "~/utils";
function Perks(props: { alreadySubbed?: boolean }) {
const i18n = useI18n();

View File

@@ -29,8 +29,7 @@ import {
} from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import eify from "~/utils/eify";
import { WORDS_EN } from "~/utils/words";
import { eify, WORDS_EN } from "~/utils";
type SeedWordsForm = {
words: string[];

View File

@@ -20,7 +20,7 @@ import {
setSettings
} from "~/logic/mutinyWalletSetup";
import { useMegaStore } from "~/state/megaStore";
import eify from "~/utils/eify";
import { eify } from "~/utils";
export function SettingsStringsEditor() {
const i18n = useI18n();

View File

@@ -21,9 +21,7 @@ import {
setupMutinyWallet
} from "~/logic/mutinyWalletSetup";
import { ParsedParams } from "~/logic/waila";
import eify from "~/utils/eify";
import { subscriptionValid } from "~/utils/subscriptions";
import { MutinyTagItem } from "~/utils/tags";
import { eify, MutinyTagItem, subscriptionValid } from "~/utils";
const MegaStoreContext = createContext<MegaStore>();

View File

@@ -1,5 +1,5 @@
/// Sometimes we catch an error as `unknown` so this turns it into an Error.
export default function eify(e: unknown): Error {
export function eify(e: unknown): Error {
if (e instanceof Error) {
return e;
} else if (typeof e === "string") {

View File

@@ -1,4 +1,4 @@
export default function getHostname(url: string): string {
export function getHostname(url: string): string {
// Check if the URL begins with "ws://" or "wss://"
if (url.startsWith("ws://")) {
// If it does, remove "ws://" from the URL

16
src/utils/index.ts Normal file
View File

@@ -0,0 +1,16 @@
export * from "./conversions";
export * from "./deepSignal";
export * from "./download";
export * from "./eify";
export * from "./fakeLabels";
export * from "./getHostname";
export * from "./gradientHash";
export * from "./mempoolTxUrl";
export * from "./objectToSearchParams";
export * from "./prettyPrintTime";
export * from "./subscriptions";
export * from "./tags";
export * from "./timeout";
export * from "./typescript";
export * from "./useCopy";
export * from "./words";

View File

@@ -1,6 +1,6 @@
import { Network } from "~/logic/mutinyWalletSetup";
export default function mempoolTxUrl(txid?: string, network?: Network) {
export function mempoolTxUrl(txid?: string, network?: Network) {
if (!txid || !network) {
console.error("Problem creating the mempool url");
return "#";