Skip to content

Commit

Permalink
Merge pull request #640 from peanutprotocol/fix/conflicts-messup
Browse files Browse the repository at this point in the history
fix: prev conflict messup when merging pr's
  • Loading branch information
kushagrasarathe authored Jan 21, 2025
2 parents 2e545a0 + 61bf684 commit e713ac9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 86 deletions.
6 changes: 4 additions & 2 deletions src/app/(mobile-ui)/home/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ export default function Home() {
const selectedWalletIndex = rawIndex === -1 ? 0 : rawIndex
const [focusedIndex, setFocusedIndex] = useState(selectedWalletIndex)

// update focusedIndex when selectedWallet changes
// update focusedIndex and focused wallet when selectedWallet changes
useEffect(() => {
const index = wallets.findIndex((wallet) => wallet.address === selectedWallet?.address)
if (index !== -1) {
setFocusedIndex(index)
// also update the focused wallet when selected wallet changes
dispatch(walletActions.setFocusedWallet(wallets[index]))
}
}, [selectedWallet, wallets])
}, [selectedWallet, wallets, dispatch])

const hasWallets = wallets.length > 0
const { handleLogin, isLoggingIn } = useZeroDev()
Expand Down
25 changes: 12 additions & 13 deletions src/app/(mobile-ui)/wallet/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@ import NavHeader from '@/components/Global/NavHeader'
import { WalletCard } from '@/components/Home/WalletCard'
import { useAuth } from '@/context/authContext'
import { useWallet } from '@/hooks/wallet/useWallet'
import { IUserBalance, WalletProviderType } from '@/interfaces'
import { IUserBalance } from '@/interfaces'
import { useWalletStore } from '@/redux/hooks'
import { formatAmount, getChainName, getUserPreferences, updateUserPreferences } from '@/utils'
import { useAppKit, useDisconnect } from '@reown/appkit/react'
import { useState } from 'react'
import { twMerge } from 'tailwind-merge'

