Skip to content

Commit

Permalink
Merge pull request #79 from teddyjfpender/main
Browse files Browse the repository at this point in the history
Feat:(new vault package)
  • Loading branch information
mrcnk authored Sep 28, 2023
2 parents 160f4af + cb133eb commit 54b0b11
Show file tree
Hide file tree
Showing 96 changed files with 3,169 additions and 1,594 deletions.
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

0 comments on commit 54b0b11

Please sign in to comment.