22 |
23 | export type DataPoint = {
24 | date: string
25 | worth: number
26 | }
27 |
28 | export const chartLengths = ['1d', '1w', '1m', '1y'] as const
29 |
30 | type ChartLengthType = typeof chartLengths
31 | export type ChartLength = ChartLengthType[number]
32 |
--------------------------------------------------------------------------------
/src/types/components.d.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | type LucideIconType = (props: LucideProps) => JSX.Element
20 |
21 | type FC = React.FC>
22 |
--------------------------------------------------------------------------------
/src/types/contacts.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | import { Optional } from '@alephium/web3'
20 |
21 | import { AddressHash } from '@/types/addresses'
22 |
23 | export type Contact = {
24 | id: string
25 | name: string
26 | address: AddressHash
27 | }
28 |
29 | export type ContactFormData = Optional
30 |
--------------------------------------------------------------------------------
/src/types/i18next.d.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | import 'i18next'
20 |
21 | import en from '../../locales/en-US/translation.json'
22 |
23 | type EnglishTranslationKeys = typeof en
24 |
25 | export type TranslationKey = keyof EnglishTranslationKeys
26 |
27 | declare module 'i18next' {
28 | interface CustomTypeOptions {
29 | resources: {
30 | translation: EnglishTranslationKeys
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/types/network.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | export type NetworkStatus = 'offline' | 'connecting' | 'online' | 'uninitialized'
20 |
21 | export enum NetworkNames {
22 | mainnet = 'mainnet',
23 | testnet = 'testnet',
24 | localhost = 'localhost',
25 | custom = 'custom'
26 | }
27 |
28 | export type NetworkName = keyof typeof NetworkNames
29 |
30 | export type NetworkPreset = Exclude
31 |
--------------------------------------------------------------------------------
/src/types/numbers.d.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | export type TimeInMs = number
20 |
21 | export type Coordinates = { x: number; y: number }
22 |
--------------------------------------------------------------------------------
/src/types/snackbar.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | export type Message = string
20 |
21 | export type OptionalMessage = Message | undefined
22 |
23 | export interface SnackbarMessage {
24 | text: Message
25 | type?: 'info' | 'alert' | 'success'
26 | duration?: number
27 | }
28 |
--------------------------------------------------------------------------------
/src/types/wallet.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | import { AddressKeyPair, Wallet } from '@alephium/sdk'
20 |
21 | import { AddressBase } from '@/types/addresses'
22 | import { TimeInMs } from '@/types/numbers'
23 |
24 | export type ActiveWallet = {
25 | id: string
26 | name: string
27 | mnemonic: string
28 | passphrase?: string
29 | }
30 |
31 | export type GeneratedWallet = {
32 | wallet: ActiveWallet & StoredWallet
33 | initialAddress: AddressBase
34 | }
35 |
36 | export type UnlockedWallet = {
37 | wallet: ActiveWallet
38 | initialAddress: AddressKeyPair
39 | }
40 |
41 | export type StoredWallet = {
42 | id: ActiveWallet['id']
43 | name: ActiveWallet['name']
44 | encrypted: string
45 | lastUsed: TimeInMs
46 | }
47 |
48 | export type UnencryptedWallet = Wallet & {
49 | name: ActiveWallet['name']
50 | }
51 |
--------------------------------------------------------------------------------
/src/types/window.d.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | import { Error, ProgressInfo, UpdateDownloadedEvent } from 'electron-updater'
20 |
21 | import { ThemeSettings } from './settings'
22 |
23 | interface NativeTheme {
24 | shouldUseDarkColors: boolean
25 | themeSource: string
26 | }
27 |
28 | export interface AlephiumWindow extends Window {
29 | electron?: {
30 | theme: {
31 | setNativeTheme: (theme: ThemeSettings) => void
32 | getNativeTheme: () => void
33 | onGetNativeTheme: (callback: (nativeTheme: NativeTheme) => void) => () => void
34 | onShouldUseDarkColors: (callback: (useDark: boolean) => void) => () => void
35 | }
36 | updater: {
37 | checkForUpdates: () => Promise
38 | startUpdateDownload: () => void
39 | onUpdateDownloadProgress: (callback: (info: ProgressInfo) => void) => () => void
40 | onUpdateDownloaded: (callback: (updateDownloadedEvent: UpdateDownloadedEvent) => void) => () => void
41 | quitAndInstallUpdate: () => void
42 | onError: (callback: (error: Error) => void) => () => void
43 | }
44 | walletConnect: {
45 | onConnect: (callback: (uri: string) => Promise) => () => void
46 | resetDeepLinkUri: () => void
47 | getDeepLinkUri: () => Promise
48 | }
49 | app: {
50 | hide: () => void
51 | show: () => void
52 | getSystemLanguage: () => Promise
53 | setProxySettings: (proxySettings: ProxySettings) => Promise
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/utils/app-data.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | export const KEY_APPMETADATA = 'alephium/desktop-wallet/appmetadata'
20 |
21 | export interface AppMetaData {
22 | lastVersionCheckedAt: Date
23 | }
24 |
25 | export type TypeConstructors = DateConstructor | StringConstructor | NumberConstructor | BooleanConstructor
26 |
27 | export const APPMETADATA_KEYS: Record = {
28 | lastVersionCheckedAt: Date
29 | }
30 |
31 | export const toAppMetaData = (key: string, value: string): unknown => {
32 | if (key === '') return value
33 | const TypeConstructor = APPMETADATA_KEYS[key]
34 | return (TypeConstructor && new TypeConstructor(value)) || undefined
35 | }
36 |
--------------------------------------------------------------------------------
/src/utils/colors.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | export const labelColorPalette = ['#3DD97E', '#FFC400', '#64C9E1', '#9257FF', '#0D92FF', '#EB3BBC', '#EF5959']
20 |
21 | export const getRandomLabelColor = () => labelColorPalette[Math.floor(Math.random() * labelColorPalette.length)]
22 |
23 | export const stringToColour = (str: string) => {
24 | let hash = 0
25 | for (let i = 0; i < str.length; i++) {
26 | hash = str.charCodeAt(i) + ((hash << 5) - hash)
27 | }
28 | let colour = '#'
29 | for (let i = 0; i < 3; i++) {
30 | const value = (hash >> (i * 8)) & 0xff
31 | colour += ('00' + value.toString(16)).substr(-2)
32 | }
33 | return colour
34 | }
35 |
--------------------------------------------------------------------------------
/src/utils/constants.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | export enum WALLETCONNECT_ERRORS {
20 | TRANSACTION_SEND_FAILED = -32000,
21 | PARSING_SESSION_REQUEST_FAILED = -33000,
22 | TRANSACTION_BUILD_FAILED = -34000,
23 | TRANSACTION_SIGN_FAILED = -35000
24 | }
25 |
26 | export const CHART_DATE_FORMAT = 'YYYY-MM-DD'
27 |
--------------------------------------------------------------------------------
/src/utils/contacts.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | import { contactsLoadedFromPersistentStorage } from '@/storage/addresses/addressesActions'
20 | import ContactsStorage from '@/storage/addresses/contactsPersistentStorage'
21 | import { store } from '@/storage/store'
22 | import { Contact } from '@/types/contacts'
23 |
24 | export const filterContacts = (contacts: Contact[], text: string) =>
25 | text.length < 2
26 | ? contacts
27 | : contacts.filter(
28 | (contact) => contact.name.toLowerCase().includes(text) || contact.address.toLowerCase().includes(text)
29 | )
30 |
31 | export const loadContacts = () => {
32 | const contacts: Contact[] = ContactsStorage.load()
33 |
34 | if (contacts.length > 0) store.dispatch(contactsLoadedFromPersistentStorage(contacts))
35 | }
36 |
--------------------------------------------------------------------------------
/src/utils/csvExport.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | import dayjs from 'dayjs'
20 |
21 | import { CsvExportTimerangeQueryParams, TransactionTimePeriod } from '@/types/transactions'
22 |
23 | export const getCsvExportTimeRangeQueryParams = (
24 | selectedTimePeriod: TransactionTimePeriod,
25 | now: dayjs.Dayjs
26 | ): CsvExportTimerangeQueryParams => {
27 | const thisMoment = now.valueOf()
28 | const lastYear = now.subtract(1, 'year')
29 |
30 | return {
31 | '24h': { fromTs: now.subtract(24, 'hour').valueOf(), toTs: thisMoment },
32 | '1w': { fromTs: now.subtract(7, 'day').valueOf(), toTs: thisMoment },
33 | '1m': { fromTs: now.subtract(30, 'day').valueOf(), toTs: thisMoment },
34 | '6m': { fromTs: now.subtract(6, 'month').valueOf(), toTs: thisMoment },
35 | '12m': { fromTs: now.subtract(12, 'month').valueOf(), toTs: thisMoment },
36 | previousYear: {
37 | fromTs: lastYear.startOf('year').valueOf(),
38 | toTs: lastYear.endOf('year').valueOf()
39 | },
40 | thisYear: { fromTs: now.startOf('year').valueOf(), toTs: thisMoment }
41 | }[selectedTimePeriod]
42 | }
43 |
44 | export const generateCsvFile = (csvContent: string, fileName: string) => {
45 | const url = URL.createObjectURL(new Blob([csvContent], { type: 'text/csv' }))
46 | const a = document.createElement('a')
47 | a.style.display = 'none'
48 | a.href = url
49 | a.download = fileName
50 | document.body.appendChild(a)
51 | a.click()
52 | document.body.removeChild(a)
53 | window.URL.revokeObjectURL(url)
54 | }
55 |
--------------------------------------------------------------------------------
/src/utils/currencies.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | import { Currency } from '@/types/settings'
20 |
21 | type CurrencyData = {
22 | name: string
23 | ticker: Currency
24 | symbol: string
25 | }
26 |
27 | export const currencies: Record = {
28 | CHF: {
29 | name: 'Swiss francs',
30 | ticker: 'CHF',
31 | symbol: 'CHF'
32 | },
33 | EUR: {
34 | name: 'Euro',
35 | ticker: 'EUR',
36 | symbol: '€'
37 | },
38 | IDR: {
39 | name: 'Rupiah',
40 | ticker: 'IDR',
41 | symbol: 'Rp'
42 | },
43 | GBP: {
44 | name: 'Great Britain Pound',
45 | ticker: 'GBP',
46 | symbol: '£'
47 | },
48 | USD: {
49 | name: 'United States Dollar',
50 | ticker: 'USD',
51 | symbol: '$'
52 | },
53 | TRY: {
54 | name: 'Turkish Lira',
55 | ticker: 'TRY',
56 | symbol: '₺'
57 | },
58 | VND: {
59 | name: 'Vietnamese Dong',
60 | ticker: 'VND',
61 | symbol: '₫'
62 | },
63 | RUB: {
64 | name: 'Russian Ruble',
65 | ticker: 'RUB',
66 | symbol: '₽'
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/utils/links.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | export const links = {
20 | passphrase:
21 | 'https://docs.alephium.org/wallet/desktop-wallet/advanced-features#2-passphrase-advanced-security-feature',
22 | latestRelease: 'https://github.com/alephium/desktop-wallet/releases/latest',
23 | latestReleaseApi: 'https://api.github.com/repos/alephium/desktop-wallet/releases/latest',
24 | utxoConsolidation: 'https://docs.alephium.org/wallet/desktop-wallet/advanced-features#1-utxo-consolidation',
25 | miningWallet: 'https://docs.alephium.org/wallet/desktop-wallet/configure-mining-wallet',
26 | discord: 'https://www.alephium.org/discord',
27 | faq: 'https://docs.alephium.org/frequently-asked-questions',
28 | analytics: 'https://docs.alephium.org/frequently-asked-questions#what-analytics-does-the-desktop-wallet-collect',
29 | utxoDust:
30 | 'https://docs.alephium.org/frequently-asked-questions#why-is-there-an-additional-0001-alph-per-token-added-to-my-transaction-when-i-try-to-send-tokens',
31 | github: 'https://github.com/alephium',
32 | twitter: 'https://twitter.com/alephium'
33 | }
34 |
--------------------------------------------------------------------------------
/src/utils/pointer.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | import { PointerEvent } from 'react'
20 |
21 | // TODO: Copied from explorer
22 |
23 | export const getPointerAbsolutePositionInElement = (e: PointerEvent) => {
24 | const bounds = e.currentTarget.getBoundingClientRect()
25 |
26 | return {
27 | x: e.clientX - bounds.x,
28 | y: e.clientY - bounds.y
29 | }
30 | }
31 |
32 | export const getPointerRelativePositionInElement = (e: PointerEvent) => {
33 | const { x: posX, y: posY } = getPointerAbsolutePositionInElement(e)
34 |
35 | return {
36 | x: posX / e.currentTarget.clientWidth,
37 | y: posY / e.currentTarget.clientHeight
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/utils/wallet.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | import { Wallet } from '@alephium/sdk'
20 |
21 | export const getWalletInitialAddress = (wallet: Wallet) => ({
22 | index: 0,
23 | hash: wallet.address,
24 | publicKey: wallet.publicKey,
25 | privateKey: wallet.privateKey
26 | })
27 |
--------------------------------------------------------------------------------
/src/vite-env.d.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | ///
20 | ///
21 |
--------------------------------------------------------------------------------
/src/workers/addressDiscovery.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | import { discoverActiveAddresses, Wallet, walletImport } from '@alephium/sdk'
20 | import { ExplorerProvider } from '@alephium/web3'
21 |
22 | import { exponentialBackoffFetchRetry } from '../api/fetchRetry'
23 |
24 | interface WorkerPayload {
25 | data: {
26 | mnemonic: Wallet['mnemonic']
27 | clientUrl: string
28 | skipIndexes?: number[]
29 | passphrase?: string
30 | }
31 | }
32 |
33 | self.onmessage = ({ data: { mnemonic, passphrase, clientUrl, skipIndexes } }: WorkerPayload) => {
34 | const { masterKey } = walletImport(mnemonic, passphrase)
35 | const client = new ExplorerProvider(clientUrl, undefined, exponentialBackoffFetchRetry)
36 |
37 | discover(masterKey, client, skipIndexes)
38 | }
39 |
40 | const discover = async (masterKey: Wallet['masterKey'], client: ExplorerProvider, skipIndexes?: number[]) => {
41 | const activeAddresses = await discoverActiveAddresses(masterKey, client, skipIndexes)
42 | self.postMessage(activeAddresses)
43 | }
44 |
--------------------------------------------------------------------------------
/src/workers/deriveAddressesFromIndexes.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | import { deriveNewAddressData, Wallet, walletImport } from '@alephium/sdk'
20 |
21 | interface WorkerPayload {
22 | data: {
23 | mnemonic: Wallet['mnemonic']
24 | indexesToDerive: number[]
25 | passphrase?: string
26 | }
27 | }
28 |
29 | self.onmessage = ({ data: { mnemonic, passphrase, indexesToDerive } }: WorkerPayload) => {
30 | const { masterKey } = walletImport(mnemonic, passphrase)
31 |
32 | derive(masterKey, indexesToDerive)
33 | }
34 |
35 | const derive = (masterKey: Wallet['masterKey'], indexesToDerive: number[]) => {
36 | self.postMessage(indexesToDerive.map((index) => deriveNewAddressData(masterKey, undefined, index)))
37 | }
38 |
--------------------------------------------------------------------------------
/src/workers/deriveAddressesInGroups.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | import { deriveNewAddressData, Wallet, walletImport } from '@alephium/sdk'
20 |
21 | interface WorkerPayload {
22 | data: {
23 | mnemonic: Wallet['mnemonic']
24 | groups: number[]
25 | skipIndexes?: number[]
26 | passphrase?: string
27 | }
28 | }
29 |
30 | self.onmessage = ({ data: { mnemonic, passphrase, groups, skipIndexes } }: WorkerPayload) => {
31 | const { masterKey } = walletImport(mnemonic, passphrase)
32 |
33 | derive(masterKey, groups, skipIndexes)
34 | }
35 |
36 | const derive = (masterKey: Wallet['masterKey'], groups: number[], skipIndexes?: number[]) => {
37 | self.postMessage(
38 | groups.map((group) => ({ ...deriveNewAddressData(masterKey, group, undefined, skipIndexes), group }))
39 | )
40 | }
41 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "baseUrl": ".",
4 | "target": "esnext",
5 | "lib": ["dom", "dom.iterable", "esnext"],
6 | "types": ["vite/client", "vite-plugin-svgr/client", "vitest/globals"],
7 | "allowJs": true,
8 | "skipLibCheck": true,
9 | "esModuleInterop": true,
10 | "allowSyntheticDefaultImports": true,
11 | "strict": true,
12 | "forceConsistentCasingInFileNames": true,
13 | "module": "esnext",
14 | "moduleResolution": "node",
15 | "resolveJsonModule": true,
16 | "isolatedModules": true,
17 | "noEmit": true,
18 | "jsx": "react-jsx",
19 | "noFallthroughCasesInSwitch": true,
20 | "paths": {
21 | "@/*": ["./src/*"]
22 | }
23 | },
24 | "include": ["src"]
25 | }
26 |
--------------------------------------------------------------------------------
/vite.config.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2018 - 2023 The Alephium Authors
3 | This file is part of the alephium project.
4 |
5 | The library is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Lesser General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | The library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public License
16 | along with the library. If not, see .
17 | */
18 |
19 | ///
20 |
21 | import react from '@vitejs/plugin-react'
22 | import { defineConfig } from 'vite'
23 | import svgrPlugin from 'vite-plugin-svgr'
24 | import viteTsconfigPaths from 'vite-tsconfig-paths'
25 |
26 | // https://vitejs.dev/config/
27 | export default defineConfig({
28 | server: {
29 | host: true,
30 | port: 3000
31 | },
32 | optimizeDeps: {
33 | esbuildOptions: {
34 | target: 'es2020',
35 | // Node.js global to browser globalThis
36 | define: {
37 | global: 'globalThis'
38 | }
39 | },
40 | include: ['@alephium/sdk'] // To allow for using npm link https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies
41 | },
42 | plugins: [react(), viteTsconfigPaths(), svgrPlugin()],
43 | test: {
44 | globals: true,
45 | environment: 'jsdom',
46 | setupFiles: ['./src/setupTests.js', '@vitest/web-worker'],
47 | coverage: {
48 | reporter: ['text', 'html'],
49 | exclude: ['node_modules/', 'src/setupTests.js']
50 | }
51 | },
52 | build: {
53 | target: 'es2020',
54 | outDir: 'build'
55 | },
56 | base: ''
57 | })
58 |
--------------------------------------------------------------------------------