Skip to content

Commit

Permalink
Merge pull request #255 from omnisat/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
hathbanger authored Nov 13, 2024
2 parents 85a9cbd + f9e65fc commit 865d67a
Show file tree
Hide file tree
Showing 21 changed files with 303 additions and 80 deletions.
35 changes: 35 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: 🐛 Bug Report
about: Report a bug or unexpected behavior in the library
title: "[Bug]: "
labels: bug
assignees: ''
---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Use '...'
3. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots or logs to help explain your problem.

**Environment (please complete the following information):**
- Library Version: [e.g., 1.2.0]
- Node Version: [e.g., 18.x]
- Wallet Provider: [e.g., UniSat, Xverse]
- Operating System: [e.g., macOS, Windows]
- Framework: [e.g., React, Angular]
- Framework Version: [e.g., 1.2.0]
- Browser: [e.g., Chrome, Safari]
- Browser Version: [e.g., 88.0.4324.150]

**Additional context**
Add any other context about the problem here.
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE/documentation_improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: 📚 Documentation Improvement
about: Suggest changes or improvements to the documentation
title: "[Docs]: "
labels: documentation
assignees: ''
---

**Describe the improvement**
What specific part of the documentation could be improved?

**Suggestion for Improvement**
Provide a description of the improvement or addition you are proposing.

**Additional context**
Is there any other relevant information or context?
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: 🚀 Feature Request
about: Suggest an idea or enhancement for the library
title: "[Feature]: "
labels: enhancement
assignees: ''
---

**Is your feature request related to a problem?**
Please describe the problem you’re trying to solve.

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
Any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
31 changes: 31 additions & 0 deletions .github/ISSUE_TEMPLATE/security_vulnerability.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: 🔒 Security Vulnerability
about: Report a security vulnerability in the library
title: "[Security]: "
labels: security
assignees: ''
---

**Describe the vulnerability**
A clear and concise description of the security vulnerability.

**Potential Impact**
Describe the potential impact of this vulnerability if exploited.

**Steps to Reproduce**
Steps to reproduce the behavior, if possible:
1. ...
2. ...

**Environment (please complete the following information):**
- Library Version: [e.g., 1.2.0]
- Node Version: [e.g., 18.x]
- Wallet Provider: [e.g., UniSat, Xverse]
- Operating System: [e.g., macOS, Windows]
- Framework: [e.g., React, Angular]
- Framework Version: [e.g., 1.2.0]
- Browser: [e.g., Chrome, Safari]
- Browser Version: [e.g., 88.0.4324.150]

**Additional context**
Add any other context, logs, or details here.
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE/support_question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: ❓ Support/Question
about: Ask a question or request guidance about using the library
title: "[Support]: "
labels: question
assignees: ''
---

**Question**
Please describe your question or the guidance you need.

**Context**
Provide any relevant code snippets or configuration information to help explain your question.

**Additional context**
Add any other context or screenshots that may help explain your question.
42 changes: 37 additions & 5 deletions apps/demo.lasereyes.build/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import {
FRACTAL_MAINNET,
FRACTAL_TESTNET,
MAINNET,
NetworkType,
SIGNET,
TESTNET,
TESTNET4,
} from '@omnisat/lasereyes'
import dynamic from 'next/dynamic'

import App from '@/components/App'
import { useState } from 'react'
import { useEffect, useState } from 'react'
import { UtxoProvider } from '@/hooks/useUtxos'

