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

Feat:(new vault package) #79

Merged
merged 26 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
be560c5
feat(new vault package): init refactoring
teddyjfpender Aug 24, 2023
b23d09b
linting
teddyjfpender Aug 24, 2023
e1ea6f5
feat(add keyAgent Store): create keyAgent module
teddyjfpender Aug 25, 2023
495bec1
add address derivation test to keyAgentStore
teddyjfpender Aug 26, 2023
6867865
add encrypted private key to derived credentials
teddyjfpender Aug 26, 2023
120f700
add cred to sign args, decrypt key
teddyjfpender Aug 27, 2023
e6befb8
linting
teddyjfpender Aug 27, 2023
52209bc
refactor stores, add credential tests
teddyjfpender Aug 27, 2023
c4e6088
lint
teddyjfpender Aug 27, 2023
e11748f
update deprecated `new Buffer()`
teddyjfpender Aug 29, 2023
21845b8
refactor(wallet pt.1)
teddyjfpender Aug 30, 2023
e286343
lint
teddyjfpender Aug 30, 2023
af1ca05
refactor(wallet pt.2 switching networks)
teddyjfpender Sep 1, 2023
26ef083
chore(refactor wallet): add manager for SoC
teddyjfpender Sep 10, 2023
8fb55ef
feat(add searching of credentials)
teddyjfpender Sep 19, 2023
340043f
feat(add credential search API to wallet)
teddyjfpender Sep 19, 2023
a797e86
fix(wallet ui): partially fixed
teddyjfpender Sep 19, 2023
8808cd7
lint
teddyjfpender Sep 19, 2023
dee4dcf
fix(UI with new wallet and stores)
teddyjfpender Sep 23, 2023
104b630
feat(add multi-chain package and use in vault)
teddyjfpender Sep 23, 2023
7ba2612
fix(multi-chain-core api)
teddyjfpender Sep 23, 2023
9a940e2
feat(multi-chain account store)
teddyjfpender Sep 23, 2023
3ffba27
feat(api)!: wallet multichain features
teddyjfpender Sep 25, 2023
93c7ecd
chore(plumbing): featues package uses multichain
teddyjfpender Sep 27, 2023
c45e7f7
refactor(change stores to wrap differently)
teddyjfpender Sep 27, 2023
cb133eb
fix(remove skipHydration from stores)
teddyjfpender Sep 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/features/.ladle/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react'
import { MinaNetwork, MinaPayload, Network } from '@palladxyz/key-management'
import { MinaPayload, Network } from '@palladxyz/key-management'
import { useWallet } from '../src/wallet/hooks/useWallet'
import { Mina } from '@palladxyz/mina-core'

Expand Down
3 changes: 2 additions & 1 deletion packages/features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"@palladxyz/offchain-data": "*",
"@palladxyz/persistence": "*",
"@palladxyz/ui": "*",
"@palladxyz/vault": "*",
"@palladxyz/vaultv2": "*",
"@palladxyz/multi-chain-core": "*",
"@total-typescript/ts-reset": "^0.4.2",
"dayjs": "^1.11.8",
"easy-mesh-gradient": "^0.0.5",
Expand Down
13 changes: 9 additions & 4 deletions packages/features/src/common/hooks/useAccount.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { MinaNetwork } from '@palladxyz/key-management'
import { Mina } from '@palladxyz/mina-core'
import useSWR from 'swr'

import { useWallet } from '../../wallet/hooks/useWallet'
import { useAppStore } from '../../wallet/store/app'

