Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

feat: replace localStorage with StorageAdapter #14

Merged
merged 12 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
.env
*.code-workspace
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 18

- uses: pnpm/action-setup@v2
name: Install pnpm
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
dist
.env
*.code-workspace
.nvmrc
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
**/node_modules
**/dist
**/.env
**/.next
**/.nuxt
**/.output
pnpm-lock.yaml
*.code-workspace
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"editor.formatOnSave": true,
"git.closeDiffOnOperation": true,
"javascript.validate.enable": true,
"eslint.workingDirectories": [
"./examples/nextjs",
"./examples/react-ts",
"./examples/vanilla-ts",
"./examples/vue-ts",
"./packages/use-wallet-js",
"./packages/use-wallet-react",
"./packages/use-wallet-vue"
]
}
3 changes: 3 additions & 0 deletions examples/nextjs/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions examples/nextjs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
3 changes: 3 additions & 0 deletions examples/nextjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @txnlab/use-wallet-react Next.js example

This example provides a minimal setup to get [@txnlab/use-wallet-react](https://github.com/TxnLab/use-wallet-js/tree/main/packages/use-wallet-react) working in a Next.js app.
10 changes: 10 additions & 0 deletions examples/nextjs/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
/** @see https://github.com/WalletConnect/walletconnect-monorepo/issues/1908#issuecomment-1487801131 */
webpack: (config) => {
config.externals.push('pino-pretty', 'lokijs', 'encoding')
return config
}
}

export default nextConfig
30 changes: 30 additions & 0 deletions examples/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "use-wallet-example-nextjs",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@blockshake/defly-connect": "^1.1.6",
"@perawallet/connect": "^1.3.3",
"@txnlab/use-wallet-js": "workspace:*",
"@txnlab/use-wallet-react": "workspace:*",
"@walletconnect/modal": "^2.6.2",
"@walletconnect/sign-client": "^2.10.2",
"algosdk": "^2.6.0",
"next": "14.1.0",
"react": "^18",
"react-dom": "^18"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.1.0",
"typescript": "^5"
}
}
1 change: 1 addition & 0 deletions examples/nextjs/public/next.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/nextjs/public/vercel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions examples/nextjs/src/app/Connect.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.walletName {
line-height: 1.5;
margin: 1.33em 0;
text-align: center;
}

.walletName[data-active='true']:after {
content: ' [active]';
}

.walletButtons {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
gap: 0.5em;
margin-bottom: 0.9em;
}

.walletButtons button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
.walletButtons button:not(:disabled):hover {
border-color: #0071ff;
}
.walletButtons button:focus,
.walletButtons button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
.walletButtons button:disabled {
opacity: 0.75;
cursor: default;
}

.walletMenu {
margin-top: 1.5em;
}

.fallbackMsg {
font-size: 1.125rem;
line-height: 1.5rem;
text-align: center;
opacity: 0.5;
margin: 2em 0;
}

@media (prefers-color-scheme: light) {
.walletButtons button {
background-color: #ffffff;
}
}
65 changes: 65 additions & 0 deletions examples/nextjs/src/app/Connect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { useWallet } from '@txnlab/use-wallet-react'
import * as React from 'react'
import styles from './Connect.module.css'

export function Connect() {
const [isReady, setIsReady] = React.useState(false)

React.useEffect(() => {
setIsReady(true)
}, [])

const { wallets } = useWallet()

if (!isReady) {
return <p className={styles.fallbackMsg}>Loading wallets&hellip;</p>
}

return (
<div>
{wallets.map((wallet) => (
<div key={wallet.id}>
<h4 className={styles.walletName} data-active={wallet.isActive}>
{wallet.metadata.name}
</h4>
<div className={styles.walletButtons}>
<button type="button" onClick={() => wallet.connect()} disabled={wallet.isConnected}>
Connect
</button>
<button
type="button"
onClick={() => wallet.disconnect()}
disabled={!wallet.isConnected}
>
Disconnect
</button>
<button
type="button"
onClick={() => wallet.setActive()}
disabled={!wallet.isConnected || wallet.isActive}
>
Set Active
</button>
</div>
{wallet.isActive && wallet.accounts.length > 0 && (
<div>
<select
className={styles.walletMenu}
onChange={(event: React.ChangeEvent<HTMLSelectElement>) => {
const target = event.target
wallet.setActiveAccount(target.value)
}}
>
{wallet.accounts.map((account) => (
<option key={account.address} value={account.address}>
{account.address}
</option>
))}
</select>
</div>
)}
</div>
))}
</div>
)
}
Binary file added examples/nextjs/src/app/favicon.ico
Binary file not shown.
100 changes: 100 additions & 0 deletions examples/nextjs/src/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
:root {
--max-width: 1100px;
--border-radius: 12px;
--font-mono: ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono',
'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono',
'Courier New', monospace;

--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;

--primary-glow: conic-gradient(
from 180deg at 50% 50%,
#16abff33 0deg,
#0885ff33 55deg,
#54d6ff33 120deg,
#0071ff33 160deg,
transparent 360deg
);
--secondary-glow: radial-gradient(rgba(255, 255, 255, 1), rgba(255, 255, 255, 0));

--tile-start-rgb: 239, 245, 249;
--tile-end-rgb: 228, 232, 233;
--tile-border: conic-gradient(
#00000080,
#00000040,
#00000030,
#00000020,
#00000010,
#00000010,
#00000080
);

--callout-rgb: 238, 240, 241;
--callout-border-rgb: 172, 175, 176;
--card-rgb: 180, 185, 188;
--card-border-rgb: 131, 134, 135;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;

--primary-glow: radial-gradient(rgba(1, 65, 255, 0.4), rgba(1, 65, 255, 0));
--secondary-glow: linear-gradient(
to bottom right,
rgba(1, 65, 255, 0),
rgba(1, 65, 255, 0),
rgba(1, 65, 255, 0.3)
);

--tile-start-rgb: 2, 13, 46;
--tile-end-rgb: 2, 5, 19;
--tile-border: conic-gradient(
#ffffff80,
#ffffff40,
#ffffff30,
#ffffff20,
#ffffff10,
#ffffff10,
#ffffff80
);

--callout-rgb: 20, 20, 20;
--callout-border-rgb: 108, 108, 108;
--card-rgb: 100, 100, 100;
--card-border-rgb: 200, 200, 200;
}
}

* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

html,
body {
max-width: 100vw;
overflow-x: hidden;
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(to bottom, transparent, rgb(var(--background-end-rgb)))
rgb(var(--background-start-rgb));
}

a {
color: inherit;
text-decoration: none;
}

@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;
}
}
25 changes: 25 additions & 0 deletions examples/nextjs/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Providers } from '@/app/providers'
import { Inter } from 'next/font/google'
import type { Metadata } from 'next'
import './globals.css'

const inter = Inter({ subsets: ['latin'] })

export const metadata: Metadata = {
title: 'use-wallet | Next.js',
description: 'Generated by create next app'
}

export default function RootLayout({
children
}: Readonly<{
children: React.ReactNode
}>) {
return (
<html lang="en">
<body className={inter.className}>
<Providers>{children}</Providers>
</body>
</html>
)
}
Loading
Loading