From 2f34b3adead08032bd3c4d1518d4cfeaa537af3b Mon Sep 17 00:00:00 2001 From: Aaron Barnard Date: Mon, 22 Aug 2022 14:16:18 +1000 Subject: [PATCH 1/2] Add js extension to relative imports --- packages/common/src/eip-1193.ts | 4 +-- packages/common/src/errors.ts | 2 +- packages/common/src/index.ts | 12 +++---- packages/core/src/chain.ts | 12 +++---- packages/core/src/configuration.ts | 4 +-- packages/core/src/connect.ts | 22 +++++++------ packages/core/src/constants.ts | 6 ++-- packages/core/src/disconnect.ts | 12 +++---- packages/core/src/i18n/index.ts | 2 +- packages/core/src/index.ts | 30 ++++++++--------- packages/core/src/notify.ts | 12 +++---- packages/core/src/preflight-notifications.ts | 14 ++++---- packages/core/src/provider.ts | 25 ++++++++------- packages/core/src/replacement.ts | 8 ++--- packages/core/src/services.ts | 4 +-- packages/core/src/store/actions.ts | 10 +++--- packages/core/src/store/index.ts | 8 ++--- packages/core/src/streams.ts | 6 ++-- packages/core/src/update-balances.ts | 6 ++-- packages/core/src/utils.ts | 32 +++++++++---------- packages/core/src/validation.ts | 2 +- packages/core/src/views/Index.svelte | 8 ++--- .../DisconnectAllConfirm.svelte | 2 +- .../src/views/account-center/Index.svelte | 4 +-- .../src/views/account-center/Maximized.svelte | 26 +++++++-------- .../src/views/account-center/Micro.svelte | 8 ++--- .../src/views/account-center/Minimized.svelte | 16 +++++----- .../src/views/account-center/WalletRow.svelte | 14 ++++---- .../core/src/views/chain/SwitchChain.svelte | 4 +-- .../src/views/connect/ActionRequired.svelte | 2 +- .../core/src/views/connect/Agreement.svelte | 4 +-- .../src/views/connect/ConnectedWallet.svelte | 8 ++--- .../src/views/connect/ConnectingWallet.svelte | 6 ++-- packages/core/src/views/connect/Index.svelte | 18 +++++------ .../src/views/connect/InstallWallet.svelte | 2 +- .../src/views/connect/SelectingWallet.svelte | 4 +-- .../core/src/views/connect/Sidebar.svelte | 8 ++--- packages/core/src/views/notify/Index.svelte | 6 ++-- .../core/src/views/notify/Notification.svelte | 14 ++++---- .../views/notify/NotificationContent.svelte | 4 +-- .../src/views/notify/StatusIconBadge.svelte | 4 +-- .../core/src/views/shared/CloseButton.svelte | 2 +- .../core/src/views/shared/InfoIcon.svelte | 2 +- packages/core/src/views/shared/Modal.svelte | 2 +- .../src/views/shared/NetworkSelector.svelte | 8 ++--- .../src/views/shared/PendingStatusIcon.svelte | 2 +- .../src/views/shared/SuccessStatusIcon.svelte | 2 +- .../src/views/shared/WalletAppBadge.svelte | 2 +- packages/core/src/views/shared/Warning.svelte | 2 +- packages/demo/src/App.svelte | 4 +-- packages/gas/src/get.ts | 6 ++-- packages/gas/src/index.ts | 6 ++-- packages/gas/src/stream.ts | 6 ++-- packages/gas/src/utils.ts | 2 +- packages/gas/src/validation.ts | 2 +- packages/hw-common/src/account-select.ts | 6 ++-- .../src/elements/AddressTable.svelte | 2 +- .../hw-common/src/elements/CloseButton.svelte | 2 +- packages/hw-common/src/hdwallets.ts | 2 +- packages/hw-common/src/index.ts | 8 ++--- packages/hw-common/src/streams.ts | 2 +- packages/hw-common/src/validation.ts | 2 +- .../hw-common/src/views/AccountSelect.svelte | 2 +- .../magic/src/elements/CloseButton.svelte | 2 +- packages/magic/src/index.ts | 4 +-- packages/magic/src/login-modal.ts | 4 +-- packages/magic/src/validation.ts | 2 +- packages/magic/src/view/LoginModal.svelte | 4 +-- packages/react/src/hooks/index.ts | 14 ++++---- packages/react/src/hooks/useAccountCenter.ts | 2 +- packages/react/src/hooks/useAppState.ts | 2 +- packages/react/src/hooks/useConnectWallet.ts | 4 +-- packages/react/src/hooks/useNotifications.ts | 4 +-- packages/react/src/hooks/useSetChain.ts | 4 +-- packages/react/src/hooks/useSetLocale.ts | 2 +- packages/react/src/hooks/useWallets.ts | 2 +- packages/react/src/index.ts | 9 ++++-- packages/vue/src/index.ts | 2 +- 78 files changed, 268 insertions(+), 262 deletions(-) diff --git a/packages/common/src/eip-1193.ts b/packages/common/src/eip-1193.ts index 656db7004..1ec3c2652 100644 --- a/packages/common/src/eip-1193.ts +++ b/packages/common/src/eip-1193.ts @@ -4,8 +4,8 @@ import type { ChainId, EIP1193Provider, ProviderAccounts -} from './types' -import { ProviderRpcError } from './errors' +} from './types.js' +import { ProviderRpcError } from './errors.js' /** * Takes a provider instance along with events diff --git a/packages/common/src/errors.ts b/packages/common/src/errors.ts index d96974cfc..9641c7d81 100644 --- a/packages/common/src/errors.ts +++ b/packages/common/src/errors.ts @@ -1,4 +1,4 @@ -import type { ProviderRpcErrorCode } from './types' +import type { ProviderRpcErrorCode } from './types.js' export class ProviderRpcError extends Error { message: string diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index 493c2f079..c11b70c68 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -1,7 +1,7 @@ -export { ProviderRpcError } from './errors' -export { createEIP1193Provider } from './eip-1193' -export { SofiaProLight, SofiaProRegular, SofiaProSemiBold } from './fonts' -export { weiToEth } from './utils' +export { ProviderRpcError } from './errors.js' +export { createEIP1193Provider } from './eip-1193.js' +export { SofiaProLight, SofiaProRegular, SofiaProSemiBold } from './fonts.js' +export { weiToEth } from './utils.js' -export * from './types' -export * from './validation' +export * from './types.js' +export * from './validation.js' diff --git a/packages/core/src/chain.ts b/packages/core/src/chain.ts index 6efd9175b..da26b849d 100644 --- a/packages/core/src/chain.ts +++ b/packages/core/src/chain.ts @@ -1,12 +1,12 @@ import { firstValueFrom } from 'rxjs' import { filter, map } from 'rxjs/operators' import { ProviderRpcErrorCode } from '@web3-onboard/common' -import { addNewChain, switchChain } from './provider' -import { state } from './store' -import { switchChainModal$ } from './streams' -import { validateSetChainOptions } from './validation' -import type { WalletState } from './types' -import { toHexString } from './utils' +import { addNewChain, switchChain } from './provider.js' +import { state } from './store/index.js' +import { switchChainModal$ } from './streams.js' +import { validateSetChainOptions } from './validation.js' +import type { WalletState } from './types.js' +import { toHexString } from './utils.js' async function setChain(options: { chainId: string | number diff --git a/packages/core/src/configuration.ts b/packages/core/src/configuration.ts index f274c4ed8..8f7f8d294 100644 --- a/packages/core/src/configuration.ts +++ b/packages/core/src/configuration.ts @@ -1,5 +1,5 @@ -import type { Configuration } from './types' -import { getDevice } from './utils' +import type { Configuration } from './types.js' +import { getDevice } from './utils.js' export let configuration: Configuration = { svelteInstance: null, diff --git a/packages/core/src/connect.ts b/packages/core/src/connect.ts index 2cda51c65..f7d08f9de 100644 --- a/packages/core/src/connect.ts +++ b/packages/core/src/connect.ts @@ -1,12 +1,16 @@ import { firstValueFrom } from 'rxjs' import { filter, withLatestFrom, pluck } from 'rxjs/operators' -import { configuration } from './configuration' -import { state } from './store' -import { setWalletModules } from './store/actions' -import { connectWallet$, wallets$ } from './streams' -import type { ConnectOptions, ConnectOptionsString, WalletState } from './types' -import { wait } from './utils' -import { validateConnectOptions } from './validation' +import { configuration } from './configuration.js' +import { state } from './store/index.js' +import { setWalletModules } from './store/actions.js' +import { connectWallet$, wallets$ } from './streams.js' +import type { + ConnectOptions, + ConnectOptionsString, + WalletState +} from './types.js' +import { wait } from './utils.js' +import { validateConnectOptions } from './validation.js' async function connect( options?: ConnectOptions | ConnectOptionsString @@ -25,8 +29,8 @@ async function connect( if (!chains.length) throw new Error( 'At least one chain must be set before attempting to connect a wallet' - ) - + ) + const { autoSelect } = options || { autoSelect: { label: '', disableModals: false } } diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index d11b49da4..609427b6e 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -1,5 +1,5 @@ -import { configuration } from './configuration' -import type { AppState } from './types' +import { configuration } from './configuration.js' +import type { AppState } from './types.js' export const APP_INITIAL_STATE: AppState = { wallets: [], @@ -25,7 +25,7 @@ export const APP_INITIAL_STATE: AppState = { }, notifications: [], locale: '', - connect : { + connect: { showSidebar: true } } diff --git a/packages/core/src/disconnect.ts b/packages/core/src/disconnect.ts index 618cd3c54..0248f4e61 100644 --- a/packages/core/src/disconnect.ts +++ b/packages/core/src/disconnect.ts @@ -1,9 +1,9 @@ -import { getBlocknativeSdk } from './services' -import { state } from './store' -import { removeWallet } from './store/actions' -import { disconnectWallet$ } from './streams' -import type { DisconnectOptions, WalletState } from './types' -import { validateDisconnectOptions } from './validation' +import { getBlocknativeSdk } from './services.js' +import { state } from './store/index.js' +import { removeWallet } from './store/actions.js' +import { disconnectWallet$ } from './streams.js' +import type { DisconnectOptions, WalletState } from './types.js' +import { validateDisconnectOptions } from './validation.js' async function disconnect(options: DisconnectOptions): Promise { const error = validateDisconnectOptions(options) diff --git a/packages/core/src/i18n/index.ts b/packages/core/src/i18n/index.ts index 06193e7a7..db5b473f9 100644 --- a/packages/core/src/i18n/index.ts +++ b/packages/core/src/i18n/index.ts @@ -1,7 +1,7 @@ import { addMessages, init, getLocaleFromNavigator } from 'svelte-i18n' import merge from 'lodash.merge' import en from './en.json' -import type { i18nOptions } from '../types' +import type { i18nOptions } from '../types.js' function initialize(options?: i18nOptions): void { if (options) { diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 1c021d3d8..2ddfecfb8 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,23 +1,23 @@ import { SofiaProRegular } from '@web3-onboard/common' -import connectWallet from './connect' -import disconnectWallet from './disconnect' -import setChain from './chain' -import { state } from './store' -import { reset$ } from './streams' -import initI18N from './i18n' +import connectWallet from './connect.js' +import disconnectWallet from './disconnect.js' +import setChain from './chain.js' +import { state } from './store/index.js' +import { reset$ } from './streams.js' +import initI18N from './i18n/index.js' import App from './views/Index.svelte' -import type { InitOptions, Notify } from './types' -import { APP_INITIAL_STATE } from './constants' -import { configuration, updateConfiguration } from './configuration' -import updateBalances from './update-balances' -import { chainIdToHex } from './utils' -import { preflightNotifications } from './preflight-notifications' +import type { InitOptions, Notify } from './types.js' +import { APP_INITIAL_STATE } from './constants.js' +import { configuration, updateConfiguration } from './configuration.js' +import updateBalances from './update-balances.js' +import { chainIdToHex } from './utils.js' +import { preflightNotifications } from './preflight-notifications.js' import { validateInitOptions, validateNotify, validateNotifyOptions -} from './validation' +} from './validation.js' import { addChains, @@ -28,7 +28,7 @@ import { setPrimaryWallet, setWalletModules, updateConnectModal -} from './store/actions' +} from './store/actions.js' const API = { connectWallet, @@ -65,7 +65,7 @@ export type { Notify, UpdateNotification, PreflightNotificationsOptions -} from './types' +} from './types.js' export type { EIP1193Provider } from '@web3-onboard/common' diff --git a/packages/core/src/notify.ts b/packages/core/src/notify.ts index 29d4b9be9..46401494d 100644 --- a/packages/core/src/notify.ts +++ b/packages/core/src/notify.ts @@ -8,13 +8,13 @@ import type { CustomNotification, Notification, NotificationType -} from './types' +} from './types.js' -import { validateTransactionHandlerReturn } from './validation' -import { state } from './store' -import { addNotification } from './store/actions' -import updateBalances from './update-balances' -import { updateTransaction } from './streams' +import { validateTransactionHandlerReturn } from './validation.js' +import { state } from './store/index.js' +import { addNotification } from './store/actions.js' +import updateBalances from './update-balances.js' +import { updateTransaction } from './streams.js' export function handleTransactionUpdates( transaction: EthereumTransactionData diff --git a/packages/core/src/preflight-notifications.ts b/packages/core/src/preflight-notifications.ts index 3fc6f59d6..3b418d58d 100644 --- a/packages/core/src/preflight-notifications.ts +++ b/packages/core/src/preflight-notifications.ts @@ -3,12 +3,12 @@ import { nanoid } from 'nanoid' import defaultCopy from './i18n/en.json' import type { Network } from 'bnc-sdk' -import type { Notification, PreflightNotificationsOptions } from './types' -import { addNotification, removeNotification } from './store/actions' -import { state } from './store' -import { eventToType } from './notify' -import { networkToChainId } from './utils' -import { validatePreflightNotifications } from './validation' +import type { Notification, PreflightNotificationsOptions } from './types.js' +import { addNotification, removeNotification } from './store/actions.js' +import { state } from './store/index.js' +import { eventToType } from './notify.js' +import { networkToChainId } from './utils.js' +import { validatePreflightNotifications } from './validation.js' let notificationsArr: Notification[] state.select('notifications').subscribe(notifications => { @@ -18,8 +18,6 @@ state.select('notifications').subscribe(notifications => { export async function preflightNotifications( options: PreflightNotificationsOptions ): Promise { - - const invalid = validatePreflightNotifications(options) if (invalid) { diff --git a/packages/core/src/provider.ts b/packages/core/src/provider.ts index 05f4acf2d..21262163f 100644 --- a/packages/core/src/provider.ts +++ b/packages/core/src/provider.ts @@ -15,13 +15,13 @@ import type { } from '@web3-onboard/common' import { weiToEth } from '@web3-onboard/common' -import { disconnectWallet$ } from './streams' -import type { Account, Address, Balances, Ens, WalletState } from './types' -import { updateAccount, updateWallet } from './store/actions' -import { validEnsChain } from './utils' -import disconnect from './disconnect' -import { state } from './store' -import { getBlocknativeSdk } from './services' +import { disconnectWallet$ } from './streams.js' +import type { Account, Address, Balances, Ens, WalletState } from './types.js' +import { updateAccount, updateWallet } from './store/actions.js' +import { validEnsChain } from './utils.js' +import disconnect from './disconnect.js' +import { state } from './store/index.js' +import { getBlocknativeSdk } from './services.js' export const ethersProviders: { [key: string]: providers.StaticJsonRpcProvider @@ -340,16 +340,17 @@ export async function getBalance( ): Promise { // chain we don't recognize and don't have a rpcUrl for requests if (!chain) return null - + const { wallets } = state.get() try { const wallet = wallets.find(wallet => !!wallet.provider) const provider = wallet.provider - const balanceHex = await provider.request({ method: 'eth_getBalance', params:[address,'latest'] }) - return balanceHex - ? { [chain.token || 'eth']: weiToEth(balanceHex) } - : null + const balanceHex = await provider.request({ + method: 'eth_getBalance', + params: [address, 'latest'] + }) + return balanceHex ? { [chain.token || 'eth']: weiToEth(balanceHex) } : null } catch (error) { console.error(error) return null diff --git a/packages/core/src/replacement.ts b/packages/core/src/replacement.ts index b5579f289..4f4d1a3d1 100644 --- a/packages/core/src/replacement.ts +++ b/packages/core/src/replacement.ts @@ -1,9 +1,9 @@ import type { EthereumTransactionData, Network } from 'bnc-sdk' import { BigNumber } from 'ethers' -import { configuration } from './configuration' -import { state } from './store' -import type { WalletState } from './types' -import { gweiToWeiHex, networkToChainId, toHexString } from './utils' +import { configuration } from './configuration.js' +import { state } from './store/index.js' +import type { WalletState } from './types.js' +import { gweiToWeiHex, networkToChainId, toHexString } from './utils.js' const ACTIONABLE_EVENT_CODES: string[] = ['txPool'] const VALID_GAS_NETWORKS: Network[] = ['main', 'matic-main'] diff --git a/packages/core/src/services.ts b/packages/core/src/services.ts index 05f7a8ac8..14b065b0d 100644 --- a/packages/core/src/services.ts +++ b/packages/core/src/services.ts @@ -1,6 +1,6 @@ import type { MultiChain } from 'bnc-sdk' -import { configuration } from './configuration' -import { handleTransactionUpdates } from './notify' +import { configuration } from './configuration.js' +import { handleTransactionUpdates } from './notify.js' let blocknativeSdk: MultiChain diff --git a/packages/core/src/store/actions.ts b/packages/core/src/store/actions.ts index b664685f0..ae0e899dd 100644 --- a/packages/core/src/store/actions.ts +++ b/packages/core/src/store/actions.ts @@ -1,7 +1,7 @@ import type { Chain, WalletInit, WalletModule } from '@web3-onboard/common' import { nanoid } from 'nanoid' -import { dispatch } from './index' -import { configuration } from '../configuration' +import { dispatch } from './index.js' +import { configuration } from '../configuration.js' import type { Account, @@ -27,7 +27,7 @@ import type { Notify, ConnectModalOptions, UpdateConnectModalAction -} from '../types' +} from '../types.js' import { validateAccountCenterUpdate, @@ -41,7 +41,7 @@ import { validateUpdateBalances, validateNotify, validateConnectModalUpdate -} from '../validation' +} from '../validation.js' import { ADD_CHAINS, @@ -58,7 +58,7 @@ import { REMOVE_NOTIFICATION, UPDATE_ALL_WALLETS, UPDATE_CONNECT_MODAL -} from './constants' +} from './constants.js' export function addChains(chains: Chain[]): void { // chains are validated on init diff --git a/packages/core/src/store/index.ts b/packages/core/src/store/index.ts index 66c98aaef..ce5e6d5a0 100644 --- a/packages/core/src/store/index.ts +++ b/packages/core/src/store/index.ts @@ -1,8 +1,8 @@ import { BehaviorSubject, Subject, Observable } from 'rxjs' import { distinctUntilKeyChanged, pluck, filter } from 'rxjs/operators' import { locale } from 'svelte-i18n' -import { APP_INITIAL_STATE } from '../constants' -import { notNullish } from '../utils' +import { APP_INITIAL_STATE } from '../constants.js' +import { notNullish } from '../utils.js' import type { Chain, WalletModule } from '@web3-onboard/common' import type { @@ -19,7 +19,7 @@ import type { RemoveNotificationAction, UpdateAllWalletsAction, UpdateConnectModalAction -} from '../types' +} from '../types.js' import { ADD_CHAINS, @@ -36,7 +36,7 @@ import { ADD_NOTIFICATION, REMOVE_NOTIFICATION, UPDATE_ALL_WALLETS -} from './constants' +} from './constants.js' function reducer(state: AppState, action: Action): AppState { const { type, payload } = action diff --git a/packages/core/src/streams.ts b/packages/core/src/streams.ts index 364ad4dfa..7fc43acc1 100644 --- a/packages/core/src/streams.ts +++ b/packages/core/src/streams.ts @@ -9,10 +9,10 @@ import { shareReplay } from 'rxjs/operators' -import { resetStore } from './store/actions' -import { state } from './store' +import { resetStore } from './store/actions.js' +import { state } from './store/index.js' -import type { WalletState, ConnectOptions } from './types' +import type { WalletState, ConnectOptions } from './types.js' import type { EthereumTransactionData } from 'bnc-sdk' export const reset$ = new Subject() diff --git a/packages/core/src/update-balances.ts b/packages/core/src/update-balances.ts index d93a95a8b..6433455e3 100644 --- a/packages/core/src/update-balances.ts +++ b/packages/core/src/update-balances.ts @@ -1,6 +1,6 @@ -import { state } from './store' -import { getBalance } from './provider' -import { updateAllWallets } from './store/actions' +import { state } from './store/index.js' +import { getBalance } from './provider.js' +import { updateAllWallets } from './store/actions.js' async function updateBalances(addresses?: string[]): Promise { const { wallets, chains } = state.get() diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index 9efc3da02..537e4591c 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -12,29 +12,29 @@ import type { ChainWithDecimalId } from '@web3-onboard/common' -import ethereumIcon from './icons/ethereum' -import polygonIcon from './icons/polygon' -import questionIcon from './icons/question' -import binanceIcon from './icons/binance' -import fantomIcon from './icons/fantom' -import optimismIcon from './icons/optimism' -import avalancheIcon from './icons/avalanche' -import celoIcon from './icons/celo' -import gnosisIcon from './icons/gnosis' -import harmonyOneIcon from './icons/harmony-one' -import arbitrumIcon from './icons/arbitrum' +import ethereumIcon from './icons/ethereum.js' +import polygonIcon from './icons/polygon.js' +import questionIcon from './icons/question.js' +import binanceIcon from './icons/binance.js' +import fantomIcon from './icons/fantom.js' +import optimismIcon from './icons/optimism.js' +import avalancheIcon from './icons/avalanche.js' +import celoIcon from './icons/celo.js' +import gnosisIcon from './icons/gnosis.js' +import harmonyOneIcon from './icons/harmony-one.js' +import arbitrumIcon from './icons/arbitrum.js' -import hourglass from './icons/hourglass' -import checkmark from './icons/checkmark' -import error from './icons/error' -import info from './icons/info' +import hourglass from './icons/hourglass.js' +import checkmark from './icons/checkmark.js' +import error from './icons/error.js' +import info from './icons/info.js' import type { ChainStyle, ConnectedChain, DeviceNotBrowser, NotifyEventStyles -} from './types' +} from './types.js' export function getDevice(): Device | DeviceNotBrowser { if (typeof window !== 'undefined') { diff --git a/packages/core/src/validation.ts b/packages/core/src/validation.ts index 164f1ebc4..38ccd05c4 100644 --- a/packages/core/src/validation.ts +++ b/packages/core/src/validation.ts @@ -27,7 +27,7 @@ import type { Notify, PreflightNotificationsOptions, ConnectModalOptions -} from './types' +} from './types.js' const unknownObject = Joi.object().unknown() diff --git a/packages/core/src/views/Index.svelte b/packages/core/src/views/Index.svelte index 77bc4d4ec..2b6fdfa04 100644 --- a/packages/core/src/views/Index.svelte +++ b/packages/core/src/views/Index.svelte @@ -1,13 +1,13 @@ diff --git a/packages/core/src/views/shared/CloseButton.svelte b/packages/core/src/views/shared/CloseButton.svelte index 96db260ac..076aa58c8 100644 --- a/packages/core/src/views/shared/CloseButton.svelte +++ b/packages/core/src/views/shared/CloseButton.svelte @@ -1,5 +1,5 @@ diff --git a/packages/core/src/views/shared/Modal.svelte b/packages/core/src/views/shared/Modal.svelte index b03857789..96325388f 100644 --- a/packages/core/src/views/shared/Modal.svelte +++ b/packages/core/src/views/shared/Modal.svelte @@ -16,7 +16,7 @@