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

refactor: utils module #4820

Merged
merged 12 commits into from Oct 20, 2022
4 changes: 2 additions & 2 deletions packages/mobile/routes/login/views/EnterPinView.svelte
Expand Up @@ -6,7 +6,7 @@
import { loginRouter } from '../../../lib/core/router'
import { Platform } from '@lib/platform'
import { openPopup, popupState } from '@auxiliary/popup'
import { validatePinFormat } from '@lib/utils'
import { isValidPin } from '@core/utils'
import { Icon, PinInput, Profile, Text, TextType } from 'shared/components'
import { onDestroy } from 'svelte'

Expand Down Expand Up @@ -34,7 +34,7 @@

$: hasReachedMaxAttempts = attempts >= MAX_PINCODE_INCORRECT_ATTEMPTS
$: {
if (validatePinFormat(pinCode)) {
if (isValidPin(pinCode)) {
void onSubmitClick()
}
}
Expand Down
Expand Up @@ -11,14 +11,10 @@
import { localize } from '@core/i18n'
import { pollLedgerNanoStatus, stopPollingLedgerNanoStatus } from '@core/ledger'
import { ProfileType } from '@core/profile'
import { storageProtectionSetupRouter } from '../../../../../lib/core/router'
import { validatePinFormat } from '@lib/utils'
import { isValidPin } from '@core/utils'
import { onMount } from 'svelte'

export let busy = false

const title = localize('views.onboarding.storageProtectionSetup.setupPinProtection.title')

let setPinInput = ''
let setPinInputError = ''
let confirmPinInput = ''
Expand All @@ -31,7 +27,7 @@
$: setPinInput, (setPinInputError = '')
$: confirmPinInput, (confirmPinInputError = '')
$: arePinInputsMatching = setPinInput === confirmPinInput
$: arePinInputsValid = validatePinFormat(setPinInput) && validatePinFormat(confirmPinInput)
$: arePinInputsValid = isValidPin(setPinInput) && isValidPin(confirmPinInput)
$: if (arePinInputsValid && !arePinInputsMatching) {
confirmPinInputError = localize('error.pincode.match')
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/components/Button.svelte
Expand Up @@ -2,7 +2,7 @@
import { ButtonSize, ButtonVariant, HTMLButtonType, Icon, Spinner } from 'shared/components'
import { onMount } from 'svelte'
import { appSettings } from '@core/app'
import { bindEvents, debounce } from '@lib/utils'
import { bindEvents, debounce } from '@core/utils'
import { Icon as IconEnum } from '@lib/auxiliary/icon'
import type { Event } from '@lib/typings/events'

Expand Down
2 changes: 1 addition & 1 deletion packages/shared/components/CopyButton.svelte
@@ -1,5 +1,5 @@
<script lang="typescript">
import { setClipboard } from 'shared/lib/utils'
import { setClipboard } from '@core/utils'
import { Icon } from 'shared/components'

export let itemToCopy: string
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/components/Idle.svelte
@@ -1,6 +1,6 @@
<script lang="typescript">
import { activeProfile, logout } from '@core/profile'
import { debounce } from 'shared/lib/utils'
import { debounce } from '@core/utils'
import { onDestroy } from 'svelte'
import { get } from 'svelte/store'
import { MILLISECONDS_PER_SECOND, SECONDS_PER_MINUTE } from 'shared/lib/time'
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/components/Link.svelte
@@ -1,6 +1,6 @@
<script lang="typescript">
import { Icon } from 'shared/components'
import { bindEvents } from 'shared/lib/utils'
import { bindEvents } from '@core/utils'

export let events = []
export let href = undefined
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/components/atoms/boxes/CopyableBox.svelte
@@ -1,5 +1,5 @@
<script lang="typescript">
import { setClipboard } from 'shared/lib/utils'
import { setClipboard } from '@core/utils'
import Box from './Box.svelte'
import { Text, Tooltip, FontWeight } from 'shared/components'
import { localize } from '@core/i18n'
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/components/filters/Filter.svelte
@@ -1,7 +1,7 @@
<script lang="typescript">
import { TogglableButton, FilterModal, FilterItem, Modal } from 'shared/components'
import type { Filter } from '@core/wallet/interfaces/filter/filter.interface'
import { deepCopy } from '@lib/utils'
import { deepCopy } from '@core/utils'
import type { Writable } from 'svelte/store'

export let filterStore: Writable<Filter>
Expand Down
7 changes: 3 additions & 4 deletions packages/shared/components/inputs/Dropdown.svelte
Expand Up @@ -2,8 +2,7 @@
import { FontWeight, Icon, Text, TextPropTypes, TextType, Error } from 'shared/components'
import { clickOutside } from 'shared/lib/actions'
import { onMount } from 'svelte'
import { isNumberLetterOrPunctuation } from '@lib/utils/isNumberLetterOrPunctuation'
import { DropdownChoice } from '@core/utils'
import { DropdownChoice, isNumberLetterOrPunctuation } from '@core/utils'

export let value: string
export let label: string = ''
Expand Down Expand Up @@ -174,15 +173,15 @@
{/if}
<nav
class:active={dropdown}
class="absolute w-full overflow-hidden pointer-events-none opacity-0 z-10 text-left
class="absolute w-full overflow-hidden pointer-events-none opacity-0 z-10 text-left
bg-white dark:bg-gray-800
border border-solid border-blue-500 border-t-gray-500 dark:border-t-gray-700"
>
<div class="inner overflow-y-auto" bind:this={navContainer}>
{#each items as item}
<button
class="relative flex items-center p-4 w-full whitespace-nowrap
{item[valueKey] === value && 'bg-gray-100 dark:bg-gray-700 dark:bg-opacity-20'}
{item[valueKey] === value && 'bg-gray-100 dark:bg-gray-700 dark:bg-opacity-20'}
hover:bg-gray-100 dark:hover:bg-gray-700 dark:hover:bg-opacity-20
focus:bg-gray-200 dark:focus:bg-gray-600 dark:focus:bg-opacity-20"
id={item[valueKey]}
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/components/inputs/Dropdown2.svelte
Expand Up @@ -2,7 +2,7 @@
import { onMount } from 'svelte'
import { Icon, Text, Error, DropdownItem } from 'shared/components'
import { clickOutside } from 'shared/lib/actions'
import { isNumberLetterOrPunctuation } from '@lib/utils/isNumberLetterOrPunctuation'
import { isNumberLetterOrPunctuation } from '@core/utils'

export let value: string
export let label: string = ''
Expand Down Expand Up @@ -142,7 +142,7 @@
>
<div
class="selection relative flex flex-row space-x-0 pl-1 pb-1.5 items-end w-full whitespace-nowrap
bg-white dark:bg-gray-800
bg-white dark:bg-gray-800
{hasFocus ? '-mr-1 pr-1' : 'pr-0'}
{items.length > 1 ? 'cursor-pointer' : ''}
{dropdown
Expand Down Expand Up @@ -172,15 +172,15 @@
{/if}
<nav
class:active={dropdown}
class="absolute w-full overflow-hidden pointer-events-none opacity-0 z-10 text-left
class="absolute w-full overflow-hidden pointer-events-none opacity-0 z-10 text-left
bg-white dark:bg-gray-800
border border-solid border-blue-500 border-t-gray-500 dark:border-t-gray-700"
>
<div class="flex flex-col items-center inner overflow-y-auto" bind:this={navContainer}>
{#each items as item}
<button
class="relative flex items-center p-2 pl-1 w-full whitespace-nowrap
{item[valueKey] === value && 'bg-gray-100 dark:bg-gray-700 dark:bg-opacity-20'}
{item[valueKey] === value && 'bg-gray-100 dark:bg-gray-700 dark:bg-opacity-20'}
hover:bg-gray-100 dark:hover:bg-gray-700 dark:hover:bg-opacity-20
focus:bg-gray-200 dark:focus:bg-gray-600 dark:focus:bg-opacity-20"
id={item[valueKey]}
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/components/inputs/ImportTextfield.svelte
Expand Up @@ -3,8 +3,8 @@
import { english } from '@auxiliary/wordlists'
import { localize } from '@core/i18n'
import { verifyMnemonic } from '@core/profile-manager'
import { debounce } from '@lib/utils'
import { Mnemonic } from '../../lib/contexts/onboarding'
import { debounce } from '@core/utils'
import { Mnemonic } from '@contexts/onboarding'

enum Type {
Seed = 'seed',
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/components/inputs/PinInput.svelte
Expand Up @@ -2,7 +2,7 @@
import { Error, Icon, Text } from 'shared/components'
import { createEventDispatcher, onMount } from 'svelte'
import { mobile, PlatformOption, platform } from '@core/app'
import { validatePinFormat, PIN_LENGTH } from '@lib/utils'
import { isValidPin, PIN_LENGTH } from '@core/utils'

const dispatch = createEventDispatcher()
const isAndroid = $platform === PlatformOption.Android
Expand Down Expand Up @@ -82,7 +82,7 @@
if (event.key === KEYBOARD.BACKSPACE) {
handleBackspace()
} else if (event.key === KEYBOARD.ENTER) {
if (validatePinFormat(inputs.join(''))) {
if (isValidPin(inputs.join(''))) {
dispatch('submit')
}
} else if (event.key === KEYBOARD.TAB) {
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/components/inputs/RecipientInput.svelte
Expand Up @@ -3,7 +3,7 @@
import { localize } from '@core/i18n'
import { networkHrp } from '@core/network'
import { Subject } from '@core/wallet'
import { ADDRESS_LENGTH, validateBech32Address } from '@lib/utils'
import { BECH32_ADDRESS_LENGTH, validateBech32Address } from '@core/utils'
import { Modal, RecipientAccountSelector, SelectorInput } from 'shared/components'

export let recipient: Subject
Expand Down Expand Up @@ -46,10 +46,10 @@
return Promise.resolve()
}

if (value.length !== ADDRESS_LENGTH + addressPrefix.length) {
if (value.length !== BECH32_ADDRESS_LENGTH + addressPrefix.length) {
error = localize('error.send.addressLength', {
values: {
length: ADDRESS_LENGTH + addressPrefix.length,
length: BECH32_ADDRESS_LENGTH + addressPrefix.length,
},
})
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/components/molecules/NftDetails.svelte
Expand Up @@ -23,7 +23,7 @@
import { getOfficialExplorerUrl } from '@core/network/utils'
import { Platform } from 'shared/lib/platform'
import { truncateString } from '@lib/helpers'
import { setClipboard } from '@lib/utils'
import { setClipboard } from '@core/utils'
import { time } from '@core/app'

export let metadata: INftMetadata
Expand Down
Expand Up @@ -23,7 +23,7 @@
import { getOfficialExplorerUrl } from '@core/network/utils'
import { Platform } from 'shared/lib/platform'
import { truncateString } from '@lib/helpers'
import { setClipboard } from '@lib/utils'
import { setClipboard } from '@core/utils'
import { time } from '@core/app'

export let asset: IPersistedAsset
Expand Down
3 changes: 1 addition & 2 deletions packages/shared/components/organisms/AccountActivity.svelte
Expand Up @@ -10,9 +10,8 @@
} from '@core/wallet'
import { ActivityTile, Text, TextInput, TogglableButton, Filter, FontWeight } from 'shared/components'
import features from 'shared/features/features'
import { debounce } from 'shared/lib/utils'
import { debounce, getMonthYear } from '@core/utils'
import VirtualList from '@sveltejs/svelte-virtual-list'
import { getMonthYear } from '@lib/utils'

let searchActive = false
let inputElement: HTMLInputElement
Expand Down
Expand Up @@ -16,7 +16,7 @@
import { activeProfile, checkActiveProfileAuth } from '@core/profile'
import { currencies, exchangeRates } from '@lib/currency'
import { CurrencyTypes } from 'shared/lib/typings/currency'
import { setClipboard } from '@lib/utils'
import { setClipboard } from '@core/utils'
import { truncateString } from '@lib/helpers'
import { closePopup, openPopup } from '@auxiliary/popup'
import { onMount } from 'svelte'
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/components/popups/Diagnostics.svelte
Expand Up @@ -4,7 +4,7 @@
import { activeProfile } from '@core/profile'
import { Button, Text } from 'shared/components'
import { Platform } from 'shared/lib/platform'
import { setClipboard } from 'shared/lib/utils'
import { setClipboard } from '@core/utils'
import { onMount } from 'svelte'

const { loggedIn } = $activeProfile ?? {}
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/components/popups/ErrorLog.svelte
Expand Up @@ -3,7 +3,7 @@
import { errorLog } from '@core/error'
import { localize } from '@core/i18n'
import { closePopup } from '@auxiliary/popup'
import { setClipboard } from '@lib/utils'
import { setClipboard } from '@core/utils'

function handleClearClick(): () => void {
errorLog.set([])
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/components/popups/NodeInfoPopup.svelte
Expand Up @@ -5,7 +5,7 @@
import { INode, INodeInfo } from '@core/network'
import { closePopup } from '@auxiliary/popup'
import { showAppNotification } from '@auxiliary/notification'
import { resolveObjectPath, setClipboard } from 'shared/lib/utils'
import { resolveObjectPath, setClipboard } from '@core/utils'
import { getNodeInfo } from '@core/profile-manager'

enum NodeInfoTab {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/components/popups/SendFormPopup.svelte
Expand Up @@ -4,7 +4,7 @@
import { newTransactionDetails, updateNewTransactionDetails } from '@core/wallet'
import { Button, Text, RecipientInput, AssetAmountInput, OptionalInput, FontWeight } from 'shared/components'
import { closePopup, openPopup } from '@auxiliary/popup'
import { getByteLengthOfString } from '@lib/utils/getByteLengthOfString'
import { getByteLengthOfString } from '@core/utils'

let { asset, rawAmount, unit, recipient, metadata, tag } = get(newTransactionDetails)
let assetAmountInput: AssetAmountInput
Expand Down
@@ -1,5 +1,7 @@
import { get } from 'svelte/store'

import { networkHrp } from '@core/network'
import { isStringTrue, getByteLengthOfString } from '@core/utils'
import {
getAssetById,
INewTransactionDetails,
Expand All @@ -20,8 +22,6 @@ import {
UnknownAssetError,
} from '../../../errors'
import { getRawAmountFromSearchParam } from '../../../utils'
import { getByteLengthOfString } from '@lib/utils/getByteLengthOfString'
import { isStringTrue } from '@core/utils'

export function handleDeepLinkSendConfirmationOperation(searchParams: URLSearchParams): void {
const transactionDetails = parseSendConfirmationOperation(searchParams)
Expand Down
@@ -1,7 +1,7 @@
import { get } from 'svelte/store'

import { appSettings } from '@core/app'
import { generateRandomId } from '@lib/utils'
import { generateRandomId } from '@core/utils'
import { Platform } from '@lib/platform'

import { DEFAULT_NOTIFICATION_TIMEOUT, NOTIFICATION_TIMEOUT_NEVER } from '../constants'
Expand Down
Expand Up @@ -3,7 +3,7 @@ import { get } from 'svelte/store'
import { Platform } from '@lib/platform'
import { InvalidBackupDestinationError } from '@core/profile'
import { backup } from '@core/profile-manager'
import { getDefaultStrongholdName } from '@lib/utils'
import { getDefaultStrongholdName } from '@core/stronghold'

import { onboardingProfile, updateOnboardingProfile } from '../stores'

Expand Down
Expand Up @@ -2,7 +2,7 @@ import { get } from 'svelte/store'

import { COIN_TYPE, NetworkProtocol } from '@core/network'
import { getSecretManagerFromProfileType, initialiseProfileManager } from '@core/profile-manager'
import { generateRandomId } from '@lib/utils'
import { generateRandomId } from '@core/utils'

import { getShimmerClaimingProfileManagerStorageDirectory } from '../helpers'
import { shimmerClaimingProfileManager, onboardingProfile } from '../stores'
Expand Down
@@ -1,5 +1,5 @@
import { NetworkProtocol } from '@core/network'
import { generateRandomId } from '@lib/utils'
import { generateRandomId } from '@core/utils'

import { IOnboardingProfile } from '../interfaces'

Expand Down
@@ -1,7 +1,7 @@
import { updateActiveProfile } from '@core/profile'
import { backup } from '@core/profile-manager'
import { Platform } from '@lib/platform'
import { getDefaultStrongholdName } from '@lib/utils'
import { getDefaultStrongholdName } from '@core/stronghold'

export async function exportStronghold(
password: string,
Expand Down
@@ -1,7 +1,6 @@
import { get, writable } from 'svelte/store'
import { updateActiveAccount } from '@core/profile'
import { IAccountState } from '../interfaces'

import { updateActiveAccount } from '@core/profile/stores/active-accounts.store'
import type { IAccountState } from '../interfaces'
export const selectedAccount = writable<IAccountState>(null)

export function updateSelectedAccount(payload: Partial<IAccountState>): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/lib/core/app/utils/shouldBeDarkMode.ts
@@ -1,4 +1,4 @@
import { AppTheme } from '@core/app'
import { AppTheme } from '../enums'

/**
* NOTE: This media query is performed only once to help make the UX
Expand Down
@@ -1,4 +1,4 @@
import { isValidHttpsUrl, isValidUrl } from '@lib/utils'
import { isValidHttpsUrl, isValidUrl } from '@core/utils'
import { INode } from '../interfaces'

/**
Expand Down
@@ -1,6 +1,6 @@
import { ClientOptions, CoinType, SecretManager } from '@iota/wallet'

import { generateRandomId } from '@lib/utils'
import { generateRandomId } from '@core/utils'

import { api } from '../api'
import { IProfileManager } from '../interfaces'
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/lib/core/profile-manager/tests/api.test.ts
Expand Up @@ -4,7 +4,7 @@ import { MOCK_MNEMONIC, ProfileManagerMock } from '@mocks/profile-manager.mock'

import { get } from 'svelte/store'

import { generateRandomId } from '@lib/utils'
import { generateRandomId } from '@core/utils'

import { destroyProfileManager } from '../actions'
import {
Expand Down
@@ -1,6 +1,6 @@
import { activeProfile, IPersistedProfile, updateActiveProfile } from '@core/profile'
import { DEFAULT_ACTIVE_PROFILE_VALUE } from '@core/profile/constants/default-active-profile-values.constant'
import { migrateObjects } from '@lib/utils'
import { migrateObjects } from '@core/utils'
import { get } from 'svelte/store'

// TODO: Fix this function does not seem to be migrating optional properties, at least on nested objects
Expand Down
@@ -1,4 +1,4 @@
import { IAccountState } from '@core/account'
import type { IAccountState } from '@core/account'
import { derived, Readable, writable } from 'svelte/store'
import { activeProfile } from './active-profile.store'

Expand Down