Skip to content

Commit ce4b1e1

Browse files
committed
fixes and improvements
1 parent d37ca7b commit ce4b1e1

25 files changed

+88
-49
lines changed

Diff for: packages/desktop/components/AccountSummary.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import { TextType } from '@ui/enums'
55
66
import { localize } from '@core/i18n'
7-
import { nodeInfo } from '@core/network'
7+
import { nodeInfoNetworkName } from '@core/network'
88
import { selectedWalletAssets } from '@core/wallet'
99
import { activeProfile } from '@core/profile'
1010
11-
$: fomattedNetworkName = $nodeInfo?.protocol.networkName
11+
$: fomattedNetworkName = $nodeInfoNetworkName
1212
.split(' ')
1313
.map((word) => word[0].toUpperCase() + word.substring(1))
1414
.join(' ')

Diff for: packages/desktop/components/AccountSwitcher.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { AccountLabel, Icon, Modal } from '@ui'
2+
import { WalletLabel, Icon, Modal } from '@ui'
33
import { WalletSwitcherModal } from '@components'
44
import { selectedWallet } from '@core/wallet/stores'
55
import { Icon as IconEnum } from '@auxiliary/icon'
@@ -19,7 +19,7 @@
1919
<svelte:window on:click={onOutsideClick} />
2020
<account-switcher>
2121
<button type="button" on:click={onButtonClick} class="flex flex-row justify-center items-center space-x-2">
22-
<AccountLabel account={$selectedWallet} />
22+
<WalletLabel wallet={$selectedWallet} />
2323
<icon-container class:rotate={isModalOpened}>
2424
<Icon height="18" width="18" icon={IconEnum.ChevronDown} classes="text-gray-800 dark:text-white" />
2525
</icon-container>