const DynamicLasereyesProvider = dynamic(
Expand All @@ -19,18 +20,49 @@ const DynamicLasereyesProvider = dynamic(
)

export default function Home() {
const [network] = useState<
const [network, setNetwork] = useState<
| typeof MAINNET
| typeof TESTNET
| typeof TESTNET4
| typeof SIGNET
| typeof FRACTAL_MAINNET
| typeof FRACTAL_TESTNET
>(MAINNET)

const [mounted, setMounted] = useState(false)

const switchNet = () => {
if (network === MAINNET) {
setNetwork(TESTNET4)
} else if (network === TESTNET4) {
setNetwork(TESTNET)
} else if (network === TESTNET) {
setNetwork(SIGNET)
} else if (network === SIGNET) {
setNetwork(FRACTAL_MAINNET)
} else if (network === FRACTAL_MAINNET) {
setNetwork(FRACTAL_TESTNET)
} else {
setNetwork(MAINNET)
}
}

useEffect(() => {
setMounted(true)
}, [])

if (!mounted) {
return null
}

return (
<DynamicLasereyesProvider config={{ network }}>
<UtxoProvider network={network}>
<App />
<DynamicLasereyesProvider
config={{
network: network,
}}
>
<UtxoProvider>
<App setNetwork={switchNet} />
</UtxoProvider>
</DynamicLasereyesProvider>
)
Expand Down
70 changes: 47 additions & 23 deletions apps/demo.lasereyes.build/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ import WalletCard from '@/components/WalletCard'
import { useEffect, useState } from 'react'
import { clsx } from 'clsx'
import {
LEATHER,
MAGIC_EDEN,
OKX,
OYL,
PHANTOM,
UNISAT,
WIZZ,
ORANGE,
XVERSE,
FRACTAL_MAINNET,
FRACTAL_TESTNET,
MAINNET,
NetworkType,
ProviderType,
SIGNET,
SUPPORTED_WALLETS,
TESTNET,
TESTNET4,
useLaserEyes,
WalletIcon,
OP_NET,
SUPPORTED_WALLETS,
ProviderType,
} from '@omnisat/lasereyes'
import { satoshisToBTC } from '@/lib/btc'
import { cn, truncateString } from '@/lib/utils'
Expand All @@ -30,8 +27,9 @@ import { FaExternalLinkAlt } from 'react-icons/fa'
import { RxReload } from 'react-icons/rx'
import { ClickToCopyNpmInstallPill } from '@/components/ClickToCopyNpmInstallPill'
import { ImNewTab } from 'react-icons/im'
import { toast } from 'sonner'

const App = () => {
const App = ({ setNetwork }: { setNetwork: (n: NetworkType) => void }) => {
const {
address,
paymentAddress,
Expand All @@ -56,6 +54,32 @@ const App = () => {
| undefined
>()

const switchN = () => {
try {
if (network === MAINNET) {
switchNetwork(TESTNET4)
setNetwork(TESTNET4)
} else if (network === TESTNET4) {
switchNetwork(TESTNET)
setNetwork(TESTNET)
} else if (network === TESTNET) {
switchNetwork(SIGNET)
setNetwork(SIGNET)
} else if (network === SIGNET) {
switchNetwork(FRACTAL_MAINNET)
setNetwork(FRACTAL_MAINNET)
} else if (network === FRACTAL_MAINNET) {
switchNetwork(FRACTAL_TESTNET)
setNetwork(FRACTAL_TESTNET)
} else {
switchNetwork(MAINNET)
setNetwork(MAINNET)
}
} catch (e: any) {
toast.error(e.message)
}
}

useEffect(() => {
getPackageVersion().then((version) => {
setPkgVersion(version)
Expand All @@ -71,15 +95,6 @@ const App = () => {
// @ts-ignore
const total = satoshisToBTC(balance)

// const NETWORKS = [
// MAINNET,
// TESTNET,
// TESTNET4,
// SIGNET,
// FRACTAL_TESTNET,
// FRACTAL_MAINNET,
// ]

return (
<div
className={
Expand All @@ -91,6 +106,8 @@ const App = () => {
src={
address ? '/lasereyes_connected.svg' : '/lasereyes_disconnected.svg'
}
className={'w-auto h-auto'}
priority
alt={address ? 'Laser Eyes Connected' : 'Laser Eyes Disconnected'}
width={300}
height={47}
Expand Down Expand Up @@ -132,7 +149,14 @@ const App = () => {
<div className={'border border-[#3c393f] w-full text-xl grow pb-8'}>
<div className={'flex flex-row items-center gap-4 '}>
<div className={'grow'} />
<div className={'flex flex-col p-4 items-center'}>{network}</div>
<div
className={
'flex flex-col border border-[#3c393f] hover:underline cursor-pointer hover:text-orange-400 p-4 items-center'
}
onClick={() => switchN()}
>
{network}
</div>
</div>
<div
className={'flex flex-col gap-2 text-center items-center break-all'}
Expand Down
17 changes: 9 additions & 8 deletions apps/demo.lasereyes.build/hooks/useUtxos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ type UtxoContextType = {
const UtxoContext = createContext<UtxoContextType | undefined>(undefined)

export const UtxoProvider: React.FC<{
network: NetworkType
children: React.ReactNode
}> = ({ children, network }) => {
const { paymentAddress } = useLaserEyes()
}> = ({ children }) => {
const { paymentAddress, network } = useLaserEyes()
const mempoolUrl = `${getMempoolSpaceUrl(network)}/api/address/${paymentAddress}/utxo`
const [utxos, setUtxos] = useState<IMempoolUtxo[]>([])

const fetcher = useCallback(async (url: string) => {
const response = await fetch(url)
if (!response.ok) {
throw new Error('Failed to fetch UTXOs')
}
return response.json()
try {
const response = await fetch(url)
if (!response.ok) {
throw new Error('Failed to fetch UTXOs')
}
return response.json()
} catch (e) {}
}, [])

const { data: utxosData, error } = useSWR<IMempoolUtxo[]>(
Expand Down
2 changes: 1 addition & 1 deletion packages/lasereyes-core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@omnisat/lasereyes-core",
"private": false,
"version": "0.0.43",
"version": "0.0.44-rc.1",
"type": "module",
"main": "./dist/index.umd.cjs",
"module": "./dist/index.js",
Expand Down
11 changes: 5 additions & 6 deletions packages/lasereyes-core/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export class LaserEyesClient {
await provider?.connect(defaultWallet)
this.$store.setKey('connected', true)
} catch (error) {
console.error(error)
this.$store.setKey('isConnecting', false)
this.disconnect()
throw error
Expand All @@ -128,9 +127,9 @@ export class LaserEyesClient {
throw new Error('No wallet provider connected')
}

if (!this.$providerMap[this.$store.get().provider!]) {
throw new Error("The connected wallet doesn't support this method")
}
// if (!this.$providerMap[this.$store.get().provider!]) {
// throw new Error("The connected wallet doesn't support request accounts")
// }

try {
return await this.$providerMap[
Expand Down Expand Up @@ -332,7 +331,7 @@ export class LaserEyesClient {
} catch (error) {
if (error instanceof Error) {
if (error.message.toLowerCase().includes('not implemented')) {
throw new Error("The connected wallet doesn't support this method")
throw new Error("The connected wallet doesn't support getPublicKey")
}
}
throw error
Expand All @@ -351,7 +350,7 @@ export class LaserEyesClient {
} catch (error) {
if (error instanceof Error) {
if (error.message.toLowerCase().includes('not implemented')) {
throw new Error("The connected wallet doesn't support this method")
throw new Error("The connected wallet doesn't support getBalance")
}
}
throw error
Expand Down
Loading

0 comments on commit 865d67a

Please sign in to comment.