Skip to content

Commit

Permalink
Refactor wallet handling: Replace wallet type literals with ProviderType
Browse files Browse the repository at this point in the history
enum, remove unused network constants, and update SUPPORTED_WALLETS
structure for improved type safety and maintainability.
  • Loading branch information
hathbanger committed Nov 7, 2024
1 parent 32ad31e commit 803c02e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 72 deletions.
57 changes: 13 additions & 44 deletions apps/demo.lasereyes.build/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,20 @@ import WalletCard from '@/components/WalletCard'
import { useEffect, useState } from 'react'
import { clsx } from 'clsx'
import {
FRACTAL_TESTNET,
LEATHER,
MAGIC_EDEN,
MAINNET,
OKX,
OYL,
PHANTOM,
SIGNET,
TESTNET,
UNISAT,
WIZZ,
ORANGE,
XVERSE,
useLaserEyes,
WalletIcon,
OP_NET,
TESTNET4,
SUPPORTED_WALLETS,
FRACTAL_MAINNET,
ProviderType,
} from '@omnisat/lasereyes'
import { satoshisToBTC } from '@/lib/btc'
import { cn, truncateString } from '@/lib/utils'
Expand All @@ -32,7 +27,6 @@ import { Input } from '@/components/ui/input'
import { getPackageVersion } from '@/lib/github'
import { badgeVariants } from '@/components/ui/badge'
import { FaExternalLinkAlt } from 'react-icons/fa'
import { toast } from 'sonner'
import { RxReload } from 'react-icons/rx'
import { ClickToCopyNpmInstallPill } from '@/components/ClickToCopyNpmInstallPill'
import { ImNewTab } from 'react-icons/im'
Expand Down Expand Up @@ -86,20 +80,6 @@ const App = () => {
// FRACTAL_MAINNET,
// ]

const switchNet = async (
n: typeof MAINNET | typeof TESTNET | typeof SIGNET | typeof FRACTAL_TESTNET
) => {
try {
// await switchNetwork(
// NETWORKS[NETWORKS.findIndex((net) => net === network) + 1]
// )
// setNetwork(n)
} catch (e) {
// @ts-ignore
toast.error(e.message)
}
}

return (
<div
className={
Expand Down Expand Up @@ -408,29 +388,18 @@ const App = () => {
</div>
</div>
<div className={'flex flex-wrap justify-center gap-8'}>
{Object.values(SUPPORTED_WALLETS).map((walletInfo) => (
<WalletCard
key={walletInfo.name}
wallet={walletInfo}
walletName={
walletInfo.name as
| typeof UNISAT
| typeof XVERSE
| typeof OYL
| typeof MAGIC_EDEN
| typeof OKX
| typeof OP_NET
| typeof ORANGE
| typeof LEATHER
| typeof PHANTOM
| typeof WIZZ
}
setSignature={setSignature}
unsignedPsbt={unsignedPsbt}
setUnsignedPsbt={setUnsignedPsbt}
setSignedPsbt={setSignedPsbt}
/>
))}
{Object.values(SUPPORTED_WALLETS).map(
(walletInfo: { name: ProviderType; url: string }) => (
<WalletCard
key={walletInfo.name}
wallet={walletInfo}
setSignature={setSignature}
unsignedPsbt={unsignedPsbt}
setUnsignedPsbt={setUnsignedPsbt}
setSignedPsbt={setSignedPsbt}
/>
)
)}
</div>
</div>
)
Expand Down
13 changes: 2 additions & 11 deletions apps/demo.lasereyes.build/components/WalletCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
useLaserEyes,
WalletIcon,
OP_NET,
ProviderType,
} from '@omnisat/lasereyes'
import {
Card,
Expand Down Expand Up @@ -49,17 +50,7 @@ const WalletCard = ({
setSignedPsbt,
}: {
wallet: {
name:
| typeof UNISAT
| typeof XVERSE
| typeof OYL
| typeof MAGIC_EDEN
| typeof OKX
| typeof OP_NET
| typeof LEATHER
| typeof ORANGE
| typeof PHANTOM
| typeof WIZZ
name: ProviderType
url: string
}
setSignature: (signature: string) => void
Expand Down
1 change: 1 addition & 0 deletions packages/lasereyes-core/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './networks'
export * from './wallets'
export * from './settings'
export * from './content'
52 changes: 35 additions & 17 deletions packages/lasereyes-core/src/constants/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,55 @@ export const P2PSH = 'p2psh'
export const P2WSH = 'p2wsh'
export const P2SH = 'p2sh'

export const SUPPORTED_WALLETS = {
[LEATHER]: {
name: LEATHER,
enum ProviderEnumMap {
LEATHER = 'leather',
MAGIC_EDEN = 'magic-eden',
OKX = 'okx',
WIZZ = 'wizz',
ORANGE = 'orange',
OYL = 'oyl',
UNISAT = 'unisat',
XVERSE = 'xverse',
}

type WalletInfo = {
[key in ProviderEnumMap]: {
name: ProviderEnumMap
url: string
}
}

export const SUPPORTED_WALLETS: WalletInfo = {
[ProviderEnumMap.LEATHER]: {
name: ProviderEnumMap.LEATHER,
url: 'https://leather.io/install-extension',
},
[MAGIC_EDEN]: {
name: MAGIC_EDEN,
[ProviderEnumMap.MAGIC_EDEN]: {
name: ProviderEnumMap.MAGIC_EDEN,
url: 'https://wallet.magiceden.io/',
},
[OKX]: {
name: OKX,
[ProviderEnumMap.OKX]: {
name: ProviderEnumMap.OKX,
url: 'https://chromewebstore.google.com/detail/okx-wallet/mcohilncbfahbmgdjkbpemcciiolgcge',
},
[WIZZ]: {
name: WIZZ,
[ProviderEnumMap.WIZZ]: {
name: ProviderEnumMap.WIZZ,
url: 'https://wizzwallet.io/#extension',
},
[ORANGE]: {
name: ORANGE,
[ProviderEnumMap.ORANGE]: {
name: ProviderEnumMap.ORANGE,
url: 'https://www.orangewallet.com/',
},
[OYL]: {
name: OYL,
[ProviderEnumMap.OYL]: {
name: ProviderEnumMap.OYL,
url: 'https://www.oyl.io/#get-wallet',
},
[UNISAT]: {
name: UNISAT,
[ProviderEnumMap.UNISAT]: {
name: ProviderEnumMap.UNISAT,
url: 'https://unisat.io/download',
},
[XVERSE]: {
name: XVERSE,
[ProviderEnumMap.XVERSE]: {
name: ProviderEnumMap.XVERSE,
url: 'https://www.xverse.app/download',
},
}

0 comments on commit 803c02e

Please sign in to comment.