Diff for: packages/desktop/electron/preload.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ try {
113113
bindMethodsAcrossContextBridge(IotaSdk.SecretManager.prototype, manager)
114114
return manager
115115
},
116+
async getClientFromWallet(id){
117+
const wallet = wallets[id];
118+
// Why is this here?:
119+
// We cannot create classes from exposed functions
120+
// https://www.electronjs.org/docs/latest/api/context-bridge
121+
const client = await wallet.getClient();
122+
bindMethodsAcrossContextBridge(IotaSdk.Client.prototype, client)
123+
return client
124+
},
116125
// TODO(2.0): rename to createWallet
117126
async createWallet(id, options) {
118127
const wallet = await IotaSdk.Wallet.create(options)
@@ -121,7 +130,7 @@ try {
121130
bindMethodsAcrossContextBridge(IotaSdk.Wallet.prototype, wallet)
122131
return wallet
123132
},
124-
// TODO(2.0): also remove from file system
133+
// TODO(2.0): also remove from file system? Does it make sense? file system != memoery
125134
deleteWallet(id) {
126135
if (id && id in wallets) {
127136
const wallet = wallets[id]
@@ -135,15 +144,15 @@ try {
135144
if (!wallet) {
136145
wallet = await IotaSdk.Wallet.create(walletOptions)
137146
wallets[id] = wallet
138-
bindMethodsAcrossContextBridge(IotaSdk.Account.prototype, wallet)
147+
bindMethodsAcrossContextBridge(IotaSdk.Wallet.prototype, wallet)
139148
}
140149
return wallet
141150
},
142151
// TODO(2.0): remove this method from here and move to new profile
143152
async recoverAccounts(managerId, payload) {
144153
const manager = wallets[managerId]
145154
const accounts = await manager.recoverAccounts(...Object.values(payload))
146-
accounts.forEach((account) => bindMethodsAcrossContextBridge(IotaSdk.Account.prototype, account))
155+
accounts.forEach((account) => bindMethodsAcrossContextBridge(IotaSdk.Wallet.prototype, account))
147156
return accounts
148157
},
149158
clearWalletsFromMemory() {

Diff for: packages/shared/components/SubjectBox.svelte

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<script lang="ts">
22
import { localize } from '@core/i18n'
33
import { Subject, SubjectType } from '@core/wallet'
4-
import { Box, AddressBox, Text, AccountLabel, TextType, FontWeight } from 'shared/components'
4+
import { Box, AddressBox, Text, WalletLabel, TextType, FontWeight } from 'shared/components'
55
66
export let subject: Subject | null = null
77
</script>
88

9-
{#if subject?.type === SubjectType.Account}
9+
{#if subject?.type === SubjectType.Wallet}
1010
<Box row clearBackground clearPadding classes="justify-center">
11-
<AccountLabel account={subject?.account} />
11+
<WalletLabel wallet={subject?.wallet} />
1212
</Box>
1313
{:else if subject?.type === SubjectType.Address}
1414
<AddressBox clearBackground clearPadding isCopyable address={subject?.address} />

Diff for: packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function createOnboardingWallet(name?: string, color?: string): Pro
3030
const walletName = name || `${localize('general.wallet')} ${(get(activeWallets)?.length ?? 0) + 1}`;
3131

3232
// 2. Create the wallet instance
33-
const wallet = await createNewWallet()
33+
const wallet = await createWallet() // TODO(2.0) Not sure about this, I think this should be createWallet instead
3434

3535
// 3. Sync the wallet with the Node
3636
// TODO(2.0): test & fix sync when we have iota2.0 nodes
@@ -41,6 +41,7 @@ export async function createOnboardingWallet(name?: string, color?: string): Pro
4141
// TODO(2.0) Fix
4242
addWalletToActiveWallets(walletState)
4343
addWalletPersistedDataToOnboardingProfile(walletState.id, walletPersistedData)
44+
addWalletPersistedDataToActiveProfile(walletState.id, walletPersistedData) // TODO(2.0) Not sure about this,
4445
// TODO(2.0) Fix
4546
addEmptyWalletActivitiesToAllWalletActivities(walletState.id)
4647

Diff for: packages/shared/lib/core/api/interfaces/api.interface.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SecretManager } from '@iota/sdk'
1+
import { Client, SecretManager } from '@iota/sdk'
22
import {
33
AccountId,
44
FoundryId,
@@ -15,6 +15,7 @@ import { IWallet } from '@core/profile/interfaces'
1515

1616
// TODO(2.0): Every method should return a promise (maybe except Utils, needs research)
1717
export interface IApi {
18+
getClientFromWallet(id: string): Promise<Client>
1819
createSecretManager(options: SecretManagerType): Promise<SecretManager>
1920
createWallet(id: string, payload: WalletOptions): Promise<IWallet>
2021
deleteWallet(id: string): void

Diff for: packages/shared/lib/core/network/constants/official-node-urls.constant.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ export const OFFICIAL_NODE_URLS: Readonly<{ [key in NetworkId]?: string[] }> = {
44
[NetworkId.Iota]: ['https://api.stardust-mainnet.iotaledger.net', 'https://iota-node.tanglebay.com'],
55
[NetworkId.IotaAlphanet]: ['https://api.iota-alphanet.iotaledger.net'],
66
[NetworkId.Shimmer]: ['https://api.shimmer.network', 'https://shimmer-node.tanglebay.com'],
7-
[NetworkId.Testnet]: ['https://api.testnet.shimmer.network'],
7+
[NetworkId.Testnet]: [':)'],
88
}
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { INodeInfo } from '@iota/sdk/out/types'
2-
import { writable } from 'svelte/store'
2+
import { derived, writable } from 'svelte/store'
33

44
export const nodeInfo = writable<INodeInfo | undefined>(undefined)
55

66
export function setNodeInfo(newNodeInfo: INodeInfo | undefined): void {
77
return nodeInfo.set(newNodeInfo)
88
}
9+
10+
export const nodeInfoNetworkName = derived(nodeInfo, ($nodeInfo) => $nodeInfo?.protocolParameters[0]?.parameters?.networkName)

Diff for: packages/shared/lib/core/network/utils/getNetworkIdFromNetworkName.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function getNetworkIdFromNetworkName(networkName: string): NetworkId {
1313
case 'testnet':
1414
case 'testnet-1':
1515
case 'testnet-2':
16+
case 'docker':
1617
return NetworkId.Testnet
1718
default:
1819
return NetworkId.Custom

Diff for: packages/shared/lib/core/profile/actions/active-profile/checkAndUpdateActiveProfileNetwork.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ export async function checkAndUpdateActiveProfileNetwork(): Promise<void> {
77
const $activeProfile = get(activeProfile)
88
const nodeInfoResponse = await getAndUpdateNodeInfo(true)
99
const networkId = $activeProfile?.network?.id
10+
const networkName = nodeInfoResponse?.nodeInfo?.protocolParameters[0]?.parameters?.networkName
1011
if (!networkId || networkId === NetworkId.Custom) {
1112
const network = buildPersistedNetworkFromNodeInfoResponse(nodeInfoResponse)
1213
network.chains = $activeProfile.network?.chains || []
1314
updateActiveProfile({ network })
14-
} else if (networkId !== getNetworkIdFromNetworkName(nodeInfoResponse?.nodeInfo?.protocol?.networkName)) {
15+
} else if (networkId !== getNetworkIdFromNetworkName(networkName)) {
1516
throw new Error('error.node.networkIdMismatch')
1617
}
1718
}

Diff for: packages/shared/lib/core/profile/actions/active-profile/loadWallets.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { loadWallet } from '@core/wallet'
1+
import { loadWallet, setSelectedWallet } from '@core/wallet'
22
import { get } from 'svelte/store'
33
import { activeWallets, activeProfile } from '../../stores'
44
import { getWallets } from '../getWallets'

Diff for: packages/shared/lib/core/profile/actions/active-profile/login.ts

+9
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
4747
if (id) {
4848
// Step 1: create profile manager if its doesn't exist
4949
incrementLoginProgress()
50+
console.log(1)
5051
await waitForPreviousManagerToBeDestroyed()
5152
// if (!isOnboardingSecretManagerInitialized()) {
5253
// // TODO(2.0) Not sure about this
@@ -71,6 +72,7 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
7172
} else {
7273
wallets = await getWallets()
7374
}
75+
console.log(2, wallets)
7476
/**
7577
* NOTE: In the case no wallets with funds were recovered, we must
7678
* create one for the new profile.
@@ -86,6 +88,7 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
8688
checkActiveProfileAuth(onSuccess, config, onCancel)
8789
})
8890
const success = await onUnlocked
91+
console.log("success", success)
8992
if (success) {
9093
await createNewWallet()
9194
} else {
@@ -94,10 +97,14 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
9497
}
9598
}
9699

100+
console.log(3)
101+
97102
// Step 4: load wallets
98103
incrementLoginProgress()
99104
await loadWallets()
100105

106+
console.log(4)
107+
101108
let initialSelectedWalletId = get(activeWallets)?.[0]?.id
102109

103110
// TODO(2.0): is needed lastUsedWalletId?
@@ -116,6 +123,8 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
116123
await checkAndUpdateActiveProfileNetwork()
117124
void pollNetworkStatus()
118125

126+
console.log(5)
127+
119128
// Step 5: load assets
120129
incrementLoginProgress()
121130
await refreshWalletAssetsForActiveProfile(

Diff for: packages/shared/lib/core/profile/actions/createWallet.ts

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
import { api } from '@core/api'
22
import { generateRandomId } from '@core/utils'
33
import { get } from 'svelte/store'
4-
import { IWallet } from '../interfaces'
4+
import { IProfile, IWallet } from '../interfaces'
55
import { activeProfile as activeProfileStore } from '../stores'
66
import { getSecretManagerFromProfileType, getStorageDirectoryOfProfile } from '../utils'
7-
import { WalletOptions } from '@iota/sdk'
7+
import { Wallet, WalletOptions } from '@iota/sdk'
88
import { selectedWalletId } from '../../wallet'
99

10+
export function getWalletOptions(profile: IProfile, storagePath:string): WalletOptions {
11+
const walletOptions: WalletOptions = {
12+
clientOptions: profile.clientOptions,
13+
storagePath,
14+
secretManager: getSecretManagerFromProfileType(profile.type, storagePath),
15+
bipPath: {
16+
coinType: profile.network.coinType,
17+
account: 0,
18+
addressIndex: 0
19+
},
20+
}
21+
22+
console.log("aaa", walletOptions)
23+
24+
return walletOptions
25+
}
26+
1027
// TODO(2.0): Fix and finish this method
1128
/* - __storage__/
1229
- profile_id_1
@@ -17,18 +34,8 @@ import { selectedWalletId } from '../../wallet'
1734
export async function createWallet(activeProfile = get(activeProfileStore)): Promise<IWallet> {
1835
const id = activeProfile.id;
1936
const storagePath = await getStorageDirectoryOfProfile(id)
20-
// const snapshotPath = ''
2137

22-
const walletOptions: WalletOptions = {
23-
clientOptions: activeProfile.clientOptions,
24-
secretManager: getSecretManagerFromProfileType(activeProfile.type, storagePath),
25-
bipPath: {
26-
coinType: activeProfile.network.coinType,
27-
account: 0,
28-
addressIndex: 0
29-
},
30-
coinType: activeProfile.network.coinType
31-
}
38+
const walletOptions = getWalletOptions(activeProfile, storagePath);
3239
console.log("walletOptions", walletOptions);
3340

3441
const wallet = await api.createWallet(id, {

Diff for: packages/shared/lib/core/profile/actions/getWallets.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { IWallet } from '../interfaces/wallet.interface'
77
// TODO(2.0): Finalize when new profile is ready
88
export async function getWallets(): Promise<IWallet[]> {
99
const profile = get(activeProfile)
10-
let wallets: IWallet[] = []
10+
let wallets: IWallet[] = []
11+
console.log(profile)
1112
if (profile.walletPersistedData) {
1213
wallets = await Promise.all(Object.entries(profile.walletPersistedData)
1314
.map(([id, data]) => api.getWallet(id, data.walletOptions)))

Diff for: packages/shared/lib/core/profile/utils/getSecretManagerFromProfileType.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ProfileType } from '@core/profile'
66
// TODO(2.0) Fix all usages
77
export function getSecretManagerFromProfileType(type?: ProfileType, storagePath?: string): SecretManagerType {
88
const strongholdSecretManager = {
9-
stronghold: { snapshotPath: `${storagePath}/wallet.stronghold`, password: 'mellamobego' },
9+
stronghold: { snapshotPath: `${storagePath}/wallet.stronghold`, password: 'mellamobego' }, // TODO(2.0) Remove this harcoded password
1010
}
1111
const ledgerSecretManager = {
1212
ledgerNano: USE_LEDGER_SIMULATOR,

Diff for: packages/shared/lib/core/wallet/actions/buildWalletStateAndPersistedData.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@ import { IWallet } from '@core/profile/interfaces';
44
import { IWalletState } from '../interfaces/wallet-state.interface';
55
import { IPersistedWalletData } from '../interfaces/persisted-wallet-data.interface';
66
import { buildWalletState } from './buildWalletState'
7+
import { activeProfile, getStorageDirectoryOfProfile, getWalletOptions } from '@core/profile';
8+
import { get } from 'svelte/store';
79

810
export async function buildWalletStateAndPersistedData(
911
wallet: IWallet,
1012
name?: string,
1113
color?: string
1214
): Promise<[IWalletState, IPersistedWalletData]> {
15+
const storagePath = await getStorageDirectoryOfProfile(wallet.id)
16+
const walletOptions = getWalletOptions(get(activeProfile), storagePath)
17+
console.log("walletOptions", walletOptions)
1318
const persistedWalletData: IPersistedWalletData = {
1419
name: name || `${localize('general.wallet')}`,
1520
color: color || getRandomWalletColor(),
1621
hidden: false,
1722
shouldRevote: false,
18-
walletOptions: {}
23+
walletOptions
1924
}
2025
const walletState = await buildWalletState(wallet, persistedWalletData)
2126
return [walletState, persistedWalletData]

Diff for: packages/shared/lib/core/wallet/actions/getClient.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Client } from '@iota/sdk/out/client'
2-
import { getSelectedWallet } from '@core/wallet/stores'
2+
import { getSelectedWallet, selectedWalletId } from '@core/wallet/stores'
3+
import { api } from '../../api';
4+
import { get } from 'svelte/store';
35

46
export function getClient(): Promise<Client> {
5-
const wallet = getSelectedWallet();
6-
console.log("wallet in getClient", wallet);
7+
const selectedWallet = get(selectedWalletId);
8+
console.log("wallet in getClient", selectedWallet);
79

8-
return wallet!.getClient()
10+
return api.getClientFromWallet(selectedWallet)
911
}

Diff for: packages/shared/lib/core/wallet/actions/loadWallet.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function loadWallet(wallet: IWallet): Promise<IWalletState> {
1111
// TODO(2.0): test & fix sync when we have iota2.0 nodes
1212
// await wallet.sync({ ...DEFAULT_SYNC_OPTIONS })
1313
const walletPersistedData = getActiveProfilePersistedWalletData(walletId)
14-
14+
console.log("walletPersistedData", walletPersistedData, walletId, wallet)
1515
let accountState: IWalletState
1616
if (walletPersistedData) {
1717
accountState = await buildWalletState(wallet, walletPersistedData)
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export enum SubjectType {
2-
Account = 'account', // TODO(2.0) This should be Wallet?
2+
Wallet = 'wallet', // TODO(2.0) This should be Wallet?
33
Address = 'address',
44
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IWalletState } from '@core/wallet/interfaces'
22
import { SubjectType } from '../enums'
33

4-
export interface IAccountSubject {
5-
type: SubjectType.Account
6-
account: IWalletState
4+
export interface IWalletSubject {
5+
type: SubjectType.Wallet
6+
wallet: IWalletState
77
}

Diff for: packages/shared/lib/core/wallet/stores/selected-wallet-activities.store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ function getFieldsToSearchFromActivity(activity: Activity): string[] {
7878
fieldsToSearch.push(getFormattedAmountFromActivity(activity, false)?.toLowerCase())
7979
}
8080

81-
if (activity.subject?.type === SubjectType.Account) {
82-
fieldsToSearch.push(activity.subject?.account?.name)
81+
if (activity.subject?.type === SubjectType.Wallet) {
82+
fieldsToSearch.push(activity.subject?.wallet?.name)
8383
} else if (activity.subject?.type === SubjectType.Address) {
8484
fieldsToSearch.push(activity.subject?.address)
8585
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { IAccountSubject, IAddressSubject } from '../interfaces'
1+
import { IWalletSubject, IAddressSubject } from '../interfaces'
22

3-
export type Subject = IAccountSubject | IAddressSubject
3+
export type Subject = IWalletSubject | IAddressSubject

Diff for: packages/shared/lib/core/wallet/utils/generateActivity/helper/getSubjectFromActivity.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export function getSubjectLocaleFromActivity(activity: Activity): string {
2727
return localize('general.shimmerGenesis')
2828
} else if (activity.type === ActivityType.Vesting) {
2929
return localize('general.stardustGenesis')
30-
} else if (subject?.type === SubjectType.Account) {
31-
return truncateString(subject?.account?.name, 13, 0)
30+
} else if (subject?.type === SubjectType.Wallet) {
31+
return truncateString(subject?.wallet?.name, 13, 0)
3232
} else if (subject?.type === SubjectType.Address) {
3333
const address = activity?.parsedLayer2Metadata?.ethereumAddress ?? subject?.address
3434
const network = getLayer2NetworkFromAddress(address)

Diff for: packages/shared/lib/core/wallet/utils/getSubjectFromAddress.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { SubjectType } from '../enums'
55
export function getSubjectFromAddress(address: string): Subject {
66
const account = findActiveWalletWithAddress(address)
77
if (account) {
8-
return { type: SubjectType.Account, account: account }
8+
return { type: SubjectType.Wallet, wallet: account }
99
} else {
1010
return { type: SubjectType.Address, address }
1111
}

Diff for: packages/shared/lib/core/wallet/utils/isSubjectInternal.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { SubjectType } from '../enums'
22
import { Subject } from '../types'
33

44
export function isSubjectInternal(subject: Subject | undefined): boolean {
5-
return subject?.type === SubjectType.Account
5+
return subject?.type === SubjectType.Wallet
66
}

0 commit comments

Comments
 (0)