initial commit
This commit is contained in:
13
.dockerignore
Normal file
13
.dockerignore
Normal file
@@ -0,0 +1,13 @@
|
||||
.next
|
||||
node_modules
|
||||
.pnpm-store
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
.git
|
||||
.gitignore
|
||||
.DS_Store
|
||||
*.local
|
||||
.env
|
||||
.env.*
|
||||
67
.gitea/workflows/build.yml
Normal file
67
.gitea/workflows/build.yml
Normal file
@@ -0,0 +1,67 @@
|
||||
name: build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- feature-*
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "24"
|
||||
cache: "pnpm"
|
||||
|
||||
- name: Enable corepack
|
||||
run: corepack enable
|
||||
|
||||
- name: Install deps
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Lint
|
||||
run: pnpm run lint
|
||||
|
||||
build:
|
||||
name: build
|
||||
runs-on: ubuntu-latest
|
||||
needs: [lint]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "24"
|
||||
cache: "pnpm"
|
||||
|
||||
- name: Enable corepack
|
||||
run: corepack enable
|
||||
|
||||
- name: Install deps
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Build (skip lint in build)
|
||||
env:
|
||||
NEXT_DISABLE_ESLINT: "1"
|
||||
run: pnpm run build
|
||||
|
||||
- name: Upload build artifacts
|
||||
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: polynote-next-build
|
||||
path: |
|
||||
.next/standalone
|
||||
.next/static
|
||||
public
|
||||
95
.gitea/workflows/build.yml.bak
Normal file
95
.gitea/workflows/build.yml.bak
Normal file
@@ -0,0 +1,95 @@
|
||||
name: Build & Publish Binaries
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- feature-*
|
||||
- main
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: Lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.25.5"
|
||||
|
||||
- name: Run golangci-lint
|
||||
uses: golangci/golangci-lint-action@v7
|
||||
with:
|
||||
args: --timeout=5m
|
||||
|
||||
test:
|
||||
name: Test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.25.5'
|
||||
|
||||
- name: Run tests
|
||||
run: go test -cover ./...
|
||||
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
needs: [lint, test]
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.25.5'
|
||||
|
||||
- name: Build binaries (Linux & Windows)
|
||||
run: make build-all
|
||||
|
||||
- name: List built binaries
|
||||
run: ls -lh ./bin/
|
||||
|
||||
- name: Collect tag name
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
id: vars
|
||||
run: echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Create release
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
id: create_release
|
||||
uses: actions/create-release@v1
|
||||
with:
|
||||
tag_name: ${{ steps.vars.outputs.tag }}
|
||||
release_name: Release ${{ steps.vars.outputs.tag }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.CI_PIPELINE }}
|
||||
|
||||
- name: Upload release binaries
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
env:
|
||||
TOKEN: ${{ secrets.CI_PIPELINE }}
|
||||
URL: ${{ steps.create_release.outputs.upload_url }}
|
||||
run: |
|
||||
set -eo pipefail
|
||||
for FILE in ./bin/*; do
|
||||
NAME=$(basename "$FILE")
|
||||
echo "🔼 Uploading $NAME ..."
|
||||
curl -sS -X POST -H "Authorization: token $TOKEN" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary @"$FILE" \
|
||||
"$URL?name=$NAME" \
|
||||
-w "\n→ HTTP %{http_code} for $NAME\n"
|
||||
done
|
||||
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
.next
|
||||
node_modules
|
||||
.env.local
|
||||
.env
|
||||
dist
|
||||
coverage
|
||||
*.log
|
||||
5
.prettierignore
Normal file
5
.prettierignore
Normal file
@@ -0,0 +1,5 @@
|
||||
.next
|
||||
node_modules
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
6
.prettierrc
Normal file
6
.prettierrc
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"singleQuote": false,
|
||||
"semi": true,
|
||||
"trailingComma": "es5",
|
||||
"printWidth": 100
|
||||
}
|
||||
37
Dockerfile
Normal file
37
Dockerfile
Normal file
@@ -0,0 +1,37 @@
|
||||
# Multi-stage build for PolyNote (Next.js 15 + pnpm)
|
||||
FROM node:24-bookworm-slim AS base
|
||||
ENV PNPM_HOME="/pnpm"
|
||||
ENV PNPM_STORE_DIR="/pnpm/store"
|
||||
ENV PATH="$PNPM_HOME:$PATH"
|
||||
RUN corepack enable
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies
|
||||
FROM base AS deps
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store \
|
||||
pnpm install --frozen-lockfile
|
||||
|
||||
# Build the app
|
||||
FROM base AS builder
|
||||
ENV NODE_ENV=production
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store \
|
||||
NEXT_DISABLE_ESLINT=1 pnpm exec next build
|
||||
|
||||
# Production image
|
||||
FROM node:24-bookworm-slim AS runner
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT=3000
|
||||
ENV HOSTNAME=0.0.0.0
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=builder /app/.next/standalone ./
|
||||
COPY --from=builder /app/.next/static ./.next/static
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/package.json ./package.json
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
667
LICENSE
Normal file
667
LICENSE
Normal file
@@ -0,0 +1,667 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
PolyNote Copyright (C) 2025 PolyNote Maintainers
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
81
README.md
Normal file
81
README.md
Normal file
@@ -0,0 +1,81 @@
|
||||
# PolyNote · Polygon message pusher
|
||||
|
||||
Send hex-encoded messages on Polygon mainnet using the Trust Wallet browser extension or in-app browser. The app builds a zero-value transaction with your message in the data field, so only gas is spent.
|
||||
|
||||
## What it does
|
||||
- Connects to an injected EIP-1193 provider (Trust Wallet) and targets Polygon mainnet.
|
||||
- Hex-encodes up to 280 characters and sends a 0 MATIC transaction carrying the payload.
|
||||
- Internationalization (English, Spanish, French, German, Italian, Swedish) with a locale picker and auto language detection.
|
||||
- Live feedback, copy-to-clipboard for the tx hash, Polygonscan deep links, and a session “recent messages” view.
|
||||
- Light/Dark theme toggle.
|
||||
|
||||
## Stack
|
||||
- Next.js 15 (App Router), React 18, TypeScript
|
||||
- Ethers v6
|
||||
- Styling via a single CSS file (`app/globals.css`)
|
||||
- Path alias: `@/` → `app/`
|
||||
- Lint: ESLint 9 (flat config), Prettier
|
||||
|
||||
## Getting started
|
||||
1. Install pnpm and Node 18+ (Node 24 recommended).
|
||||
2. Install deps:
|
||||
```bash
|
||||
pnpm install
|
||||
```
|
||||
3. Run dev:
|
||||
```bash
|
||||
pnpm dev -- --hostname 127.0.0.1 --port 3120
|
||||
```
|
||||
The dev script guards against a missing `.next/server/middleware-manifest.json`.
|
||||
4. Open the URL, pick a language, connect Trust Wallet, type a message, and send. Only gas is charged.
|
||||
|
||||
## Scripts
|
||||
- `pnpm dev` – start dev server (with manifest guard)
|
||||
- `pnpm build` – production build (skips lint, run lint separately)
|
||||
- `pnpm start` – run the production server
|
||||
- `pnpm lint` – ESLint flat config
|
||||
- `pnpm format` – Prettier check
|
||||
|
||||
## Project layout
|
||||
- `app/page.tsx` – main UI/logic
|
||||
- `app/components/LocaleSelector.tsx` – locale dropdown
|
||||
- `app/hooks/useI18n.ts`, `app/hooks/useTheme.ts` – i18n + theme toggles
|
||||
- `app/locales/*.json` – translations
|
||||
- `app/globals.css` – styles
|
||||
- `scripts/ensure-middleware-manifest.cjs` – guards against missing Next middleware manifest on fresh starts
|
||||
|
||||
## Configuration
|
||||
No env vars required. Wallet connectivity is via the injected Trust Wallet provider; WalletConnect is not used.
|
||||
|
||||
## Docker
|
||||
The Dockerfile is multi-stage and uses pnpm:
|
||||
```bash
|
||||
docker build -t polynote .
|
||||
# run
|
||||
docker run -p 3000:3000 polynote
|
||||
```
|
||||
BuildKit with cache mounts is supported in the Dockerfile, but if buildx isn’t available locally, use the plain `docker build` command above.
|
||||
|
||||
## CI (Gitea actions)
|
||||
`.gitea/workflows/build.yml` runs lint on Node 22, then builds and uploads `.next/standalone` + `.next/static` + `public` as artifacts for `main` and tags.
|
||||
|
||||
## Security notes
|
||||
- Only injected providers are used; no secrets leave the browser.
|
||||
- Recipient addresses validated with `ethers.isAddress`.
|
||||
- Zero-value tx; user pays gas. The app requests a switch to Polygon (chainId 137).
|
||||
- Copy-to-clipboard is wrapped in error handling.
|
||||
- Serve over HTTPS in production so wallet and clipboard APIs work reliably.
|
||||
- Sending data to an EOA can be blocked by some wallets/RPCs; a warning is shown when you target your own address.
|
||||
|
||||
## Path aliases
|
||||
Imports under `app/` can use `@/` (configured in `tsconfig.json`):
|
||||
```ts
|
||||
import en from "@/locales/en.json";
|
||||
import { LocaleSelector } from "@/components/LocaleSelector";
|
||||
```
|
||||
|
||||
## Contributing
|
||||
PRs welcome. Run `pnpm format` and `pnpm lint` before submitting. If you add locales, extend the JSON files under `app/locales/`.
|
||||
|
||||
## License
|
||||
GPL-3.0 (see `LICENSE`). Core dependencies are permissive (MIT): Next.js, React, React DOM, ethers, Prettier, TypeScript, @types/*.
|
||||
157
app/components/LocaleSelector.tsx
Normal file
157
app/components/LocaleSelector.tsx
Normal file
@@ -0,0 +1,157 @@
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import type { KeyboardEvent } from "react";
|
||||
import type { Locale, LocaleOption } from "@/hooks/useI18n";
|
||||
|
||||
type Props = {
|
||||
locale: Locale;
|
||||
onChange: (code: Locale) => void;
|
||||
options: LocaleOption[];
|
||||
label: string;
|
||||
searchPlaceholder: string;
|
||||
};
|
||||
|
||||
export function LocaleSelector({ locale, onChange, options, label, searchPlaceholder }: Props) {
|
||||
const dropdownRef = useRef<HTMLDivElement | null>(null);
|
||||
const searchRef = useRef<HTMLInputElement | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [search, setSearch] = useState("");
|
||||
const [focusedIndex, setFocusedIndex] = useState(-1);
|
||||
|
||||
const selected = useMemo(
|
||||
() => options.find((opt) => opt.code === locale) || options[0],
|
||||
[locale, options]
|
||||
);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
const term = search.trim().toLowerCase();
|
||||
return term ? options.filter((opt) => opt.name.toLowerCase().includes(term)) : options;
|
||||
}, [options, search]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const clickHandler = (e: MouseEvent) => {
|
||||
if (dropdownRef.current && !dropdownRef.current.contains(e.target as Node)) {
|
||||
setOpen(false);
|
||||
setSearch("");
|
||||
setFocusedIndex(-1);
|
||||
}
|
||||
};
|
||||
document.addEventListener("click", clickHandler);
|
||||
setTimeout(() => searchRef.current?.focus(), 0);
|
||||
return () => document.removeEventListener("click", clickHandler);
|
||||
}, [open]);
|
||||
|
||||
const toggle = () => setOpen((prev) => !prev);
|
||||
const close = () => {
|
||||
setOpen(false);
|
||||
setSearch("");
|
||||
setFocusedIndex(-1);
|
||||
};
|
||||
|
||||
const select = (opt: LocaleOption) => {
|
||||
onChange(opt.code);
|
||||
close();
|
||||
};
|
||||
|
||||
const onKeyDownList = (e: KeyboardEvent<HTMLUListElement>) => {
|
||||
if (!open) return;
|
||||
const list = filtered;
|
||||
if (!list.length) return;
|
||||
if (e.key === "ArrowDown") {
|
||||
e.preventDefault();
|
||||
setFocusedIndex((prev) => {
|
||||
const next = (prev + 1) % list.length;
|
||||
scrollIntoView(next);
|
||||
return next;
|
||||
});
|
||||
} else if (e.key === "ArrowUp") {
|
||||
e.preventDefault();
|
||||
setFocusedIndex((prev) => {
|
||||
const next = (prev - 1 + list.length) % list.length;
|
||||
scrollIntoView(next);
|
||||
return next;
|
||||
});
|
||||
} else if (e.key === "Enter" && focusedIndex >= 0) {
|
||||
e.preventDefault();
|
||||
select(list[focusedIndex]);
|
||||
} else if (e.key === "Escape") {
|
||||
e.preventDefault();
|
||||
close();
|
||||
}
|
||||
};
|
||||
|
||||
const scrollIntoView = (index: number) => {
|
||||
requestAnimationFrame(() => {
|
||||
const items = dropdownRef.current?.querySelectorAll(".locale-panel-item");
|
||||
const el = items?.[index] as HTMLElement | undefined;
|
||||
el?.scrollIntoView({ block: "nearest" });
|
||||
});
|
||||
};
|
||||
|
||||
const handleItemKeyDown = (e: KeyboardEvent<HTMLLIElement>, opt: LocaleOption) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
select(opt);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div ref={dropdownRef} className="locale-dropdown" tabIndex={-1} role="group">
|
||||
<p className="locale-label">{label}</p>
|
||||
<button
|
||||
type="button"
|
||||
className="locale-toggle"
|
||||
aria-expanded={open}
|
||||
aria-haspopup="menu"
|
||||
onClick={toggle}
|
||||
>
|
||||
<span className="locale-flag" aria-hidden>
|
||||
{selected?.emoji}
|
||||
</span>
|
||||
<span className="locale-name">{selected?.name}</span>
|
||||
<svg
|
||||
className={`locale-arrow ${open ? "open" : ""}`}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M19 9l-7 7-7-7" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="locale-panel" role="menu" tabIndex={-1}>
|
||||
<div className="locale-panel-search">
|
||||
<input
|
||||
ref={searchRef}
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
type="text"
|
||||
placeholder={searchPlaceholder}
|
||||
/>
|
||||
</div>
|
||||
<ul className="locale-panel-list" role="menu" tabIndex={0} onKeyDown={onKeyDownList}>
|
||||
{filtered.map((opt, index) => (
|
||||
<li
|
||||
key={opt.code}
|
||||
className={`locale-panel-item ${index === focusedIndex ? "focused" : ""}`}
|
||||
role="menuitem"
|
||||
tabIndex={0}
|
||||
onClick={() => select(opt)}
|
||||
onKeyDown={(e) => handleItemKeyDown(e, opt)}
|
||||
onMouseEnter={() => setFocusedIndex(index)}
|
||||
>
|
||||
<span className="locale-item-flag" aria-hidden>
|
||||
{opt.emoji}
|
||||
</span>
|
||||
<span className="locale-item-label">{opt.name}</span>
|
||||
</li>
|
||||
))}
|
||||
{filtered.length === 0 && <li className="locale-no-results">No languages found.</li>}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
617
app/globals.css
Normal file
617
app/globals.css
Normal file
@@ -0,0 +1,617 @@
|
||||
@import url("https://fonts.googleapis.com/css2?family=Sora:wght@400;500;600;700&display=swap");
|
||||
|
||||
:root {
|
||||
--bg-1: #f1f6ff;
|
||||
--bg-2: #fff4e6;
|
||||
--ink: #0f172a;
|
||||
--muted: #5c677d;
|
||||
--card: rgba(255, 255, 255, 0.9);
|
||||
--surface: #ffffff;
|
||||
--surface-soft: #f7fbff;
|
||||
--surface-secondary: #fff8ed;
|
||||
--border: #d8deea;
|
||||
--accent: #0ea5e9;
|
||||
--accent-strong: #0f766e;
|
||||
--pill: #e1f6ff;
|
||||
--pill-border: #c7ecff;
|
||||
--pill-text: #0f4c5c;
|
||||
--live-ok-bg: #e6ffe8;
|
||||
--live-ok-border: #c4f0d0;
|
||||
--live-ok-text: #0f6d2f;
|
||||
--shadow: 0 12px 60px rgba(15, 23, 42, 0.14);
|
||||
--link: #0ea5e9;
|
||||
--link-disabled: #94a3b8;
|
||||
--status-ok-bg: #e9fff2;
|
||||
--status-ok-border: #c1f3d7;
|
||||
--status-error-bg: #fff2ed;
|
||||
--status-error-border: #ffd2c8;
|
||||
}
|
||||
|
||||
[data-theme="dark"] {
|
||||
--bg-1: #0f172a;
|
||||
--bg-2: #111827;
|
||||
--ink: #e5e7eb;
|
||||
--muted: #a5b4c6;
|
||||
--card: rgba(24, 32, 48, 0.9);
|
||||
--surface: #0f172a;
|
||||
--surface-soft: #1f2937;
|
||||
--surface-secondary: #1c2432;
|
||||
--border: #1f2a3a;
|
||||
--accent: #22d3ee;
|
||||
--accent-strong: #10b981;
|
||||
--pill: #142337;
|
||||
--pill-border: #1f3a5f;
|
||||
--pill-text: #c7e1ff;
|
||||
--live-ok-bg: #15392a;
|
||||
--live-ok-border: #1e4f37;
|
||||
--live-ok-text: #bef0d2;
|
||||
--shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
|
||||
--link: #7dd3fc;
|
||||
--link-disabled: #475569;
|
||||
--status-ok-bg: #102b1f;
|
||||
--status-ok-border: #1e4f37;
|
||||
--status-error-bg: #321717;
|
||||
--status-error-border: #6b2727;
|
||||
}
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
background: radial-gradient(120% 120% at 20% 20%, rgba(14, 165, 233, 0.18), transparent),
|
||||
radial-gradient(80% 80% at 80% 0%, rgba(255, 159, 67, 0.16), transparent),
|
||||
linear-gradient(135deg, var(--bg-1), var(--bg-2));
|
||||
font-family: "Sora", "Segoe UI", -apple-system, sans-serif;
|
||||
color: var(--ink);
|
||||
padding: 32px;
|
||||
}
|
||||
|
||||
.page {
|
||||
max-width: 1100px;
|
||||
margin: 0 auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.hero {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.hero-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.hero-text {
|
||||
flex: 1 1 320px;
|
||||
}
|
||||
|
||||
.hero-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: flex-start;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.eyebrow {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 10px;
|
||||
background: rgba(255, 255, 255, 0.7);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 999px;
|
||||
color: var(--muted);
|
||||
width: fit-content;
|
||||
font-size: 13px;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
font-size: 32px;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.hero-topline {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.logo-mark {
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
border-radius: 12px;
|
||||
box-shadow: var(--shadow);
|
||||
background: var(--surface);
|
||||
}
|
||||
|
||||
.lede {
|
||||
margin: 0;
|
||||
color: var(--muted);
|
||||
max-width: 760px;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--card);
|
||||
border-radius: 18px;
|
||||
border: 1px solid var(--border);
|
||||
box-shadow: var(--shadow);
|
||||
padding: 18px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
backdrop-filter: blur(8px);
|
||||
}
|
||||
|
||||
.card-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.label {
|
||||
margin: 0;
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.muted {
|
||||
margin: 4px 0 0;
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.stack {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
input,
|
||||
textarea {
|
||||
width: 100%;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 12px 14px;
|
||||
font: inherit;
|
||||
transition: border-color 0.2s ease, box-shadow 0.2s ease;
|
||||
background: var(--surface);
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
input:focus,
|
||||
textarea:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.12);
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.input-label {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.button-row {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
button {
|
||||
border: none;
|
||||
border-radius: 12px;
|
||||
padding: 12px 14px;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.primary {
|
||||
background: linear-gradient(135deg, var(--accent), #22c55e);
|
||||
color: #fff;
|
||||
box-shadow: 0 10px 30px rgba(14, 165, 233, 0.3);
|
||||
}
|
||||
|
||||
.ghost {
|
||||
background: transparent;
|
||||
color: var(--ink);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
button:hover:not(:disabled) {
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.meta {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
|
||||
gap: 10px 18px;
|
||||
padding: 12px;
|
||||
border-radius: 12px;
|
||||
background: var(--surface-soft);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.meta dt {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.meta dd {
|
||||
margin: 0;
|
||||
font-weight: 600;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.pill {
|
||||
padding: 8px 12px;
|
||||
border-radius: 999px;
|
||||
font-weight: 600;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.pill-quiet {
|
||||
background: var(--pill);
|
||||
color: var(--pill-text);
|
||||
border: 1px solid var(--pill-border);
|
||||
}
|
||||
|
||||
.pill-live {
|
||||
background: var(--live-ok-bg);
|
||||
color: var(--live-ok-text);
|
||||
border: 1px solid var(--live-ok-border);
|
||||
}
|
||||
|
||||
.status-card .status-line {
|
||||
padding: 12px;
|
||||
border-radius: 12px;
|
||||
border: 1px dashed var(--border);
|
||||
background: var(--surface-soft);
|
||||
font-weight: 600;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.status-card .secondary {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-weight: 500;
|
||||
background: var(--surface-secondary);
|
||||
}
|
||||
|
||||
.status-card .dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 999px;
|
||||
background: #f59e0b;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.hint {
|
||||
margin: 0;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.status-card .hint {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.tx-box {
|
||||
padding: 12px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--surface);
|
||||
}
|
||||
|
||||
.hash {
|
||||
font-family: "SFMono-Regular", "JetBrains Mono", "Fira Code", monospace;
|
||||
word-break: break-all;
|
||||
margin: 6px 0;
|
||||
}
|
||||
|
||||
.tx-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.copy-btn {
|
||||
padding: 8px 10px;
|
||||
}
|
||||
|
||||
.link {
|
||||
color: var(--link);
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.link.disabled {
|
||||
pointer-events: none;
|
||||
color: var(--link-disabled);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.locale-dropdown {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
min-width: 180px;
|
||||
}
|
||||
|
||||
.locale-label {
|
||||
margin: 0;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.locale-toggle {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 999px;
|
||||
padding: 10px 12px;
|
||||
cursor: pointer;
|
||||
transition: box-shadow 0.2s, background 0.2s;
|
||||
}
|
||||
|
||||
.locale-toggle:hover {
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.locale-toggle:focus {
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.12);
|
||||
}
|
||||
|
||||
.locale-flag {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--surface-soft);
|
||||
border-radius: 50%;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.locale-name {
|
||||
font-weight: 600;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.locale-arrow {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
color: #6366f1;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.locale-arrow.open {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.locale-panel {
|
||||
position: absolute;
|
||||
top: calc(100% + 6px);
|
||||
right: 0;
|
||||
background: var(--card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 14px;
|
||||
box-shadow: var(--shadow);
|
||||
overflow: hidden;
|
||||
z-index: 20;
|
||||
min-width: 220px;
|
||||
}
|
||||
|
||||
.locale-panel-search {
|
||||
padding: 8px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.locale-panel-search input {
|
||||
width: 100%;
|
||||
padding: 8px 10px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.locale-panel-search input:focus {
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
|
||||
}
|
||||
|
||||
.locale-panel-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 6px 0;
|
||||
max-height: 240px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.locale-panel-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 8px 12px;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s;
|
||||
}
|
||||
|
||||
.locale-panel-item:hover,
|
||||
.locale-panel-item.focused {
|
||||
background: var(--surface-soft);
|
||||
}
|
||||
|
||||
.locale-item-flag {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.locale-item-label {
|
||||
font-size: 14px;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.locale-no-results {
|
||||
padding: 10px 12px;
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.status-ok {
|
||||
border-color: var(--status-ok-border) !important;
|
||||
background: var(--status-ok-bg) !important;
|
||||
}
|
||||
|
||||
.status-error {
|
||||
border-color: var(--status-error-border) !important;
|
||||
background: var(--status-error-bg) !important;
|
||||
}
|
||||
|
||||
.theme-toggle {
|
||||
min-width: 160px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.history {
|
||||
margin-top: 12px;
|
||||
padding: 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
background: var(--surface);
|
||||
}
|
||||
|
||||
.history-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.history-empty {
|
||||
margin: 8px 0 0;
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.history-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 10px 0 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.history-item {
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
padding: 10px;
|
||||
background: var(--surface-soft);
|
||||
}
|
||||
|
||||
.history-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.history-time {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.history-meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
margin: 6px 0;
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.history-message {
|
||||
font-weight: 600;
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
.history-hash {
|
||||
font-family: "SFMono-Regular", "JetBrains Mono", "Fira Code", monospace;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
body {
|
||||
padding: 18px;
|
||||
}
|
||||
|
||||
.card-head {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.button-row {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.hero-row {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.locale-dropdown {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
77
app/hooks/useI18n.ts
Normal file
77
app/hooks/useI18n.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import de from "@/locales/de.json";
|
||||
import en from "@/locales/en.json";
|
||||
import es from "@/locales/es.json";
|
||||
import fr from "@/locales/fr.json";
|
||||
import it from "@/locales/it.json";
|
||||
import sv from "@/locales/sv.json";
|
||||
|
||||
const bundles = { en, es, fr, de, it, sv } as const;
|
||||
|
||||
export type Locale = keyof typeof bundles;
|
||||
export type MessageKey = string;
|
||||
|
||||
export type LocaleOption = {
|
||||
code: Locale;
|
||||
name: string;
|
||||
emoji: string;
|
||||
};
|
||||
|
||||
const localeOptions: LocaleOption[] = [
|
||||
{ code: "en", name: "English", emoji: "🇺🇸" },
|
||||
{ code: "es", name: "Español", emoji: "🇪🇸" },
|
||||
{ code: "fr", name: "Français", emoji: "🇫🇷" },
|
||||
{ code: "de", name: "Deutsch", emoji: "🇩🇪" },
|
||||
{ code: "it", name: "Italiano", emoji: "🇮🇹" },
|
||||
{ code: "sv", name: "Svenska", emoji: "🇸🇪" },
|
||||
];
|
||||
|
||||
export function useI18n(defaultLocale: Locale = "en") {
|
||||
const [locale, setLocale] = useState<Locale>(defaultLocale);
|
||||
const hasDetectedLocale = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (hasDetectedLocale.current) return;
|
||||
hasDetectedLocale.current = true;
|
||||
const navLangs =
|
||||
typeof navigator !== "undefined" ? navigator.languages || [navigator.language] : [];
|
||||
const mapToLocale = (lang: string | undefined | null): Locale | null => {
|
||||
if (!lang) return null;
|
||||
const lower = lang.toLowerCase();
|
||||
if (lower.startsWith("es")) return "es";
|
||||
if (lower.startsWith("fr")) return "fr";
|
||||
if (lower.startsWith("de")) return "de";
|
||||
if (lower.startsWith("it")) return "it";
|
||||
if (lower.startsWith("sv")) return "sv";
|
||||
if (lower.startsWith("en")) return "en";
|
||||
return null;
|
||||
};
|
||||
const detected = navLangs.map((l) => mapToLocale(l)).find(Boolean);
|
||||
if (detected && detected !== locale) {
|
||||
setLocale(detected);
|
||||
}
|
||||
}, [locale]);
|
||||
|
||||
const t = useCallback(
|
||||
(key: MessageKey, vars?: Record<string, string>): string => {
|
||||
const parts = key.split(".");
|
||||
const dict = bundles[locale] ?? bundles.en;
|
||||
const fallbackDict = bundles.en;
|
||||
const resolveKey = (source: unknown) =>
|
||||
parts.reduce<unknown>(
|
||||
(acc, part) =>
|
||||
acc && typeof acc === "object" ? (acc as Record<string, unknown>)[part] : undefined,
|
||||
source
|
||||
);
|
||||
const value = resolveKey(dict) ?? resolveKey(fallbackDict);
|
||||
const text = typeof value === "string" ? value : key;
|
||||
if (!vars) return text;
|
||||
return text.replace(/\{(\w+)\}/g, (_: string, k: string) => (vars[k] ? vars[k] : `{${k}}`));
|
||||
},
|
||||
[locale]
|
||||
);
|
||||
|
||||
const options = useMemo(() => localeOptions, []);
|
||||
|
||||
return { locale, setLocale, t, localeOptions: options };
|
||||
}
|
||||
38
app/hooks/useTheme.ts
Normal file
38
app/hooks/useTheme.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export type Theme = "light" | "dark";
|
||||
|
||||
export function useTheme(initial?: Theme) {
|
||||
const [theme, setTheme] = useState<Theme>(initial ?? "light");
|
||||
|
||||
useEffect(() => {
|
||||
const stored =
|
||||
typeof window !== "undefined" && "localStorage" in window
|
||||
? window.localStorage.getItem("theme")
|
||||
: null;
|
||||
if (stored === "light" || stored === "dark") {
|
||||
setTheme(stored);
|
||||
return;
|
||||
}
|
||||
if (typeof window !== "undefined" && "matchMedia" in window) {
|
||||
const media = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
setTheme(media.matches ? "dark" : "light");
|
||||
const handler = (event: MediaQueryListEvent) => setTheme(event.matches ? "dark" : "light");
|
||||
media.addEventListener("change", handler);
|
||||
return () => media.removeEventListener("change", handler);
|
||||
}
|
||||
setTheme("light");
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof document === "undefined") return;
|
||||
document.documentElement.setAttribute("data-theme", theme);
|
||||
if ("localStorage" in window) {
|
||||
window.localStorage.setItem("theme", theme);
|
||||
}
|
||||
}, [theme]);
|
||||
|
||||
const toggleTheme = () => setTheme((prev) => (prev === "light" ? "dark" : "light"));
|
||||
|
||||
return { theme, setTheme, toggleTheme };
|
||||
}
|
||||
76
app/layout.tsx
Normal file
76
app/layout.tsx
Normal file
@@ -0,0 +1,76 @@
|
||||
import type { Metadata } from "next";
|
||||
import { headers } from "next/headers";
|
||||
import type { ReactNode } from "react";
|
||||
import de from "@/locales/de.json";
|
||||
import en from "@/locales/en.json";
|
||||
import es from "@/locales/es.json";
|
||||
import fr from "@/locales/fr.json";
|
||||
import it from "@/locales/it.json";
|
||||
import sv from "@/locales/sv.json";
|
||||
import "./globals.css";
|
||||
|
||||
type Locale = "en" | "es" | "fr" | "de" | "it" | "sv";
|
||||
|
||||
const descriptions: Record<Locale, string> = {
|
||||
en: en.hero.lede,
|
||||
es: es.hero.lede,
|
||||
fr: fr.hero.lede,
|
||||
de: de.hero.lede,
|
||||
it: it.hero.lede,
|
||||
sv: sv.hero.lede,
|
||||
};
|
||||
|
||||
async function pickLocaleFromHeaders(): Promise<Locale> {
|
||||
const hdrs = await headers();
|
||||
const accept = hdrs.get("accept-language") || "";
|
||||
const entries = accept.split(",").map((entry) => entry.trim().toLowerCase());
|
||||
const match = entries.find((entry) =>
|
||||
["es", "fr", "de", "it", "sv", "en"].some((code) => entry.startsWith(code))
|
||||
);
|
||||
if (!match) return "en";
|
||||
if (match.startsWith("es")) return "es";
|
||||
if (match.startsWith("fr")) return "fr";
|
||||
if (match.startsWith("de")) return "de";
|
||||
if (match.startsWith("it")) return "it";
|
||||
if (match.startsWith("sv")) return "sv";
|
||||
return "en";
|
||||
}
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const locale = await pickLocaleFromHeaders();
|
||||
return {
|
||||
title: "PolyNote",
|
||||
description: descriptions[locale] ?? descriptions.en,
|
||||
metadataBase: new URL("https://polynote.wittrail.com"),
|
||||
openGraph: {
|
||||
title: "PolyNote",
|
||||
description: descriptions[locale] ?? descriptions.en,
|
||||
url: "https://polynote.wittrail.com",
|
||||
siteName: "PolyNote",
|
||||
images: [
|
||||
{
|
||||
url: "/logo.svg",
|
||||
width: 256,
|
||||
height: 256,
|
||||
alt: "PolyNote logo",
|
||||
},
|
||||
],
|
||||
locale,
|
||||
type: "website",
|
||||
},
|
||||
icons: {
|
||||
icon: "/favicon.ico",
|
||||
shortcut: "/favicon.ico",
|
||||
apple: "/favicon.png",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default async function RootLayout({ children }: { children: ReactNode }) {
|
||||
const locale = await pickLocaleFromHeaders();
|
||||
return (
|
||||
<html lang={locale}>
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
83
app/locales/de.json
Normal file
83
app/locales/de.json
Normal file
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"locale": {
|
||||
"label": "Sprache",
|
||||
"search": "Sprache suchen..."
|
||||
},
|
||||
"theme": {
|
||||
"toggle": "Thema wechseln",
|
||||
"dark": "Dunkler Modus",
|
||||
"light": "Heller Modus"
|
||||
},
|
||||
"hero": {
|
||||
"eyebrow": "Eingebettetes Trust Wallet • Polygon Mainnet",
|
||||
"title": "PolyNote · Trust Wallet zu Polygon",
|
||||
"lede": "Verbinde dich mit der Trust-Wallet-Erweiterung oder dem In-App-Browser. Wir kodieren deinen Text in Hex und senden eine Null-MATIC-Transaktion auf Polygon – nur Gasgebühren fallen an."
|
||||
},
|
||||
"connection": {
|
||||
"title": "Verbindung",
|
||||
"subtitle": "Eingebettetes Trust Wallet (Browser-Erweiterung oder In-App dApp Browser).",
|
||||
"pill": "Nur Polygon",
|
||||
"connect": "Trust Wallet verbinden",
|
||||
"disconnect": "Trennen",
|
||||
"account": "Konto",
|
||||
"chain": "Netzwerk",
|
||||
"status": "Status",
|
||||
"connected": "Verbunden",
|
||||
"notConnected": "Nicht verbunden"
|
||||
},
|
||||
"compose": {
|
||||
"title": "Nachricht verfassen",
|
||||
"subtitle": "Wir kodieren deinen Text in Hex und senden eine 0 MATIC Transaktion mit diesem Payload.",
|
||||
"recipientLabel": "Zieladresse",
|
||||
"recipientHint": "(standardmäßig deine eigene Wallet)",
|
||||
"messageLabel": "Nachricht einbetten",
|
||||
"messagePlaceholder": "Bis zu 280 Zeichen eingeben...",
|
||||
"messageHint": "Wir wandeln dies in Hex um und fügen es in das Datenfeld ein.",
|
||||
"send": "Nachrichten-Transaktion senden",
|
||||
"sending": "Senden…"
|
||||
},
|
||||
"live": {
|
||||
"title": "Live-Feedback",
|
||||
"subtitle": "Wir halten dich über jeden Schritt auf dem Laufenden.",
|
||||
"chainReady": "Auf Polygon Mainnet und bereit.",
|
||||
"chainRequired": "Polygon Mainnet erforderlich.",
|
||||
"lastTx": "Letzter Transaktions-Hash",
|
||||
"trackHint": "Du kannst sie in deiner Wallet oder auf Polygonscan verfolgen.",
|
||||
"viewOnPolygonscan": "In Polygonscan öffnen",
|
||||
"copy": "Hash kopieren",
|
||||
"copySuccess": "Transaktions-Hash kopiert.",
|
||||
"copyFailed": "Hash konnte nicht kopiert werden. Kopiere ihn manuell."
|
||||
},
|
||||
"history": {
|
||||
"title": "Letzte Nachrichten",
|
||||
"subtitle": "Nachrichten, die du in dieser Sitzung gesendet hast.",
|
||||
"empty": "Noch keine Nachrichten.",
|
||||
"sent": "Gesendet",
|
||||
"from": "Von",
|
||||
"to": "An"
|
||||
},
|
||||
"status": {
|
||||
"waiting": "Warten auf Verbindung…",
|
||||
"preparingConnect": "Verbindung wird vorbereitet…",
|
||||
"requesting": "Wallet-Zugriff wird angefordert…",
|
||||
"connectedInjected": "Über eingebetteten Provider verbunden. Du kannst jetzt eine Polygon-Nachricht senden.",
|
||||
"connectFirst": "Verbinde zuerst deine Wallet.",
|
||||
"messageEmpty": "Nachricht darf nicht leer sein.",
|
||||
"recipientInvalid": "Empfänger muss eine gültige Adresse sein.",
|
||||
"switchPolygon": "Bitte wechsel in deiner Wallet zu Polygon Mainnet.",
|
||||
"prepareTx": "Gas wird geschätzt und Transaktion vorbereitet…",
|
||||
"gasFallback": "Gas-Schätzung fehlgeschlagen; verwende ein Fallback-Limit und sende trotzdem.",
|
||||
"feeFallback": "Gebühren konnten nicht geholt werden; neuer Versuch mit Legacy-Gaspreis.",
|
||||
"eoaWarning": "Warnung: Daten an eine EOA zu senden kann bei manchen Wallets/RPCs scheitern.",
|
||||
"submitted": "Transaktion gesendet. Hash: {hash}",
|
||||
"onchain": "Nachricht ist on-chain. Prüfe sie in deiner Wallet oder auf Polygonscan.",
|
||||
"rejected": "Anfrage in der Wallet abgelehnt.",
|
||||
"disconnected": "Getrennt."
|
||||
},
|
||||
"errors": {
|
||||
"noWallet": "Keine eingebettete Wallet gefunden. Verwende die Trust-Wallet-Erweiterung oder den In-App-Browser.",
|
||||
"noAccounts": "Die Wallet hat keine Konten zurückgegeben.",
|
||||
"sendFailed": "Nachrichten-Transaktion konnte nicht gesendet werden.",
|
||||
"connectionFailed": "Verbindung fehlgeschlagen."
|
||||
}
|
||||
}
|
||||
83
app/locales/en.json
Normal file
83
app/locales/en.json
Normal file
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"locale": {
|
||||
"label": "Language",
|
||||
"search": "Search language..."
|
||||
},
|
||||
"theme": {
|
||||
"toggle": "Toggle theme",
|
||||
"dark": "Dark mode",
|
||||
"light": "Light mode"
|
||||
},
|
||||
"hero": {
|
||||
"eyebrow": "Injected Trust Wallet • Polygon mainnet",
|
||||
"title": "PolyNote · Trust Wallet to Polygon",
|
||||
"lede": "Connect with the Trust Wallet extension or the in-app browser. We hex-encode your text and submit a zero-value Polygon transaction that only costs gas."
|
||||
},
|
||||
"connection": {
|
||||
"title": "Connection",
|
||||
"subtitle": "Injected Trust Wallet (browser extension or in-app dApp browser).",
|
||||
"pill": "Polygon only",
|
||||
"connect": "Connect Trust Wallet",
|
||||
"disconnect": "Disconnect",
|
||||
"account": "Account",
|
||||
"chain": "Chain",
|
||||
"status": "Status",
|
||||
"connected": "Connected",
|
||||
"notConnected": "Not connected"
|
||||
},
|
||||
"compose": {
|
||||
"title": "Compose message",
|
||||
"subtitle": "We hex-encode your text and send a 0 MATIC transaction carrying that payload.",
|
||||
"recipientLabel": "Recipient address",
|
||||
"recipientHint": "(defaults to your own wallet)",
|
||||
"messageLabel": "Message to embed",
|
||||
"messagePlaceholder": "Type up to 280 characters...",
|
||||
"messageHint": "We will convert this to hex and attach it to the transaction data field.",
|
||||
"send": "Send message transaction",
|
||||
"sending": "Sending…"
|
||||
},
|
||||
"live": {
|
||||
"title": "Live feedback",
|
||||
"subtitle": "We keep you posted through each step.",
|
||||
"chainReady": "On Polygon mainnet and ready.",
|
||||
"chainRequired": "Polygon mainnet required.",
|
||||
"lastTx": "Last transaction hash",
|
||||
"trackHint": "You can track it in your wallet or on Polygonscan.",
|
||||
"viewOnPolygonscan": "Open in Polygonscan",
|
||||
"copy": "Copy hash",
|
||||
"copySuccess": "Transaction hash copied.",
|
||||
"copyFailed": "Could not copy hash. Copy it manually."
|
||||
},
|
||||
"history": {
|
||||
"title": "Recent messages",
|
||||
"subtitle": "Messages you sent in this session.",
|
||||
"empty": "No messages yet.",
|
||||
"sent": "Sent",
|
||||
"from": "From",
|
||||
"to": "To"
|
||||
},
|
||||
"status": {
|
||||
"waiting": "Waiting to connect…",
|
||||
"preparingConnect": "Preparing to connect…",
|
||||
"requesting": "Requesting wallet access…",
|
||||
"connectedInjected": "Connected via injected provider. You can send a Polygon message now.",
|
||||
"connectFirst": "Connect your wallet first.",
|
||||
"messageEmpty": "Message cannot be empty.",
|
||||
"recipientInvalid": "Recipient must be a valid address.",
|
||||
"switchPolygon": "Please switch to Polygon mainnet in your wallet.",
|
||||
"prepareTx": "Estimating gas and preparing transaction…",
|
||||
"gasFallback": "Gas estimation failed; using a fallback limit and sending anyway.",
|
||||
"feeFallback": "Fee data failed; retrying with a legacy gas price.",
|
||||
"eoaWarning": "Warning: sending data to an EOA can fail in some wallets/RPCs.",
|
||||
"submitted": "Transaction submitted. Hash: {hash}",
|
||||
"onchain": "Message is on-chain. Check your wallet or Polygonscan.",
|
||||
"rejected": "Request rejected in wallet.",
|
||||
"disconnected": "Disconnected."
|
||||
},
|
||||
"errors": {
|
||||
"noWallet": "No injected wallet found. Try the Trust Wallet extension or app browser.",
|
||||
"noAccounts": "No accounts returned from injected wallet.",
|
||||
"sendFailed": "Failed to send message transaction.",
|
||||
"connectionFailed": "Connection failed."
|
||||
}
|
||||
}
|
||||
83
app/locales/es.json
Normal file
83
app/locales/es.json
Normal file
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"locale": {
|
||||
"label": "Idioma",
|
||||
"search": "Buscar idioma..."
|
||||
},
|
||||
"theme": {
|
||||
"toggle": "Cambiar tema",
|
||||
"dark": "Modo oscuro",
|
||||
"light": "Modo claro"
|
||||
},
|
||||
"hero": {
|
||||
"eyebrow": "Trust Wallet inyectado • Polygon mainnet",
|
||||
"title": "PolyNote · Trust Wallet a Polygon",
|
||||
"lede": "Conecta con la extensión de Trust Wallet o el navegador dentro de la app. Codificamos tu texto en hex y enviamos una transacción de valor cero en Polygon; solo pagas gas."
|
||||
},
|
||||
"connection": {
|
||||
"title": "Conexión",
|
||||
"subtitle": "Trust Wallet inyectado (extensión o navegador dentro de la app).",
|
||||
"pill": "Solo Polygon",
|
||||
"connect": "Conectar Trust Wallet",
|
||||
"disconnect": "Desconectar",
|
||||
"account": "Cuenta",
|
||||
"chain": "Red",
|
||||
"status": "Estado",
|
||||
"connected": "Conectado",
|
||||
"notConnected": "No conectado"
|
||||
},
|
||||
"compose": {
|
||||
"title": "Redactar mensaje",
|
||||
"subtitle": "Codificamos tu texto en hex y enviamos una transacción de 0 MATIC con ese payload.",
|
||||
"recipientLabel": "Dirección de destino",
|
||||
"recipientHint": "(por defecto tu propia wallet)",
|
||||
"messageLabel": "Mensaje a incrustar",
|
||||
"messagePlaceholder": "Escribe hasta 280 caracteres...",
|
||||
"messageHint": "Convertiremos esto a hex y lo pondremos en el campo data.",
|
||||
"send": "Enviar transacción con mensaje",
|
||||
"sending": "Enviando…"
|
||||
},
|
||||
"live": {
|
||||
"title": "Estado en vivo",
|
||||
"subtitle": "Te avisamos en cada paso.",
|
||||
"chainReady": "En Polygon mainnet, listo.",
|
||||
"chainRequired": "Se requiere Polygon mainnet.",
|
||||
"lastTx": "Último hash de transacción",
|
||||
"trackHint": "Puedes rastrearlo en tu wallet o Polygonscan.",
|
||||
"viewOnPolygonscan": "Abrir en Polygonscan",
|
||||
"copy": "Copiar hash",
|
||||
"copySuccess": "Hash de transacción copiado.",
|
||||
"copyFailed": "No se pudo copiar el hash. Hazlo manualmente."
|
||||
},
|
||||
"history": {
|
||||
"title": "Mensajes recientes",
|
||||
"subtitle": "Mensajes que enviaste en esta sesión.",
|
||||
"empty": "Aún no hay mensajes.",
|
||||
"sent": "Enviado",
|
||||
"from": "De",
|
||||
"to": "Para"
|
||||
},
|
||||
"status": {
|
||||
"waiting": "Esperando conexión…",
|
||||
"preparingConnect": "Preparando conexión…",
|
||||
"requesting": "Solicitando acceso a la wallet…",
|
||||
"connectedInjected": "Conectado con proveedor inyectado. Ya puedes enviar un mensaje en Polygon.",
|
||||
"connectFirst": "Conecta tu wallet primero.",
|
||||
"messageEmpty": "El mensaje no puede estar vacío.",
|
||||
"recipientInvalid": "El destinatario debe ser una dirección válida.",
|
||||
"switchPolygon": "Cambia a Polygon mainnet en tu wallet.",
|
||||
"prepareTx": "Calculando gas y preparando la transacción…",
|
||||
"gasFallback": "La estimación de gas falló; usamos un límite por defecto e igualmente enviamos.",
|
||||
"feeFallback": "No se pudieron obtener las tarifas; reintentamos con gas price legado.",
|
||||
"eoaWarning": "Aviso: enviar datos a una EOA puede fallar en algunas wallets/RPCs.",
|
||||
"submitted": "Transacción enviada. Hash: {hash}",
|
||||
"onchain": "El mensaje está on-chain. Revísalo en tu wallet o Polygonscan.",
|
||||
"rejected": "Solicitud rechazada en la wallet.",
|
||||
"disconnected": "Desconectado."
|
||||
},
|
||||
"errors": {
|
||||
"noWallet": "No se encontró una wallet inyectada. Usa la extensión de Trust Wallet o el navegador de la app.",
|
||||
"noAccounts": "La wallet no devolvió cuentas.",
|
||||
"sendFailed": "No se pudo enviar la transacción con mensaje.",
|
||||
"connectionFailed": "Fallo de conexión."
|
||||
}
|
||||
}
|
||||
83
app/locales/fr.json
Normal file
83
app/locales/fr.json
Normal file
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"locale": {
|
||||
"label": "Langue",
|
||||
"search": "Rechercher une langue..."
|
||||
},
|
||||
"theme": {
|
||||
"toggle": "Changer de thème",
|
||||
"dark": "Mode sombre",
|
||||
"light": "Mode clair"
|
||||
},
|
||||
"hero": {
|
||||
"eyebrow": "Trust Wallet injecté • Polygon mainnet",
|
||||
"title": "PolyNote · Trust Wallet vers Polygon",
|
||||
"lede": "Connecte-toi avec l’extension Trust Wallet ou le navigateur intégré. Nous encodons ton texte en hex et envoyons une transaction à 0 MATIC sur Polygon ; seuls les frais de gas sont dus."
|
||||
},
|
||||
"connection": {
|
||||
"title": "Connexion",
|
||||
"subtitle": "Trust Wallet injecté (extension navigateur ou navigateur dApp intégré).",
|
||||
"pill": "Polygon uniquement",
|
||||
"connect": "Connecter Trust Wallet",
|
||||
"disconnect": "Déconnecter",
|
||||
"account": "Compte",
|
||||
"chain": "Réseau",
|
||||
"status": "Statut",
|
||||
"connected": "Connecté",
|
||||
"notConnected": "Non connecté"
|
||||
},
|
||||
"compose": {
|
||||
"title": "Composer un message",
|
||||
"subtitle": "Nous encodons ton texte en hex et envoyons une transaction de 0 MATIC avec cette donnée.",
|
||||
"recipientLabel": "Adresse de destination",
|
||||
"recipientHint": "(par défaut ta propre wallet)",
|
||||
"messageLabel": "Message à intégrer",
|
||||
"messagePlaceholder": "Saisis jusqu’à 280 caractères...",
|
||||
"messageHint": "Nous convertissons en hex et plaçons cela dans le champ data.",
|
||||
"send": "Envoyer la transaction message",
|
||||
"sending": "Envoi…"
|
||||
},
|
||||
"live": {
|
||||
"title": "Retour en direct",
|
||||
"subtitle": "Nous te tenons informé à chaque étape.",
|
||||
"chainReady": "Sur Polygon mainnet, prêt.",
|
||||
"chainRequired": "Polygon mainnet requis.",
|
||||
"lastTx": "Dernier hash de transaction",
|
||||
"trackHint": "Suis-la dans ta wallet ou sur Polygonscan.",
|
||||
"viewOnPolygonscan": "Ouvrir dans Polygonscan",
|
||||
"copy": "Copier le hash",
|
||||
"copySuccess": "Hash de transaction copié.",
|
||||
"copyFailed": "Impossible de copier le hash. Copie-le manuellement."
|
||||
},
|
||||
"history": {
|
||||
"title": "Messages récents",
|
||||
"subtitle": "Messages envoyés pendant cette session.",
|
||||
"empty": "Pas encore de messages.",
|
||||
"sent": "Envoyé",
|
||||
"from": "De",
|
||||
"to": "À"
|
||||
},
|
||||
"status": {
|
||||
"waiting": "En attente de connexion…",
|
||||
"preparingConnect": "Préparation de la connexion…",
|
||||
"requesting": "Demande d’accès à la wallet…",
|
||||
"connectedInjected": "Connecté via le provider injecté. Tu peux envoyer un message sur Polygon.",
|
||||
"connectFirst": "Connecte d’abord ta wallet.",
|
||||
"messageEmpty": "Le message ne peut pas être vide.",
|
||||
"recipientInvalid": "Le destinataire doit être une adresse valide.",
|
||||
"switchPolygon": "Passe sur Polygon mainnet dans ta wallet.",
|
||||
"prepareTx": "Estimation du gas et préparation de la transaction…",
|
||||
"gasFallback": "Échec de l’estimation du gas ; utilisation d’une limite de secours.",
|
||||
"feeFallback": "Impossible de récupérer les frais ; nouvel essai avec un gas price legacy.",
|
||||
"eoaWarning": "Attention : envoyer des données à une EOA peut échouer selon les wallets/RPC.",
|
||||
"submitted": "Transaction envoyée. Hash : {hash}",
|
||||
"onchain": "Message on-chain. Vérifie dans ta wallet ou sur Polygonscan.",
|
||||
"rejected": "Demande rejetée dans la wallet.",
|
||||
"disconnected": "Déconnecté."
|
||||
},
|
||||
"errors": {
|
||||
"noWallet": "Aucune wallet injectée trouvée. Utilise l’extension Trust Wallet ou le navigateur de l’app.",
|
||||
"noAccounts": "La wallet n’a renvoyé aucun compte.",
|
||||
"sendFailed": "Impossible d’envoyer la transaction message.",
|
||||
"connectionFailed": "Échec de connexion."
|
||||
}
|
||||
}
|
||||
83
app/locales/it.json
Normal file
83
app/locales/it.json
Normal file
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"locale": {
|
||||
"label": "Lingua",
|
||||
"search": "Cerca lingua..."
|
||||
},
|
||||
"theme": {
|
||||
"toggle": "Cambia tema",
|
||||
"dark": "Modalità scura",
|
||||
"light": "Modalità chiara"
|
||||
},
|
||||
"hero": {
|
||||
"eyebrow": "Trust Wallet iniettato • Polygon mainnet",
|
||||
"title": "PolyNote · Trust Wallet su Polygon",
|
||||
"lede": "Connetti con l’estensione di Trust Wallet o il browser integrato. Codifichiamo il testo in hex e inviamo una transazione a 0 MATIC su Polygon; paghi solo il gas."
|
||||
},
|
||||
"connection": {
|
||||
"title": "Connessione",
|
||||
"subtitle": "Trust Wallet iniettato (estensione o browser dApp integrato).",
|
||||
"pill": "Solo Polygon",
|
||||
"connect": "Connetti Trust Wallet",
|
||||
"disconnect": "Disconnetti",
|
||||
"account": "Account",
|
||||
"chain": "Rete",
|
||||
"status": "Stato",
|
||||
"connected": "Connesso",
|
||||
"notConnected": "Non connesso"
|
||||
},
|
||||
"compose": {
|
||||
"title": "Scrivi il messaggio",
|
||||
"subtitle": "Codifichiamo il testo in hex e inviamo una transazione da 0 MATIC con quel payload.",
|
||||
"recipientLabel": "Indirizzo destinatario",
|
||||
"recipientHint": "(di default il tuo wallet)",
|
||||
"messageLabel": "Messaggio da includere",
|
||||
"messagePlaceholder": "Scrivi fino a 280 caratteri...",
|
||||
"messageHint": "Lo convertiremo in hex e lo inseriremo nel campo data.",
|
||||
"send": "Invia transazione con messaggio",
|
||||
"sending": "Invio…"
|
||||
},
|
||||
"live": {
|
||||
"title": "Aggiornamenti in tempo reale",
|
||||
"subtitle": "Ti aggiorniamo a ogni passo.",
|
||||
"chainReady": "Su Polygon mainnet, pronto.",
|
||||
"chainRequired": "Polygon mainnet necessario.",
|
||||
"lastTx": "Ultimo hash di transazione",
|
||||
"trackHint": "Puoi seguirla nel wallet o su Polygonscan.",
|
||||
"viewOnPolygonscan": "Apri in Polygonscan",
|
||||
"copy": "Copia hash",
|
||||
"copySuccess": "Hash di transazione copiato.",
|
||||
"copyFailed": "Impossibile copiare l’hash. Copialo manualmente."
|
||||
},
|
||||
"history": {
|
||||
"title": "Messaggi recenti",
|
||||
"subtitle": "Messaggi inviati in questa sessione.",
|
||||
"empty": "Ancora nessun messaggio.",
|
||||
"sent": "Inviato",
|
||||
"from": "Da",
|
||||
"to": "A"
|
||||
},
|
||||
"status": {
|
||||
"waiting": "In attesa di connessione…",
|
||||
"preparingConnect": "Preparazione della connessione…",
|
||||
"requesting": "Richiesta di accesso al wallet…",
|
||||
"connectedInjected": "Connesso tramite provider iniettato. Puoi inviare ora su Polygon.",
|
||||
"connectFirst": "Connetti prima il wallet.",
|
||||
"messageEmpty": "Il messaggio non può essere vuoto.",
|
||||
"recipientInvalid": "Il destinatario deve essere un indirizzo valido.",
|
||||
"switchPolygon": "Passa a Polygon mainnet nel wallet.",
|
||||
"prepareTx": "Stima del gas e preparazione transazione…",
|
||||
"gasFallback": "Stima del gas fallita; uso un limite di fallback e invio comunque.",
|
||||
"feeFallback": "Impossibile recuperare le fee; ritento con un gas price legacy.",
|
||||
"eoaWarning": "Avviso: inviare dati a un EOA può fallire in alcuni wallet/RPC.",
|
||||
"submitted": "Transazione inviata. Hash: {hash}",
|
||||
"onchain": "Messaggio on-chain. Controlla nel wallet o su Polygonscan.",
|
||||
"rejected": "Richiesta rifiutata nel wallet.",
|
||||
"disconnected": "Disconnesso."
|
||||
},
|
||||
"errors": {
|
||||
"noWallet": "Nessun wallet iniettato trovato. Usa l’estensione Trust Wallet o il browser dell’app.",
|
||||
"noAccounts": "Il wallet non ha restituito account.",
|
||||
"sendFailed": "Impossibile inviare la transazione con messaggio.",
|
||||
"connectionFailed": "Connessione fallita."
|
||||
}
|
||||
}
|
||||
83
app/locales/sv.json
Normal file
83
app/locales/sv.json
Normal file
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"locale": {
|
||||
"label": "Språk",
|
||||
"search": "Sök språk..."
|
||||
},
|
||||
"theme": {
|
||||
"toggle": "Byt tema",
|
||||
"dark": "Mörkt läge",
|
||||
"light": "Ljust läge"
|
||||
},
|
||||
"hero": {
|
||||
"eyebrow": "Injektad Trust Wallet • Polygon mainnet",
|
||||
"title": "PolyNote · Trust Wallet till Polygon",
|
||||
"lede": "Anslut via Trust Wallets tillägg eller den inbyggda webbläsaren. Vi kodar din text i hex och skickar en 0 MATIC-transaktion på Polygon; du betalar bara gas."
|
||||
},
|
||||
"connection": {
|
||||
"title": "Anslutning",
|
||||
"subtitle": "Injekterad Trust Wallet (tillägg eller in-app dApp-webbläsare).",
|
||||
"pill": "Endast Polygon",
|
||||
"connect": "Anslut Trust Wallet",
|
||||
"disconnect": "Koppla från",
|
||||
"account": "Konto",
|
||||
"chain": "Nätverk",
|
||||
"status": "Status",
|
||||
"connected": "Ansluten",
|
||||
"notConnected": "Inte ansluten"
|
||||
},
|
||||
"compose": {
|
||||
"title": "Skriv meddelande",
|
||||
"subtitle": "Vi kodar din text i hex och skickar en 0 MATIC-transaktion med den datan.",
|
||||
"recipientLabel": "Mottagaradress",
|
||||
"recipientHint": "(standard är din egen plånbok)",
|
||||
"messageLabel": "Meddelande att bädda in",
|
||||
"messagePlaceholder": "Skriv upp till 280 tecken...",
|
||||
"messageHint": "Vi gör om det till hex och lägger det i data-fältet.",
|
||||
"send": "Skicka meddelande-transaktion",
|
||||
"sending": "Skickar…"
|
||||
},
|
||||
"live": {
|
||||
"title": "Status i realtid",
|
||||
"subtitle": "Vi uppdaterar dig vid varje steg.",
|
||||
"chainReady": "På Polygon mainnet och redo.",
|
||||
"chainRequired": "Polygon mainnet krävs.",
|
||||
"lastTx": "Senaste transaktionshash",
|
||||
"trackHint": "Följ den i din plånbok eller på Polygonscan.",
|
||||
"viewOnPolygonscan": "Öppna i Polygonscan",
|
||||
"copy": "Kopiera hash",
|
||||
"copySuccess": "Transaktions-hash kopierad.",
|
||||
"copyFailed": "Kunde inte kopiera hash. Kopiera manuellt."
|
||||
},
|
||||
"history": {
|
||||
"title": "Senaste meddelanden",
|
||||
"subtitle": "Meddelanden du skickade i den här sessionen.",
|
||||
"empty": "Inga meddelanden ännu.",
|
||||
"sent": "Skickat",
|
||||
"from": "Från",
|
||||
"to": "Till"
|
||||
},
|
||||
"status": {
|
||||
"waiting": "Väntar på anslutning…",
|
||||
"preparingConnect": "Förbereder anslutning…",
|
||||
"requesting": "Begär åtkomst till plånboken…",
|
||||
"connectedInjected": "Ansluten via injekterad provider. Du kan skicka ett Polygon-meddelande nu.",
|
||||
"connectFirst": "Anslut plånboken först.",
|
||||
"messageEmpty": "Meddelandet kan inte vara tomt.",
|
||||
"recipientInvalid": "Mottagaren måste vara en giltig adress.",
|
||||
"switchPolygon": "Byt till Polygon mainnet i din plånbok.",
|
||||
"prepareTx": "Beräknar gas och förbereder transaktionen…",
|
||||
"gasFallback": "Gasberäkningen misslyckades; använder ett reservtak och skickar ändå.",
|
||||
"feeFallback": "Kunde inte hämta avgifter; försöker igen med legacy gas price.",
|
||||
"eoaWarning": "Varning: data till en EOA kan misslyckas i vissa wallets/RPC:er.",
|
||||
"submitted": "Transaktion skickad. Hash: {hash}",
|
||||
"onchain": "Meddelandet är on-chain. Kontrollera i plånboken eller på Polygonscan.",
|
||||
"rejected": "Begäran avvisad i plånboken.",
|
||||
"disconnected": "Frånkopplad."
|
||||
},
|
||||
"errors": {
|
||||
"noWallet": "Ingen injekterad plånbok hittades. Använd Trust Wallet-tillägget eller appens webbläsare.",
|
||||
"noAccounts": "Plånboken returnerade inga konton.",
|
||||
"sendFailed": "Det gick inte att skicka meddelande-transaktionen.",
|
||||
"connectionFailed": "Anslutningen misslyckades."
|
||||
}
|
||||
}
|
||||
603
app/page.tsx
Normal file
603
app/page.tsx
Normal file
@@ -0,0 +1,603 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import type { FormEvent } from "react";
|
||||
import Image from "next/image";
|
||||
import { ethers } from "ethers";
|
||||
import { LocaleSelector } from "@/components/LocaleSelector";
|
||||
import { useI18n, type Locale, type MessageKey } from "@/hooks/useI18n";
|
||||
import { useTheme } from "@/hooks/useTheme";
|
||||
|
||||
type StatusTone = "info" | "success" | "error";
|
||||
|
||||
type StatusState = {
|
||||
text: string;
|
||||
tone: StatusTone;
|
||||
key?: string;
|
||||
vars?: Record<string, string>;
|
||||
};
|
||||
|
||||
type Eip1193Provider = {
|
||||
request: (args: { method: string; params?: unknown[] }) => Promise<unknown>;
|
||||
on?: (event: string, fn: (...args: unknown[]) => void | Promise<void>) => void;
|
||||
removeListener?: (event: string, fn: (...args: unknown[]) => void | Promise<void>) => void;
|
||||
providers?: Eip1193Provider[];
|
||||
isTrustWallet?: boolean;
|
||||
isTrust?: boolean;
|
||||
};
|
||||
|
||||
type EthereumWindow = Window & {
|
||||
ethereum?: Eip1193Provider & { providers?: Eip1193Provider[] };
|
||||
trustwallet?: Eip1193Provider;
|
||||
};
|
||||
|
||||
const formatChain = (chainId: number | null) => {
|
||||
if (chainId === 137) return "Polygon";
|
||||
if (typeof chainId === "number" && Number.isFinite(chainId)) return `Chain ${chainId}`;
|
||||
return "—";
|
||||
};
|
||||
|
||||
type MessageEntry = {
|
||||
hash: string;
|
||||
to: string;
|
||||
from: string;
|
||||
message: string;
|
||||
createdAt: number;
|
||||
};
|
||||
|
||||
export default function HomePage() {
|
||||
const { locale, setLocale, t, localeOptions } = useI18n("en");
|
||||
const [account, setAccount] = useState<string>("");
|
||||
const [chainId, setChainId] = useState<number | null>(null);
|
||||
const [txHash, setTxHash] = useState<string>("—");
|
||||
const [status, setStatus] = useState<StatusState>({
|
||||
text: t("status.waiting"),
|
||||
key: "status.waiting",
|
||||
tone: "info",
|
||||
});
|
||||
const [connecting, setConnecting] = useState<boolean>(false);
|
||||
const [sending, setSending] = useState<boolean>(false);
|
||||
const [connected, setConnected] = useState<boolean>(false);
|
||||
const [history, setHistory] = useState<MessageEntry[]>([]);
|
||||
|
||||
const providerRef = useRef<Eip1193Provider | null>(null);
|
||||
const signerRef = useRef<ethers.Signer | null>(null);
|
||||
const formRef = useRef<HTMLFormElement | null>(null);
|
||||
|
||||
const chainLabel = formatChain(chainId);
|
||||
const onPolygon = chainId === 137;
|
||||
const statusClass =
|
||||
status.tone === "success"
|
||||
? "status-line status-ok"
|
||||
: status.tone === "error"
|
||||
? "status-line status-error"
|
||||
: "status-line";
|
||||
const chainPillClass = onPolygon ? "pill pill-live" : "pill pill-quiet";
|
||||
const chainPillText = onPolygon ? "Polygon" : chainLabel || t("live.chainRequired");
|
||||
const disableSend = !connected || sending;
|
||||
const disableConnect = connecting;
|
||||
const disableDisconnect = !connected || connecting;
|
||||
const polygonscanBase = "https://polygonscan.com/tx/";
|
||||
const hasTxHash = Boolean(txHash && txHash !== "—");
|
||||
|
||||
useEffect(() => {
|
||||
if (status.key) {
|
||||
setStatus((prev) => ({
|
||||
...prev,
|
||||
text: t(prev.key as MessageKey, prev.vars),
|
||||
}));
|
||||
}
|
||||
}, [locale, status.key, status.vars, t]);
|
||||
|
||||
function setStatusMessage(
|
||||
text: string,
|
||||
tone: StatusTone = "info",
|
||||
key?: string,
|
||||
vars?: Record<string, string>
|
||||
) {
|
||||
setStatus({ text, tone, key, vars });
|
||||
}
|
||||
|
||||
async function connectWallet() {
|
||||
if (connecting) return;
|
||||
setConnecting(true);
|
||||
setTxHash("—");
|
||||
setStatusMessage(t("status.preparingConnect"), "info", "status.preparingConnect");
|
||||
await disconnect(false);
|
||||
|
||||
try {
|
||||
await connectInjected();
|
||||
} catch (err) {
|
||||
console.error("Connection failed", err);
|
||||
setStatusMessage(normalizeError(err, t("errors.connectionFailed"), t), "error");
|
||||
resetState();
|
||||
} finally {
|
||||
setConnecting(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function connectInjected() {
|
||||
const injected = pickInjectedProvider();
|
||||
if (!injected) {
|
||||
setStatusMessage(t("errors.noWallet"), "error", "errors.noWallet");
|
||||
return;
|
||||
}
|
||||
|
||||
providerRef.current = injected;
|
||||
attachProviderEvents(injected);
|
||||
|
||||
setStatusMessage(t("status.requesting"), "info", "status.requesting");
|
||||
// Try to force a fresh permission prompt when possible
|
||||
try {
|
||||
await injected.request({
|
||||
method: "wallet_requestPermissions",
|
||||
params: [{ eth_accounts: {} }],
|
||||
});
|
||||
} catch (err) {
|
||||
// Some wallets do not support this; fall back silently
|
||||
console.warn("wallet_requestPermissions not supported or rejected", err);
|
||||
}
|
||||
|
||||
const accounts = (await injected.request({
|
||||
method: "eth_requestAccounts",
|
||||
})) as string[];
|
||||
if (!accounts || accounts.length === 0) {
|
||||
throw new Error(t("errors.noAccounts"));
|
||||
}
|
||||
|
||||
const browserProvider = new ethers.BrowserProvider(
|
||||
injected as unknown as ethers.Eip1193Provider
|
||||
);
|
||||
const signer = await browserProvider.getSigner();
|
||||
signerRef.current = signer;
|
||||
const address = await signer.getAddress();
|
||||
const network = await browserProvider.getNetwork();
|
||||
|
||||
setAccount(address);
|
||||
setChainId(Number(network.chainId));
|
||||
setConnected(true);
|
||||
setStatusMessage(t("status.connectedInjected"), "success", "status.connectedInjected");
|
||||
}
|
||||
|
||||
async function disconnect(showMessage = true) {
|
||||
removeProviderEvents(providerRef.current);
|
||||
providerRef.current = null;
|
||||
signerRef.current = null;
|
||||
resetState();
|
||||
if (showMessage) setStatusMessage(t("status.disconnected"), "info", "status.disconnected");
|
||||
}
|
||||
|
||||
function resetState() {
|
||||
setConnected(false);
|
||||
setAccount("");
|
||||
setChainId(null);
|
||||
setTxHash("—");
|
||||
}
|
||||
|
||||
function attachProviderEvents(provider: Eip1193Provider) {
|
||||
if (!provider?.on) return;
|
||||
provider.on("accountsChanged", handleAccountsChanged);
|
||||
provider.on("chainChanged", handleChainChanged);
|
||||
provider.on("disconnect", handleDisconnectEvent);
|
||||
}
|
||||
|
||||
function removeProviderEvents(provider: Eip1193Provider | null) {
|
||||
if (!provider?.removeListener) return;
|
||||
provider.removeListener("accountsChanged", handleAccountsChanged);
|
||||
provider.removeListener("chainChanged", handleChainChanged);
|
||||
provider.removeListener("disconnect", handleDisconnectEvent);
|
||||
}
|
||||
|
||||
function handleDisconnectEvent() {
|
||||
disconnect(true);
|
||||
}
|
||||
|
||||
async function handleAccountsChanged(...args: unknown[]) {
|
||||
const accounts = Array.isArray(args[0]) ? args[0] : [];
|
||||
if (!accounts || accounts.length === 0) {
|
||||
await disconnect(true);
|
||||
return;
|
||||
}
|
||||
const first = accounts.find((acct): acct is string => typeof acct === "string");
|
||||
if (!first) {
|
||||
await disconnect(true);
|
||||
return;
|
||||
}
|
||||
setAccount(first);
|
||||
}
|
||||
|
||||
async function handleChainChanged(newChainId: unknown) {
|
||||
if (typeof newChainId !== "string" && typeof newChainId !== "number") return;
|
||||
const parsed = parseChainId(newChainId);
|
||||
setChainId(parsed);
|
||||
}
|
||||
|
||||
async function ensurePolygonChain() {
|
||||
if (chainId === 137 || !providerRef.current) return true;
|
||||
try {
|
||||
await providerRef.current.request({
|
||||
method: "wallet_switchEthereumChain",
|
||||
params: [{ chainId: "0x89" }],
|
||||
});
|
||||
setChainId(137);
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.warn("Chain switch rejected", err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCopyHash() {
|
||||
if (!hasTxHash) return;
|
||||
try {
|
||||
if (!("clipboard" in navigator)) {
|
||||
throw new Error("Clipboard API unavailable");
|
||||
}
|
||||
await navigator.clipboard.writeText(txHash);
|
||||
setStatusMessage(t("live.copySuccess"), "success", "live.copySuccess");
|
||||
} catch (err) {
|
||||
console.warn("Copy failed", err);
|
||||
setStatusMessage(t("live.copyFailed"), "error", "live.copyFailed");
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSendMessage(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
const formEl = event.currentTarget;
|
||||
setTxHash("—");
|
||||
if (!signerRef.current) {
|
||||
setStatusMessage(t("status.connectFirst"), "error", "status.connectFirst");
|
||||
return;
|
||||
}
|
||||
|
||||
const formData = new FormData(event.currentTarget);
|
||||
const message = (formData.get("message") || "").toString().trim();
|
||||
let recipient = (formData.get("to") || "").toString().trim();
|
||||
|
||||
if (!message) {
|
||||
setStatusMessage(t("status.messageEmpty"), "error", "status.messageEmpty");
|
||||
return;
|
||||
}
|
||||
if (!recipient) recipient = account;
|
||||
if (!ethers.isAddress(recipient)) {
|
||||
setStatusMessage(t("status.recipientInvalid"), "error", "status.recipientInvalid");
|
||||
return;
|
||||
}
|
||||
const recipientIsEoa = recipient.toLowerCase() === account.toLowerCase();
|
||||
if (recipientIsEoa) {
|
||||
setStatusMessage(t("status.eoaWarning"), "info", "status.eoaWarning");
|
||||
}
|
||||
|
||||
const canUsePolygon = await ensurePolygonChain();
|
||||
if (!canUsePolygon) {
|
||||
setStatusMessage(t("status.switchPolygon"), "error", "status.switchPolygon");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setSending(true);
|
||||
setStatusMessage(t("status.prepareTx"), "info", "status.prepareTx");
|
||||
|
||||
const data = ethers.hexlify(ethers.toUtf8Bytes(message));
|
||||
const txRequest = { to: recipient, value: 0n, data };
|
||||
let gasLimit: bigint;
|
||||
try {
|
||||
gasLimit = await signerRef.current.estimateGas(txRequest);
|
||||
} catch (estimateErr) {
|
||||
console.warn("Gas estimation failed, using fallback", estimateErr);
|
||||
setStatusMessage(t("status.gasFallback"), "info", "status.gasFallback");
|
||||
gasLimit = 250000n;
|
||||
}
|
||||
|
||||
const feeData = await signerRef.current.provider?.getFeeData?.();
|
||||
const feeOverrides =
|
||||
feeData && feeData.maxFeePerGas && feeData.maxPriorityFeePerGas
|
||||
? {
|
||||
maxFeePerGas: feeData.maxFeePerGas,
|
||||
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
|
||||
}
|
||||
: {
|
||||
// conservative Polygon fallbacks in gwei
|
||||
maxFeePerGas: ethers.parseUnits("50", "gwei"),
|
||||
maxPriorityFeePerGas: ethers.parseUnits("40", "gwei"),
|
||||
};
|
||||
|
||||
let tx;
|
||||
try {
|
||||
tx = await signerRef.current.sendTransaction({
|
||||
...txRequest,
|
||||
gasLimit,
|
||||
...feeOverrides,
|
||||
});
|
||||
} catch (sendErr) {
|
||||
const code = (sendErr as { code?: number | string })?.code;
|
||||
if (code === 4001 || code === "ACTION_REJECTED") {
|
||||
setStatusMessage(t("status.rejected"), "error", "status.rejected");
|
||||
throw sendErr;
|
||||
}
|
||||
|
||||
// Fallback to legacy gasPrice if EIP-1559 style send fails or simulates a revert
|
||||
setStatusMessage(t("status.feeFallback"), "info", "status.feeFallback");
|
||||
const gasPrice =
|
||||
(await signerRef.current.provider?.getGasPrice?.()) || ethers.parseUnits("50", "gwei");
|
||||
tx = await signerRef.current.sendTransaction({
|
||||
...txRequest,
|
||||
gasLimit,
|
||||
gasPrice,
|
||||
});
|
||||
}
|
||||
|
||||
setTxHash(tx.hash);
|
||||
setStatusMessage(t("status.submitted", { hash: tx.hash }), "success", "status.submitted", {
|
||||
hash: tx.hash,
|
||||
});
|
||||
|
||||
await tx.wait();
|
||||
setStatusMessage(t("status.onchain"), "success", "status.onchain");
|
||||
formEl.reset();
|
||||
setHistory((prev) => [
|
||||
{
|
||||
hash: tx.hash,
|
||||
to: recipient,
|
||||
from: account,
|
||||
message,
|
||||
createdAt: Date.now(),
|
||||
},
|
||||
...prev,
|
||||
]);
|
||||
} catch (err) {
|
||||
console.error("Send failed", err);
|
||||
setStatusMessage(normalizeError(err, t("errors.sendFailed"), t), "error");
|
||||
} finally {
|
||||
setSending(false);
|
||||
}
|
||||
}
|
||||
|
||||
const { theme, toggleTheme } = useTheme();
|
||||
|
||||
return (
|
||||
<main className="page">
|
||||
<header className="hero">
|
||||
<div className="hero-row">
|
||||
<div className="hero-text">
|
||||
<div className="hero-topline">
|
||||
<Image
|
||||
src="/logo.svg"
|
||||
alt="PolyNote logo"
|
||||
width={52}
|
||||
height={52}
|
||||
className="logo-mark"
|
||||
/>
|
||||
<div className="eyebrow">{t("hero.eyebrow")}</div>
|
||||
</div>
|
||||
<h1>{t("hero.title")}</h1>
|
||||
<p className="lede">{t("hero.lede")}</p>
|
||||
</div>
|
||||
<div className="hero-actions">
|
||||
<LocaleSelector
|
||||
locale={locale}
|
||||
onChange={(code) => setLocale(code as Locale)}
|
||||
options={localeOptions}
|
||||
label={t("locale.label")}
|
||||
searchPlaceholder={t("locale.search")}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="ghost theme-toggle"
|
||||
onClick={toggleTheme}
|
||||
aria-pressed={theme === "dark"}
|
||||
title={t("theme.toggle")}
|
||||
>
|
||||
{theme === "dark" ? "🌙" : "☀️"}{" "}
|
||||
{theme === "dark" ? t("theme.light") : t("theme.dark")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section className="grid">
|
||||
<article className="card">
|
||||
<div className="card-head">
|
||||
<div>
|
||||
<p className="label">{t("connection.title")}</p>
|
||||
<p className="muted">{t("connection.subtitle")}</p>
|
||||
</div>
|
||||
<span className="pill pill-quiet">{t("connection.pill")}</span>
|
||||
</div>
|
||||
<div className="stack">
|
||||
<div className="button-row">
|
||||
<button
|
||||
id="connectBtn"
|
||||
type="button"
|
||||
onClick={connectWallet}
|
||||
disabled={disableConnect}
|
||||
>
|
||||
{connecting ? t("compose.sending") : t("connection.connect")}
|
||||
</button>
|
||||
<button
|
||||
id="disconnectBtn"
|
||||
type="button"
|
||||
className="ghost"
|
||||
onClick={() => disconnect(true)}
|
||||
disabled={disableDisconnect}
|
||||
>
|
||||
{t("connection.disconnect")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<dl className="meta">
|
||||
<div>
|
||||
<dt>{t("connection.account")}</dt>
|
||||
<dd>{account || "—"}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>{t("connection.chain")}</dt>
|
||||
<dd>{chainLabel}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>{t("connection.status")}</dt>
|
||||
<dd>{connected ? t("connection.connected") : t("connection.notConnected")}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</article>
|
||||
|
||||
<article className="card">
|
||||
<div className="card-head">
|
||||
<div>
|
||||
<p className="label">{t("compose.title")}</p>
|
||||
<p className="muted">{t("compose.subtitle")}</p>
|
||||
</div>
|
||||
<span className={chainPillClass}>{chainPillText}</span>
|
||||
</div>
|
||||
<form
|
||||
id="messageForm"
|
||||
ref={formRef}
|
||||
className="stack"
|
||||
noValidate
|
||||
onSubmit={handleSendMessage}
|
||||
>
|
||||
<label className="input-label" htmlFor="toAddress">
|
||||
{t("compose.recipientLabel")}{" "}
|
||||
<span className="muted">{t("compose.recipientHint")}</span>
|
||||
</label>
|
||||
<input
|
||||
id="toAddress"
|
||||
name="to"
|
||||
type="text"
|
||||
placeholder="0x destination (optional)"
|
||||
autoComplete="off"
|
||||
/>
|
||||
|
||||
<label className="input-label" htmlFor="messageInput">
|
||||
{t("compose.messageLabel")}
|
||||
</label>
|
||||
<textarea
|
||||
id="messageInput"
|
||||
name="message"
|
||||
rows={4}
|
||||
maxLength={280}
|
||||
placeholder={t("compose.messagePlaceholder")}
|
||||
disabled={!connected}
|
||||
></textarea>
|
||||
<p className="hint">{t("compose.messageHint")}</p>
|
||||
|
||||
<button id="sendBtn" type="submit" className="primary" disabled={disableSend}>
|
||||
{sending ? t("compose.sending") : t("compose.send")}
|
||||
</button>
|
||||
</form>
|
||||
</article>
|
||||
|
||||
<article className="card status-card">
|
||||
<div className="card-head">
|
||||
<div>
|
||||
<p className="label">{t("live.title")}</p>
|
||||
<p className="muted">{t("live.subtitle")}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className={statusClass}>{status.text}</div>
|
||||
<div className="status-line secondary">
|
||||
<span className="dot"></span>
|
||||
<span>{onPolygon ? t("live.chainReady") : t("live.chainRequired")}</span>
|
||||
</div>
|
||||
<div className="tx-box">
|
||||
<div className="label">{t("live.lastTx")}</div>
|
||||
<div className="hash">{txHash || "—"}</div>
|
||||
<div className="tx-actions">
|
||||
<button
|
||||
type="button"
|
||||
className="ghost copy-btn"
|
||||
onClick={handleCopyHash}
|
||||
disabled={!hasTxHash}
|
||||
title={t("live.copy")}
|
||||
>
|
||||
{t("live.copy")}
|
||||
</button>
|
||||
<a
|
||||
className={`link ${!hasTxHash ? "disabled" : ""}`}
|
||||
href={hasTxHash ? `${polygonscanBase}${txHash}` : undefined}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
aria-disabled={!hasTxHash}
|
||||
>
|
||||
{t("live.viewOnPolygonscan")}
|
||||
</a>
|
||||
</div>
|
||||
<div className="hint">{t("live.trackHint")}</div>
|
||||
</div>
|
||||
<div className="history">
|
||||
<div className="history-head">
|
||||
<div>
|
||||
<p className="label">{t("history.title")}</p>
|
||||
<p className="muted">{t("history.subtitle")}</p>
|
||||
</div>
|
||||
</div>
|
||||
{history.length === 0 ? (
|
||||
<div className="history-empty">{t("history.empty")}</div>
|
||||
) : (
|
||||
<ul className="history-list">
|
||||
{history.map((item) => (
|
||||
<li key={item.hash} className="history-item">
|
||||
<div className="history-row">
|
||||
<span className="pill pill-quiet">{t("history.sent")}</span>
|
||||
<span className="history-time">
|
||||
{new Date(item.createdAt).toLocaleTimeString()}
|
||||
</span>
|
||||
</div>
|
||||
<div className="history-meta">
|
||||
<span>
|
||||
{t("history.from")}: {item.from}
|
||||
</span>
|
||||
<span>
|
||||
{t("history.to")}: {item.to}
|
||||
</span>
|
||||
</div>
|
||||
<div className="history-message">{item.message}</div>
|
||||
<div className="history-hash">
|
||||
{item.hash.slice(0, 10)}…{item.hash.slice(-6)}
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function pickInjectedProvider(): Eip1193Provider | null {
|
||||
if (typeof window === "undefined") return null;
|
||||
const { ethereum, trustwallet } = window as EthereumWindow;
|
||||
if (ethereum?.providers?.length) {
|
||||
const trust = ethereum.providers.find((p) => p.isTrustWallet || p.isTrust);
|
||||
if (trust) return trust;
|
||||
return ethereum.providers[0];
|
||||
}
|
||||
if (trustwallet) return trustwallet;
|
||||
return ethereum || null;
|
||||
}
|
||||
|
||||
function parseChainId(chainId: string | number): number {
|
||||
if (typeof chainId === "string" && chainId.startsWith("0x")) {
|
||||
return parseInt(chainId, 16);
|
||||
}
|
||||
return Number(chainId);
|
||||
}
|
||||
|
||||
function normalizeError(
|
||||
err: unknown,
|
||||
fallback: string,
|
||||
t: (key: string, vars?: Record<string, string>) => string
|
||||
): string {
|
||||
if (!err) return fallback;
|
||||
if (typeof err === "string") return err;
|
||||
if (typeof err === "object") {
|
||||
const maybeError = err as { code?: number | string; message?: string; reason?: string };
|
||||
if (maybeError.code === 4001 || maybeError.message?.toLowerCase().includes("user rejected"))
|
||||
return t("status.rejected");
|
||||
if (maybeError.message) return maybeError.message;
|
||||
if (maybeError.reason) return maybeError.reason;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
61
eslint.config.js
Normal file
61
eslint.config.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import js from "@eslint/js";
|
||||
import pluginNext from "@next/eslint-plugin-next";
|
||||
import pluginReact from "eslint-plugin-react";
|
||||
import pluginReactHooks from "eslint-plugin-react-hooks";
|
||||
import pluginJsxA11y from "eslint-plugin-jsx-a11y";
|
||||
import pluginPrettier from "eslint-plugin-prettier";
|
||||
import tseslint from "@typescript-eslint/eslint-plugin";
|
||||
import tsParser from "@typescript-eslint/parser";
|
||||
import globals from "globals";
|
||||
|
||||
export default [
|
||||
{
|
||||
name: "ignores",
|
||||
ignores: ["**/node_modules/**", "**/.next/**", "**/dist/**", "**/build/**", "next-env.d.ts"],
|
||||
},
|
||||
js.configs.recommended,
|
||||
{
|
||||
name: "base:react-next",
|
||||
files: ["**/*.{js,jsx,ts,tsx}"],
|
||||
languageOptions: {
|
||||
parser: tsParser,
|
||||
parserOptions: {
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
ecmaFeatures: { jsx: true },
|
||||
},
|
||||
globals: {
|
||||
...globals.browser,
|
||||
React: "readonly",
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
"@next/next": pluginNext,
|
||||
react: pluginReact,
|
||||
"react-hooks": pluginReactHooks,
|
||||
"jsx-a11y": pluginJsxA11y,
|
||||
prettier: pluginPrettier,
|
||||
"@typescript-eslint": tseslint,
|
||||
},
|
||||
settings: {
|
||||
react: { version: "detect" },
|
||||
},
|
||||
rules: {
|
||||
...pluginNext.configs["core-web-vitals"].rules,
|
||||
...pluginReact.configs.recommended.rules,
|
||||
...pluginReactHooks.configs.recommended.rules,
|
||||
...pluginJsxA11y.configs.recommended.rules,
|
||||
...pluginPrettier.configs.recommended.rules,
|
||||
...tseslint.configs.recommended.rules,
|
||||
"react/react-in-jsx-scope": "off",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "scripts:node",
|
||||
files: ["scripts/**/*.{js,cjs}"],
|
||||
languageOptions: {
|
||||
sourceType: "script",
|
||||
globals: globals.node,
|
||||
},
|
||||
},
|
||||
];
|
||||
6
next-env.d.ts
vendored
Normal file
6
next-env.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
/// <reference path="./.next/types/routes.d.ts" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||
9
next.config.mjs
Normal file
9
next.config.mjs
Normal file
@@ -0,0 +1,9 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
output: "standalone",
|
||||
eslint: {
|
||||
ignoreDuringBuilds: true, // we run eslint separately with flat config + ESLint 9
|
||||
},
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
34
package.json
Normal file
34
package.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "poly-note",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "node scripts/ensure-middleware-manifest.cjs && pnpm exec next dev",
|
||||
"build": "NEXT_DISABLE_ESLINT=1 pnpm exec next build",
|
||||
"start": "node scripts/ensure-middleware-manifest.cjs && NEXT_DISABLE_ESLINT=1 pnpm exec next start",
|
||||
"lint": "pnpm exec eslint .",
|
||||
"format": "prettier --check ."
|
||||
},
|
||||
"dependencies": {
|
||||
"ethers": "^6.16.0",
|
||||
"next": "^15.0.3",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.9.3",
|
||||
"@types/react": "19.2.9",
|
||||
"@typescript-eslint/eslint-plugin": "^8.17.0",
|
||||
"@typescript-eslint/parser": "^8.17.0",
|
||||
"@eslint/js": "^9.12.0",
|
||||
"@next/eslint-plugin-next": "^15.5.9",
|
||||
"eslint": "^9.12.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.9.0",
|
||||
"eslint-plugin-prettier": "^5.2.1",
|
||||
"eslint-plugin-react": "^7.37.2",
|
||||
"eslint-plugin-react-hooks": "^5.0.0",
|
||||
"globals": "^15.12.0",
|
||||
"prettier": "^3.3.3",
|
||||
"typescript": "5.9.3"
|
||||
}
|
||||
}
|
||||
3029
pnpm-lock.yaml
generated
Normal file
3029
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
BIN
public/favicon.ico
Normal file
BIN
public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.9 KiB |
BIN
public/favicon.png
Normal file
BIN
public/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 733 B |
27
public/logo.svg
Normal file
27
public/logo.svg
Normal file
@@ -0,0 +1,27 @@
|
||||
<svg width="256" height="256" viewBox="0 0 256 256"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
|
||||
<!-- Base hexagon -->
|
||||
<path d="M128 28
|
||||
L208 72
|
||||
L208 160
|
||||
L128 204
|
||||
L48 160
|
||||
L48 72 Z"
|
||||
fill="#6B4EFF"/>
|
||||
|
||||
<!-- Centered envelope (offset on Y) -->
|
||||
<rect x="76" y="80" width="104" height="72" rx="10"
|
||||
fill="none"
|
||||
stroke="#FFFFFF"
|
||||
stroke-width="8"/>
|
||||
|
||||
<!-- Envelope flap -->
|
||||
<path d="M76 88 L128 120 L180 88"
|
||||
fill="none"
|
||||
stroke="#FFFFFF"
|
||||
stroke-width="8"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"/>
|
||||
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 636 B |
22
scripts/ensure-middleware-manifest.cjs
Normal file
22
scripts/ensure-middleware-manifest.cjs
Normal file
@@ -0,0 +1,22 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const manifestPath = path.join(__dirname, "..", ".next", "server", "middleware-manifest.json");
|
||||
const dir = path.dirname(manifestPath);
|
||||
|
||||
try {
|
||||
if (!fs.existsSync(manifestPath)) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
const payload = {
|
||||
version: 2,
|
||||
middleware: {},
|
||||
functions: {},
|
||||
sortedMiddleware: [],
|
||||
clientInfo: [],
|
||||
};
|
||||
fs.writeFileSync(manifestPath, JSON.stringify(payload, null, 2));
|
||||
console.log(`Created missing middleware manifest at ${manifestPath}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn("Could not ensure middleware manifest (likely permissions). You can create it manually:", manifestPath, err?.message);
|
||||
}
|
||||
24
tsconfig.json
Normal file
24
tsconfig.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["app/*"]
|
||||
},
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"plugins": [{ "name": "next" }]
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user