const WalletDetailsPage = () => {
const { selectedWallet, isConnected } = useWallet()
const { open } = useAppKit()
const { disconnect } = useDisconnect()
const { focusedWallet, wallets } = useWalletStore()
const { isConnected } = useWallet()
const { username } = useAuth()
const [isBalanceHidden, setIsBalanceHidden] = useState(() => {
const prefs = getUserPreferences()
return prefs?.balanceHidden ?? false
})

const { username } = useAuth()
const isActiveWalletPW = selectedWallet?.walletProviderType === WalletProviderType.PEANUT
const isActiveWalletBYOW = selectedWallet?.walletProviderType === WalletProviderType.BYOW

console.log('selectedWallet', selectedWallet)
const walletDetails = wallets.find((wallet) => wallet.address === focusedWallet)

const handleToggleBalanceVisibility = (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation()
Expand All @@ -46,11 +45,11 @@ const WalletDetailsPage = () => {
</div>

<div className="mx-auto">
{selectedWallet && (
{focusedWallet && walletDetails && (
<WalletCard
key={selectedWallet.address}
key={walletDetails.address}
type="wallet"
wallet={selectedWallet}
wallet={walletDetails}
username={username ?? ''}
selected
onClick={() => {}}
Expand All @@ -75,14 +74,14 @@ const WalletDetailsPage = () => {

<div
className={twMerge(
selectedWallet?.balances && !!selectedWallet?.balances?.length ? 'border-b border-b-n-1' : ''
walletDetails?.balances && !!walletDetails?.balances?.length ? 'border-b border-b-n-1' : ''
)}
>
{!!selectedWallet?.balances?.length ? (
{!!walletDetails?.balances?.length ? (
<div className="space-y-3">
<div className="text-base font-semibold">Balance</div>
<div>
{selectedWallet.balances.map((balance: IUserBalance) => (
{walletDetails.balances.map((balance: IUserBalance) => (
<ListItemView
key={`${balance.chainId}-${balance.symbol}`}
id={`${balance.chainId}-${balance.symbol}`}
Expand Down
146 changes: 75 additions & 71 deletions src/components/Request/Create/Views/Initial.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Button, Card } from '@/components/0_Bruddle'
import { getTokenDetails } from '@/components/Create/Create.utils'
import AddressInput from '@/components/Global/AddressInput'
import FileUploadInput, { IFileUploadInputProps } from '@/components/Global/FileUploadInput'
import FlowHeader from '@/components/Global/FlowHeader'
import Loading from '@/components/Global/Loading'
import TokenAmountInput from '@/components/Global/TokenAmountInput'
import TokenSelector from '@/components/Global/TokenSelector/TokenSelector'
Expand Down Expand Up @@ -165,80 +166,83 @@ export const InitialView = ({
}, [isPeanutWallet, selectedWallet?.address])

return (
<Card className="shadow-none sm:shadow-primary-4">
<Card.Header>
<Card.Title>Request a payment</Card.Title>
<Card.Description>
Choose the amount, token and chain. You will request a payment to your wallet. Add an invoice if you
want to.
</Card.Description>
</Card.Header>
<Card.Content>
<div className="flex w-full flex-col items-center justify-center gap-3">
<TokenAmountInput
className="w-full"
setTokenValue={(value) => {
_setTokenValue(value ?? '')
}}
tokenValue={_tokenValue}
onSubmit={() => {
handleOnNext({
recipientAddress,
tokenAddress: selectedTokenAddress,
chainId: selectedChainID,
userBalances: selectedWallet?.balances ?? [],
tokenValue,
tokenData: selectedTokenData,
attachmentOptions,
})
}}
/>
{isExternalWallet && <TokenSelector shouldBeConnected={false} />}
<FileUploadInput
attachmentOptions={attachmentOptions}
setAttachmentOptions={setAttachmentOptions}
/>
{isExternalWallet && (
<AddressInput
placeholder="Enter recipient address"
value={recipientAddress ?? ''}
onUpdate={(update: InputUpdate) => {
setRecipientAddress(update.value)
setInputChanging(update.isChanging)
setIsValidRecipient(update.isValid)
}}
<div>
<FlowHeader />
<Card className="shadow-none sm:shadow-primary-4">
<Card.Header>
<Card.Title>Request a payment</Card.Title>
<Card.Description>
Choose the amount, token and chain. You will request a payment to your wallet. Add an invoice if
you want to.
</Card.Description>
</Card.Header>
<Card.Content>
<div className="flex w-full flex-col items-center justify-center gap-3">
<TokenAmountInput
className="w-full"
setTokenValue={(value) => {
_setTokenValue(value ?? '')
}}
tokenValue={_tokenValue}
onSubmit={() => {
handleOnNext({
recipientAddress,
tokenAddress: selectedTokenAddress,
chainId: selectedChainID,
userBalances: selectedWallet?.balances ?? [],
tokenValue,
tokenData: selectedTokenData,
attachmentOptions,
})
}}
/>
)}
<Button
onClick={() => {
handleOnNext({
recipientAddress,
tokenAddress: selectedTokenAddress,
chainId: selectedChainID,
userBalances: selectedWallet?.balances ?? [],
tokenValue,
tokenData: selectedTokenData,
attachmentOptions,
})
}}
disabled={!isValidRecipient || inputChanging || isLoading || !_tokenValue}
>
{isLoading ? (
<div className="flex w-full flex-row items-center justify-center gap-2">
<Loading /> {loadingState}
</div>
) : (
'Confirm'
{isExternalWallet && <TokenSelector shouldBeConnected={false} />}
<FileUploadInput
attachmentOptions={attachmentOptions}
setAttachmentOptions={setAttachmentOptions}
/>
{isExternalWallet && (
<AddressInput
placeholder="Enter recipient address"
value={recipientAddress ?? ''}
onUpdate={(update: InputUpdate) => {
setRecipientAddress(update.value)
setInputChanging(update.isChanging)
setIsValidRecipient(update.isValid)
}}
className="w-full"
/>
)}
</Button>
</div>
{errorState.showError && (
<div className="text-start">
<label className=" text-h8 font-normal text-red ">{errorState.errorMessage}</label>
<Button
onClick={() => {
handleOnNext({
recipientAddress,
tokenAddress: selectedTokenAddress,
chainId: selectedChainID,
userBalances: selectedWallet?.balances ?? [],
tokenValue,
tokenData: selectedTokenData,
attachmentOptions,
})
}}
disabled={!isValidRecipient || inputChanging || isLoading || !_tokenValue}
>
{isLoading ? (
<div className="flex w-full flex-row items-center justify-center gap-2">
<Loading /> {loadingState}
</div>
) : (
'Confirm'
)}
</Button>
</div>
)}
</Card.Content>
</Card>
{errorState.showError && (
<div className="text-start">
<label className=" text-h8 font-normal text-red ">{errorState.errorMessage}</label>
</div>
)}
</Card.Content>
</Card>
</div>
)
}

0 comments on commit e713ac9

Please sign in to comment.