export const useAccount = () => {
const { wallet } = useWallet()
const address = wallet.getCurrentWallet()?.address
const { wallet, address } = useWallet()
const network = useAppStore((state) => state.network)
const swr = useSWR(
address ? [address, 'account', MinaNetwork[network]] : null,
address
? [
address,
'account',
Mina.Networks[network.toUpperCase() as keyof typeof Mina.Networks]
]
: null,
async () => await wallet.getAccountInfo()
)
const rawMinaBalance = swr.isLoading ? 0 : swr.data?.balance?.total || 0
Expand Down
13 changes: 9 additions & 4 deletions packages/features/src/common/hooks/useTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { MinaNetwork } from '@palladxyz/key-management'
import { Mina } from '@palladxyz/mina-core'
import useSWR from 'swr'

import { useWallet } from '../../wallet/hooks/useWallet'
import { useAppStore } from '../../wallet/store/app'

export const useTransaction = ({ hash }: { hash: string }) => {
const { wallet } = useWallet()
const address = wallet.getCurrentWallet()?.address
const { wallet, address } = useWallet()
const network = useAppStore((state) => state.network)
return useSWR(
address ? ['transaction', hash, MinaNetwork[network]] : null,
address
? [
'transaction',
hash,
Mina.Networks[network.toUpperCase() as keyof typeof Mina.Networks]
]
: null,
async () => await wallet.getTransaction({ hash })
)
}
13 changes: 9 additions & 4 deletions packages/features/src/common/hooks/useTransactions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { MinaNetwork } from '@palladxyz/key-management'
import { Mina } from '@palladxyz/mina-core'
import useSWR from 'swr'

import { useWallet } from '../../wallet/hooks/useWallet'
import { useAppStore } from '../../wallet/store/app'

export const useTransactions = () => {
const { wallet } = useWallet()
const address = wallet.getCurrentWallet()?.address
const { wallet, address } = useWallet()
const network = useAppStore((state) => state.network)
return useSWR(
address ? [address, 'transactions', MinaNetwork[network]] : null,
address
? [
address,
'transactions',
Mina.Networks[network.toUpperCase() as keyof typeof Mina.Networks]
]
: null,
async () => await wallet.getTransactions()
)
}
8 changes: 4 additions & 4 deletions packages/features/src/lock/views/UnlockWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
TooltipContent,
TooltipTrigger
} from '@palladxyz/ui'
import { keyAgentStore } from '@palladxyz/vault'
import { AlertCircleIcon, EyeIcon, EyeOffIcon } from 'lucide-react'
import { useState } from 'react'
import { useForm } from 'react-hook-form'
Expand Down Expand Up @@ -39,9 +38,10 @@ export const UnlockWalletView = () => {
spendingPassword: string
}) => {
await getSessionPersistence().setItem('spendingPassword', spendingPassword)
keyAgentStore.destroy()
await keyAgentStore.persist.rehydrate()
const currentWallet = wallet.getCurrentWallet()
//keyAgentStore.destroy()
//await keyAgentStore.persist.rehydrate()
wallet.rehydrateStores()
const currentWallet = wallet.getCurrentWallet() // might have to return address
if (!currentWallet) return await onError()
return navigate('/dashboard')
}
Expand Down
30 changes: 19 additions & 11 deletions packages/features/src/onboarding/views/MnemonicConfirmation.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { MinaPayload, Network } from '@palladxyz/key-management'
import {
MinaPayload,
MinaSpecificArgs,
Network
} from '@palladxyz/key-management'
import { Mina } from '@palladxyz/mina-core'
import { getSessionPersistence } from '@palladxyz/persistence'
import { Button, cn, Input, Label } from '@palladxyz/ui'
import { keyAgentStore } from '@palladxyz/vault'
import { useMemo, useState } from 'react'
import { useForm } from 'react-hook-form'
import { useNavigate } from 'react-router-dom'
Expand Down Expand Up @@ -47,21 +50,26 @@ export const MnemonicConfirmationView = () => {
if (!spendingPassword) return
if (!mnemonic) return
getSessionPersistence().setItem('spendingPassword', spendingPassword)
keyAgentStore.destroy()
keyAgentStore.persist.rehydrate()
//keyAgentStore.destroy()
//keyAgentStore.persist.rehydrate()
// TODO: Add await in UI when user clicks restore wallet
// only press "submit" once
wallet.rehydrateStores()
const restoreArgs: MinaSpecificArgs = {
network: Network.Mina,
accountIndex: 0,
addressIndex: 0,
networkType: 'testnet' // TODO: make this configurable
}
await wallet.restoreWallet(
new MinaPayload(),
{
network: Network.Mina,
accountIndex: 0,
addressIndex: 0,
networkType: 'testnet'
},
restoreArgs,
Mina.Networks.MAINNET,
{
mnemonicWords: mnemonic.split(' '),
getPassphrase: async () => Buffer.from(spendingPassword)
}
},
walletName //this is the keyAgentName
)
setVaultStateInitialized()
return navigate('/onboarding/finish')
Expand Down
23 changes: 13 additions & 10 deletions packages/features/src/onboarding/views/MnemonicInput.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
MinaPayload,
MinaSpecificArgs,
Network,
validateMnemonic,
wordlist
} from '@palladxyz/key-management'
import { Mina } from '@palladxyz/mina-core'
import { getSessionPersistence } from '@palladxyz/persistence'
import { Button, cn, Label, Textarea } from '@palladxyz/ui'
import { keyAgentStore } from '@palladxyz/vault'
import { useMemo, useState } from 'react'
import { useForm } from 'react-hook-form'
import { useNavigate } from 'react-router-dom'
Expand Down Expand Up @@ -47,21 +47,24 @@ export const MnemonicInputView = () => {
if (!walletName) return
if (!spendingPassword) return
getSessionPersistence().setItem('spendingPassword', spendingPassword)
keyAgentStore.destroy()
keyAgentStore.persist.rehydrate()
//keyAgentStore.destroy()
//keyAgentStore.persist.rehydrate()
wallet.rehydrateStores()
const restoreArgs: MinaSpecificArgs = {
network: Network.Mina,
accountIndex: 0,
addressIndex: 0,
networkType: 'testnet' // TODO: make this configurable
}
await wallet.restoreWallet(
new MinaPayload(),
{
network: Network.Mina,
accountIndex: 0,
addressIndex: 0,
networkType: 'testnet'
},
restoreArgs,
Mina.Networks.MAINNET,
{
mnemonicWords: mnemonic.split(' '),
getPassphrase: async () => Buffer.from(spendingPassword)
}
},
walletName //this is the keyAgentName
)
setVaultStateInitialized()
return navigate('/onboarding/finish')
Expand Down
2 changes: 1 addition & 1 deletion packages/features/src/onboarding/views/Start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const StartView = () => {
<div className="flex flex-col gap-8">
<div>
<h1 className="text-5xl text-sky-500 font-semibold">Pallad</h1>
<h2 className="text-5xl">- Mina Wallet You Deserve</h2>
<h2 className="text-5xl">- Enter The Minaverse</h2>
</div>
<p className="leading-8">
Take your Mina journey to the next level with out secure, transparent,
Expand Down
4 changes: 2 additions & 2 deletions packages/features/src/overview/components/OverviewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { useWallet } from '../../wallet/hooks/useWallet'
import { AvatarMenu } from './AvatarMenu'

export const OverviewCard = () => {
const { wallet, copyWalletAddress, gradientBackground } = useWallet()
const walletAddress = wallet.getCurrentWallet()?.address
const { copyWalletAddress, gradientBackground, address } = useWallet()
const walletAddress = address
const navigate = useNavigate()
const { isLoading: accountLoading, minaBalance } = useAccount()
const { data: fiatPriceData, isLoading: priceLoading } = useFiatPrice()
Expand Down
4 changes: 2 additions & 2 deletions packages/features/src/receive/views/Receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { useWallet } from '../../wallet/hooks/useWallet'
export const ReceiveView = () => {
const { theme } = useTheme()
const navigate = useNavigate()
const { wallet, copyWalletAddress, gradientBackground } = useWallet()
const walletAddress = wallet.getCurrentWallet()?.address
const { copyWalletAddress, gradientBackground, address } = useWallet()
const walletAddress = address
return (
<AppLayout>
<div className="flex flex-col flex-1 gap-4">
Expand Down
15 changes: 11 additions & 4 deletions packages/features/src/send/views/TransactionSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Mina } from '@palladxyz/mina-core'
import { Multichain } from '@palladxyz/multi-chain-core'
import { Button, Card } from '@palladxyz/ui'
import { ArrowDownLeftIcon } from 'lucide-react'
import { useMemo } from 'react'
Expand Down Expand Up @@ -28,19 +29,25 @@ export const TransactionSummaryView = () => {
const amount = BigInt(outgoingTransaction.amount * 1_000_000_000)
const fee = BigInt(outgoingTransaction.fee * 1_000_000_000)
const constructAndSubmitTx = async () => {
const transaction: Mina.TransactionBody = {
const transaction: Multichain.MultiChainTransactionBody = {
to: outgoingTransaction.to,
from: address,
fee,
amount,
nonce: 0,
type: 'payment'
nonce: 0, // TODO: nonce management -- should we have a Nonce Manager in the wallet? Yes.
type: 'payment' // TODO: handle with enums (payment, delegation, zkApp commands?)
}
const constructedTx = await wallet.constructTx(
transaction,
Mina.TransactionKind.PAYMENT
)
const signedTx = await wallet.sign(constructedTx)
const keyAgentName = await wallet.getCurrentKeyAgentName()
if (!keyAgentName) {
throw new Error(
'No key agent name set in @features/send/views/TransactionSummary'
)
}
const signedTx = await wallet.sign(constructedTx, keyAgentName) // TODO: Fix this with new wallet API
const submittedTx = await wallet.submitTx(signedTx)
console.log('>>>ST', submittedTx?.result)
navigate('/transactions/success')
Expand Down
26 changes: 20 additions & 6 deletions packages/features/src/settings/views/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MinaNetwork } from '@palladxyz/key-management'
import { Mina } from '@palladxyz/mina-core'
import {
Card,
Label,
Expand Down Expand Up @@ -26,11 +26,13 @@ export const SettingsView = () => {
setNetwork: state.setNetwork,
network: state.network
}))
const handleNetworkSwitch = async (value: MinaNetwork) => {
const handleNetworkSwitch = async (value: Mina.Networks) => {
await switchNetwork(value)
await mutate(() => true, undefined, { revalidate: false })
toast({
title: `Network has been changed to ${MinaNetwork[value]}`
title: `Network has been changed to ${
Mina.Networks[value.toUpperCase() as keyof typeof Mina.Networks]
}`
})
}
const handleThemeSwitch = async (value: string) => {
Expand All @@ -51,21 +53,33 @@ export const SettingsView = () => {
<RadioGroup value={network} onValueChange={handleNetworkSwitch}>
<div className="flex items-center space-x-2">
<RadioGroupItem
value={MinaNetwork[MinaNetwork.Mainnet]}
value={
Mina.Networks[
Mina.Networks.MAINNET.toUpperCase() as keyof typeof Mina.Networks
]
}
id="networkMainnet"
/>
<Label htmlFor="networkMainnet">Mainnet</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem
value={MinaNetwork[MinaNetwork.Devnet]}
value={
Mina.Networks[
Mina.Networks.DEVNET.toUpperCase() as keyof typeof Mina.Networks
]
}
id="networkDevnet"
/>
<Label htmlFor="networkDevnet">Devnet</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem
value={MinaNetwork[MinaNetwork.Berkeley]}
value={
Mina.Networks[
Mina.Networks.BERKELEY.toUpperCase() as keyof typeof Mina.Networks
]
}
id="networkBerkeley"
/>
<Label htmlFor="networkBerkeley">Berkeley</Label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { Mina } from '@palladxyz/mina-core'
import { Multichain } from '@palladxyz/multi-chain-core'

import { useWallet } from '../../wallet/hooks/useWallet'
import { structurizeTransactions } from '../utils/structurizeTransactions'
import { TxTile } from './TxTile'

interface TransactionsListProps {
transactions: Mina.TransactionBody[]
transactions: Multichain.MultiChainTransactionBody[]
}

export const TransactionsList = ({ transactions }: TransactionsListProps) => {
const { wallet } = useWallet()
const address = wallet.getCurrentWallet()?.address
const { address } = useWallet()
if (!address) return null
const txDates =
transactions &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TxSide } from '../../common/types'

interface TxSideIndicatorProps {
side: TxSide
// TODO: consider how to make this with Multichain
kind: Mina.TransactionKind
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Mina } from '@palladxyz/mina-core'
import { Multichain } from '@palladxyz/multi-chain-core'
import dayjs from 'dayjs'
import { groupBy, map, pipe } from 'rambda'

Expand All @@ -13,7 +13,7 @@ export const structurizeTransaction = ({
tx,
walletPublicKey
}: {
tx: Mina.TransactionBody
tx: Multichain.MultiChainTransactionBody
walletPublicKey: string
}) => ({
...tx,
Expand All @@ -24,11 +24,11 @@ export const structurizeTransaction = ({
})

export const structurizeTransactions = ([txs, walletPublicKey]: [
Mina.TransactionBody[],
Multichain.MultiChainTransactionBody[],
string
]) =>
pipe(
map((tx: Mina.TransactionBody) =>
map((tx: Multichain.MultiChainTransactionBody) =>
structurizeTransaction({ tx, walletPublicKey })
),
groupBy((tx) => tx.date)
Expand Down
Loading