Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General cleanup #9537

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
2 changes: 1 addition & 1 deletion packages/commonwealth/client/scripts/helpers/awsHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function replaceBucketWithCDN(url) {
return url.replace(
's3.amazonaws.com/assets.commonwealth.im',
'assets.commonwealth.im'
'assets.commonwealth.im',
);
}
23 changes: 0 additions & 23 deletions packages/commonwealth/client/scripts/helpers/getFetch.ts

This file was deleted.

71 changes: 0 additions & 71 deletions packages/commonwealth/client/scripts/helpers/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { ChainBase, ChainNetwork } from '@hicommonwealth/shared';
import type { Coin } from 'adapters/currency';
import BigNumber from 'bignumber.js';
import moment from 'moment';
import React from 'react';
import app from 'state';
import { getChainDecimals } from '../controllers/app/webWallets/utils';
import Account from '../models/Account';
import IChainAdapter from '../models/IChainAdapter';
import { ThreadStage } from '../models/types';

export async function sleep(msec) {
Expand Down Expand Up @@ -98,24 +94,6 @@ export function pluralizeWithoutNumberPrefix(num: number, str: string) {
}
}

export function articlize(str: string) {
if (str.trimLeft().match(/^[aeiouAEIOU]/)) {
return `an ${str.trimLeft()}`;
} else {
return `a ${str.trimLeft()}`;
}
}

export function formatAsTitleCase(str: string) {
return str
.toLowerCase()
.split(' ')
.map((word) => {
return word.replace(word[0], word[0].toUpperCase());
})
.join(' ');
}

export function formatLastUpdated(timestamp) {
if (timestamp.isBefore(moment().subtract(365, 'days')))
return timestamp.format('MMM D YYYY');
Expand All @@ -142,12 +120,6 @@ export function formatTimestamp(timestamp) {
.replace(' month', 'mo')}`;
}

export function formatTimestampAsDate(timestamp: moment.Moment) {
if (timestamp.isBefore(moment().startOf('year')))
return timestamp.format('MMM D YYYY');
else return timestamp.format('MMM D');
}

// duplicated in adapters/currency.ts
export function formatNumberLong(num: number) {
// format small numbers with decimals, large numbers with commas
Expand All @@ -158,21 +130,6 @@ export function formatNumberLong(num: number) {
return nf.format(num);
}

export function formatPercentShort(num: number) {
if (num === 0) return '0%';
if (num === 1) return '100%';
if (num > 1) return '100%+';
return `${(num * 100).toFixed(1)}%`;
}

/* Choose Total Digits to Display*/
export function formatPercent(num: number, digits: number) {
if (num === 0) return '0%';
if (num === 1) return '100%';
if (num > 1) return '100%+';
return `${(num * 100).toFixed(digits)}%`;
}

export function formatDuration(
duration: moment.Duration,
includeSeconds = true,
Expand All @@ -186,11 +143,6 @@ export function formatDuration(
].join('');
}

export function formatProposalHashShort(hash: string) {
if (!hash) return;
return `${hash.slice(0, 8)}…`;
}

export function formatAddressShort(
address: string,
numberOfVisibleCharacters = 5,
Expand Down Expand Up @@ -234,10 +186,6 @@ export function blocknumToDuration(blocknum: number) {
.asMilliseconds();
}

export function blockperiodToDuration(blocknum: number) {
return moment.duration(blocknum * app.chain.block.duration, 'seconds');
}

// loads remote scripts from a URI, e.g. Twitter widgets
export const loadScript = (scriptURI) => {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -302,22 +250,3 @@ export const handleRedirectClicks = (
callback();
}
};

// Decimals For Tokens
export function getDecimals(chain: IChainAdapter<Coin, Account>): number {
let decimals;
if (chain.meta.id === 'evmos') {
// Custom for evmos
decimals = 18;
} else if (chain && chain.meta) {
decimals = getChainDecimals(chain.id || '', chain.base);
} else if (chain.network === ChainNetwork.ERC721) {
decimals = 0;
} else if (chain.network === ChainNetwork.ERC1155) {
decimals = 0;
} else if (chain.base === ChainBase.CosmosSDK) {
decimals = 6;
}

return decimals;
}
4 changes: 2 additions & 2 deletions packages/commonwealth/client/scripts/helpers/truncate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const truncate = (
str: string,
maxCharLength = 140,
ellipsisPadding = 4
ellipsisPadding = 4,
): string => {
// Get the available width of the container or the window
const availableWidth = window.innerWidth;
Expand All @@ -20,7 +20,7 @@ export const truncate = (

// Calculate the maximum truncated length based on the available width and ellipsis width
const truncatedLength = Math.floor(
(maxWidth - ellipsisWidth) / lengthModifier
(maxWidth - ellipsisWidth) / lengthModifier,
);

return str.substring(0, truncatedLength) + '...';
Expand Down
24 changes: 0 additions & 24 deletions packages/commonwealth/client/scripts/helpers/typeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ export const isNotNil = <T>(x: T | Nil): x is T => !isNil(x);
export const isBoolean = (x: unknown): x is boolean =>
x === true || x === false;

/**
* Type guard for the `false` literal of the `boolean` primitive
*/
export const isFalse = (x: unknown): x is false =>
typeof x === 'boolean' && x === false;

/**
* Type guard for the `true` literal of the `boolean` primitive
*/
Expand Down Expand Up @@ -77,21 +71,3 @@ export const isEmptyString = (x: unknown): x is '' => isString(x) && x === '';
*/
export const isNonEmptyString = (x: unknown): x is string =>
isString(x) && !isEmptyString(x);

/**
* Type guard for the `Function` type
*/
// eslint-disable-next-line @typescript-eslint/ban-types
export const isFunction = (x: unknown): x is Function => x instanceof Function;

/**
* Typeguard for making sure a key is in an object when the object has no index signature
*/
export function hasKey<O, K extends string | number | symbol>(
obj: O,
key: K,
): obj is O & { [k in K]: unknown } {
// @ts-expect-error StrictNullChecks
if (typeof obj === 'object') return key in obj;
else return false;
}
11 changes: 0 additions & 11 deletions packages/commonwealth/client/scripts/helpers/validateTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { bech32 } from 'bech32';
import { isAddress } from 'web3-utils';
import type { ValidationStatus } from '../views/components/component_kit/cw_validation_text';

Expand All @@ -11,16 +10,6 @@ export function isValidEthAddress(address: string) {
return isAddress(address);
}

export function isValidCosmosAddress(address) {
try {
const decodedAddress = bech32.decode(address);
bech32.fromWords(decodedAddress.words);
return true;
} catch {
return false;
}
}

function isValidToken(input: string) {
const numberRegex = /^[1-9]\d*$/;
return numberRegex.test(input);
Expand Down
34 changes: 1 addition & 33 deletions packages/commonwealth/client/scripts/helpers/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,6 @@
import { WalletId } from '@hicommonwealth/shared';
import IWebWallet from '../models/IWebWallet';

// getWalletName() fetches friendly names for wallets. It is assumed
// that the user already knows what chain or community they are
// logging into, so a more concise wallet name can be used,
// e.g. "Keplr" instead of "Keplr (Ethereum)".
//
// Do not enumerate over this list for logins across multiple chains -
// there will be multiple entries with the same names.
//
// Examples:
// - Please login via {Metamask}.
// - Please login via {WalletConnect}.
// - Please reconnect your wallet via {Metamask}.
// - Please reconnect your wallet via {WalletConnect}.
// - Please select a login method: {Magic Link}, {Metamask}, {WalletConnect}...

const getWalletName = (walletId: WalletId) => {
const lookups = {
[WalletId.Magic]: 'Magic Link',
[WalletId.Polkadot]: 'Polkadot',
[WalletId.Metamask]: 'Metamask',
[WalletId.WalletConnect]: 'WalletConnect',
[WalletId.KeplrEthereum]: 'Keplr',
[WalletId.Keplr]: 'Keplr',
[WalletId.Leap]: 'Leap',
[WalletId.TerraStation]: 'Terra Station',
[WalletId.TerraWalletConnect]: 'Terra WalletConnect',
[WalletId.CosmosEvmMetamask]: 'Metamask',
[WalletId.Phantom]: 'Phantom',
};
return lookups[walletId];
};

const getAddressFromWallet = (wallet: IWebWallet<any>) => {
const selectedAddress = (() => {
if (wallet.chain === 'ethereum' || wallet.chain === 'solana') {
Expand Down Expand Up @@ -63,4 +31,4 @@ const getAddressFromWallet = (wallet: IWebWallet<any>) => {
return selectedAddress;
};

export { getAddressFromWallet, getWalletName };
export { getAddressFromWallet };
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useCallback } from 'react';
import { useCallback, useState } from 'react';

const useForceRerender = () => {
const [, setState] = useState({});
Expand Down
63 changes: 0 additions & 63 deletions packages/commonwealth/client/scripts/stores/ActivityStore.ts

This file was deleted.

Loading