Compare commits

...

98 Commits

Author SHA1 Message Date
fa46663dda fix problem when notification subscription isn't found 2024-11-24 17:40:29 -07:00
7777fa202b finish separation of daily reminder message, bump version to 0.3.34 2024-11-24 13:09:40 -07:00
8735fe44db change the notification detection to our own variables, and save the selected time 2024-11-20 19:55:51 -07:00
2a652d2079 make the import selection more obvious, plus other verbiage 2024-11-18 18:22:11 -07:00
75fb4da42d move push notification setup out of an App.vue Notification and into a component 2024-11-18 17:00:06 -07:00
6dc44b2494 move more logging into the database 2024-11-17 18:16:22 -07:00
2c0c7ac256 add minute to notification scheduling & fix a bug, plus other tweaks 2024-11-15 20:39:08 -07:00
f06eb27ba0 Revert "after npx cap add ... for ios & android"
This reverts commit 17f304ddb8.
2024-11-15 20:38:40 -07:00
a1c1c9f805 add way to quickly import test data when on a test instance 2024-11-11 16:37:28 -07:00
17f304ddb8 after npx cap add ... for ios & android 2024-11-10 20:17:45 -07:00
6605fbd708 bump version and add "-beta"; add capacitor libraries 2024-11-10 20:16:19 -07:00
9b079ee5f2 update changelog 2024-11-10 19:07:39 -07:00
a3b10d9a78 adjust test lines to await/expect appropriately 2024-11-07 19:07:45 -07:00
a73f0239c9 fix problem not showing user's projects on project page 2024-11-07 18:48:52 -07:00
8466bb0b1f fix linting problem (NOW we'll deploy 0.3.33) 2024-11-07 18:24:01 -07:00
71675edc3f bump all files to 0.3.33 2024-11-07 18:21:09 -07:00
7ef8263d49 bump version to 0.3.33 2024-11-07 18:19:52 -07:00
bacf9d7de6 fix problem with "Affirm Delivery" on offer claim page, plus other look-and-feel tweaks 2024-11-07 18:17:33 -07:00
79a530aff5 bump version to 0.3.32 2024-11-05 19:58:00 -07:00
c004706425 add pages to see all the offers to user and offers to user's projects 2024-11-05 19:03:12 -07:00
0d880d1edc add "+" to numbers if hit limit (>50), fix linting 2024-11-05 09:06:04 -07:00
f96c5892e7 add test for user-project offers on front page 2024-11-05 05:50:15 -07:00
195ba6c759 add new projects to front page 2024-11-04 19:57:39 -07:00
5f452dcf73 add tests for new activity of offers-directly-to-user 2024-11-03 20:09:54 -07:00
fcec9e53f5 add better verbiage when an offer has both description and amount 2024-11-03 17:30:40 -07:00
dbf010c1fe mark new-activity offers as seen, and mark them unseen again 2024-11-03 17:20:54 -07:00
67b2b7199a fix tests (from project-page switch 4 commits ago) and fix linting 2024-11-03 15:23:03 -07:00
4168c37074 add large notice when user has a new offer to them 2024-11-03 10:39:28 -07:00
8a61d9df45 various look-and-feel improvements 2024-11-01 20:32:39 -06:00
eb90c9ebae still 0.3.31, fix linting 2024-10-25 15:14:37 -06:00
e1d0a2b02c bump to version 0.3.31, tweak messaging to include offers 2024-10-25 15:12:06 -06:00
42dcb3b43c tweak onboarding messages 2024-10-24 20:50:27 -06:00
00b191c4fd suggest new user going to the front page 2024-10-24 20:04:08 -06:00
45214eabc5 adjust tests for new onboarding messages 2024-10-23 09:07:34 -06:00
53abf964b2 add basic page-by-page onboarding help 2024-10-23 08:27:16 -06:00
6f880d0df1 fix bad link to project page, fix improper action on invite-add-contact cancel 2024-10-12 20:55:55 -06:00
9c527b27f8 enhance help & help onboarding 2024-10-10 08:53:12 -06:00
14cc309d25 bump to version 0.3.29 2024-10-09 21:06:46 -06:00
fe482d06f6 show more redeemed info & action on the invites, refactor onboarding instructions 2024-10-09 20:45:06 -06:00
7fabb78ae3 improve messages on invite page 2024-10-08 20:25:55 -06:00
6e248f0385 add an invite-delete function 2024-10-08 20:13:07 -06:00
98afa8a259 refactor invite link & add test 2024-10-08 08:36:32 -06:00
2e100aedf5 fix linting 2024-10-06 20:07:05 -06:00
149481d468 finish the loading of an invite RegisterAction when clicking on a link 2024-10-06 20:01:07 -06:00
1bfdcab90b add page for one-on-one invites (incomplete) 2024-10-05 18:35:59 -06:00
9f4a19993e update nostr message to include signature for public key 2024-10-04 13:24:07 -06:00
5efd3e0e89 bump to version 3.0.28 2024-09-30 20:29:19 -06:00
4edcefd0f0 fix verbiage for recipient on home page 2024-09-30 19:54:14 -06:00
1fccf0fa92 change give provider to a single value 2024-09-30 18:33:15 -06:00
9925800fbd allow details on a give for a providing project (so we can attach a picture) 2024-09-30 18:11:07 -06:00
7c70e699d8 switch BVC-meeting-end gift to be from the plan, and add display of providers on claim-view page 2024-09-28 17:31:58 -06:00
a271d9c206 add link directly into contact page to add a new contact via "contactJwt" query parameter 2024-09-27 18:41:11 -06:00
2942a02a4e fix another vulnerability 2024-09-26 20:12:18 -06:00
eecca9b345 fix some vulnerabilities 2024-09-26 20:05:56 -06:00
8868d17c85 bump version and add "-beta" 2024-09-26 09:16:58 -06:00
3831cda76d Merge branch 'nostr' 2024-09-26 09:14:56 -06:00
1d48da6855 disable checkboxes for nostr partner messages; adjust linting warnings 2024-09-26 09:14:08 -06:00
a4073a5fff support TripHopping on nostr as well 2024-09-26 08:42:31 -06:00
d492ea9eeb send all info needed to create a Trustroots event 2024-09-25 09:01:49 -06:00
e6b9ef237b bump to version 0.3.27 2024-09-22 13:30:42 -06:00
791c0a0a5e update caniuse-lite 2024-09-22 13:28:18 -06:00
cd9f6b448b add more specific check to avoid complaint about multiple matches 2024-09-22 13:27:21 -06:00
25d5e13029 add nostr Trustroots partner as an option when submitting a project 2024-09-22 08:40:24 -06:00
b149e623b2 only show the "raw edit" when advanced options are turned on 2024-09-22 08:39:08 -06:00
1c79cc25fe fix problem where mounted ran before create and didn't load any claims 2024-09-21 12:47:37 -06:00
534f3d8a8b allow bulk-imported contacts to have visibility set 2024-09-17 18:30:50 -06:00
61a488a25d bump to version 0.3.26 2024-09-16 15:29:54 -06:00
4fd2319d53 fix error is OfferDialog where assignment to a project was missed, plus some refactors 2024-09-16 15:12:32 -06:00
008ae9e906 fix alert when looking at one's own activity 2024-09-15 19:53:12 -06:00
8111b0e5cf modify the settings to allow account-specific settings, eg. for "isRegistered" 2024-09-15 16:30:46 -06:00
fe627ed6b2 include some DID info on the contact list page 2024-08-31 13:05:59 -06:00
5b9e767f88 bump version and add "-beta" 2024-08-30 22:05:43 -06:00
8a8ebaf894 bump version to 0.3.25 2024-08-30 21:59:15 -06:00
0947c55110 remove the last of the localStorage for passing parameters 2024-08-30 21:55:08 -06:00
b15476e379 bump version to 0.3.24 2024-08-30 20:51:13 -06:00
c7cac6c894 fix so "not named" shows on detail screen for anonymous 2024-08-30 20:44:07 -06:00
9a9c9d3a06 jump from ideas directly into giving dialog choice 2024-08-30 20:37:36 -06:00
eec55e95be add message when no projects are found in a search, and bump to version 0.3.23 2024-08-30 14:55:06 -06:00
5151052202 fix test BVC setting, remove stray console.outs 2024-08-30 14:28:22 -06:00
4ed26f9464 bump to version 0.3.22 2024-08-30 12:56:25 -06:00
Jose Olarte III
514ac7b8b5 Variable website, date and time 2024-08-30 16:56:37 +08:00
Jose Olarte III
10a0313eeb Merge branch 'master' into test-playwright 2024-08-30 15:37:30 +08:00
8f22f9365c add wording in help page 2024-08-29 20:02:57 -06:00
676a03d379 change tests assuming result will be at top 2024-08-29 19:49:35 -06:00
6f7b197667 add blurbs for different audiences in Help, and allow a link for direct search on project discovery page 2024-08-29 19:25:34 -06:00
Jose Olarte III
22f85f2321 Improved create project test
- Added editing to test
- Added variables for other values
2024-08-29 19:25:02 +08:00
Jose Olarte III
7aeeeed229 Removed test.slow() 2024-08-28 19:32:51 +08:00
Jose Olarte III
4228d3c390 Moved common functions to testUtils 2024-08-28 19:12:59 +08:00
Jose Olarte III
2e2705eae8 Remove unneeded timeouts 2024-08-28 16:24:50 +08:00
Jose Olarte III
0e4e6c96e2 Merge branch 'master' into test-playwright 2024-08-28 16:12:52 +08:00
Jose Olarte III
541d8e9935 Remove PWA test
Created a new branch for this specific test, instead
2024-08-28 16:12:30 +08:00
d777856bbf bump to version 0.3.21 2024-08-24 08:36:14 -06:00
b5a833cc11 after copying personal data, add a message to copy contacts for them 2024-08-24 07:56:23 -06:00
9e98a9ab43 add test for new name-entry & copy-to-clipboard flow 2024-08-24 07:23:49 -06:00
d3a4377935 make the user-name pop-up the preferred way to set the name 2024-08-24 06:36:49 -06:00
f2cb7d3ed8 prompt for name when showing info, and provide a "copy" page when remote 2024-08-23 20:06:50 -06:00
431672fd63 move some buttons to take less space at the top of Home 2024-08-23 15:22:48 -06:00
2d450e6455 add test for registration of new user 2024-08-22 20:21:37 -06:00
89 changed files with 7998 additions and 2350 deletions

View File

@@ -1,4 +1,6 @@
# Only the variables that start with VITE_ are seen in the application import.meta.env in Vue. # Only the variables that start with VITE_ are seen in the application import.meta.env in Vue.
VITE_APP_SERVER=https://timesafari.app
VITE_BVC_MEETUPS_PROJECT_CLAIM_ID=https://endorser.ch/entity/01GXYPFF7FA03NXKPYY142PY4H VITE_BVC_MEETUPS_PROJECT_CLAIM_ID=https://endorser.ch/entity/01GXYPFF7FA03NXKPYY142PY4H
VITE_DEFAULT_ENDORSER_API_SERVER=https://api.endorser.ch VITE_DEFAULT_ENDORSER_API_SERVER=https://api.endorser.ch
VITE_DEFAULT_IMAGE_API_SERVER=https://image-api.timesafari.app VITE_DEFAULT_IMAGE_API_SERVER=https://image-api.timesafari.app
VITE_DEFAULT_PARTNER_API_SERVER=https://partner-api.timesafari.app

View File

@@ -14,8 +14,21 @@ module.exports = {
// ecmaVersion: 2020, // ecmaVersion: 2020,
// }, // },
rules: { rules: {
"max-len": [
"warn",
{
code: 120,
ignoreComments: true, // why does this not make it allow comment of any length?
ignorePattern: '^\\s*class="[^"]*"$',
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreTrailingComments: true,
ignoreUrls: true,
},
],
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off", "no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off", "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
// "prettier/prettier": ["warn", { printWidth: 120 }], // removes errors but adds thousands of warnings
"@typescript-eslint/no-unnecessary-type-constraint": "off", "@typescript-eslint/no-unnecessary-type-constraint": "off",
}, },
}; };

View File

@@ -6,9 +6,88 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## ? ## [0.3.35] - 2024.11.24
### Added ### Added
- Send list of contacts to someone - Daily reliable, hard-coded notification message
- Setting to change the partner API server
## [0.3.33] - 2024.11.07 - adb7b16ecf1343c39cba71a7d6bb0e7a973e1102
### Fixed
- Affirm Delivery button on offer claim page didn't work.
- Plans were not showing by default on project page.
## [0.3.32] - 2024.11.06 - 9a3fa38a3fd28f977e06f0265fc39e635c9c5ccd
### Added
- Highlight new offers to user & to user's projects on the front page.
## [0.3.31] - 2024.10.25 - 07c02ab98a09d293dd90d9289a7872e7d681d296
### Changed
- Onboarding messages about offers
## [0.3.30]
### Added
- Onboarding messages
## [0.3.29] - 2024.10.09 - babd3832bdfe0c40eaa3869de1b41399a51713c1
### Added
- Invite for a contact to join immediately
### Changed
- Send signed data to nostr endpoints to verify public key ownership.
- Enhanced help & help onboarding.
### Changed in DB or environment
- Uses Endorser.ch version 4.1.1
## [0.3.28] - 2024.09.30 - 84720b94049d29cc0ddd99c50cef2e7176130133
### Added
- Posting to nostr apps Trustroots & TripHopping
- Display of providers on claim view page
### Changed
- Switched BVC-meeting-ending gift to be a gift from the group.
### Changed in DB or environment
- Requires Endorser.ch version 4.1.0
## [0.3.27] - 2024.09.22 - ee23e6f005e47f5bd6f04d804599f6395371b0e4
### Fixed
- Error loading BVC claims to confirm
- Really allow visibility of bulk-imported contacts
## [0.3.26] - 2024.09.16 - 8263ed2b29947b3ccc6f3133bbc9454c222bce28
### Added
- Separate 'isRegistered' flag for each account
### Fixed
- Failure to assign offers to their project
- Alert when looking at one's own activity if not in contacts.
## [0.3.25] - 2024.08.30 - dcbe02d877aecb4cdef2643d90e6595d246a9f82
### Added
- "Ideas" now jumps directly to giving prompt or contact list.
### Fixed
- Empty giver name on gifted-details view
- Previously visited project would show up on the giving-details page.
### Removed
- All unnecessary localStorage for project IDs
## [0.3.23] - 2024.08.30
### Added
- Sections in Help for different kinds of users
- Discovery page parameters so that links with search text work
- Message when no projects are found
## [0.3.21] - 2024.08.24 - a7b89f4bb6da928d56daeffaae7741fa74cc80bf
### Added
- Send list of contacts to someone, and move individual contact actions to detail page.
- Prompt for name in pop-up, and send to different contact-sharing screens.
### Changed ### Changed
- Moved contact actions from list onto detail page - Moved contact actions from list onto detail page

View File

@@ -21,6 +21,8 @@ npm install
npm run dev npm run dev
``` ```
See the test locations for "IMAGE_API_SERVER" or "PARTNER_API_SERVER" below, or use http://localhost:3000 for local endorser.ch
### Build the test & production app ### Build the test & production app
``` ```
npm run serve npm run serve
@@ -31,6 +33,14 @@ npm run serve
npm run lint npm run lint
``` ```
### Run all important tests
... including automated UI tests (see below for details)
```
npm run test-all
```
### Compile and minify for test & production ### Compile and minify for test & production
* If there are DB changes: before updating the test server, open browser(s) with current version to test DB migrations. * If there are DB changes: before updating the test server, open browser(s) with current version to test DB migrations.
@@ -41,7 +51,9 @@ npm run lint
* Commit everything (since the commit hash is used the app). * Commit everything (since the commit hash is used the app).
* Record what version is currently on production. * Put the commit hash in the changelog (which will help you remember to bump the version later).
* Record what version is currently on production in docs.
* Run the correct build: * Run the correct build:
@@ -49,7 +61,7 @@ npm run lint
``` ```
# (Let's replace this with a .env.development or .env.staging file.) # (Let's replace this with a .env.development or .env.staging file.)
# The test BVC_MEETUPS_PROJECT_CLAIM_ID does not resolve as a URL because it's only in the test DB and the prod redirect won't redirect there. # The test BVC_MEETUPS_PROJECT_CLAIM_ID does not resolve as a URL because it's only in the test DB and the prod redirect won't redirect there.
TIME_SAFARI_APP_TITLE="TimeSafari_Test" VITE_BVC_MEETUPS_PROJECT_CLAIM_ID=https://endorser.ch/entity/01HNTZYJJXTGT0EZS3VEJGX7AK VITE_DEFAULT_ENDORSER_API_SERVER=https://test-api.endorser.ch VITE_DEFAULT_IMAGE_API_SERVER=https://test-image-api.timesafari.app VITE_PASSKEYS_ENABLED=yep npm run build TIME_SAFARI_APP_TITLE="TimeSafari_Test" VITE_APP_SERVER=https://test.timesafari.app VITE_BVC_MEETUPS_PROJECT_CLAIM_ID=https://endorser.ch/entity/01HWE8FWHQ1YGP7GFZYYPS272F VITE_DEFAULT_ENDORSER_API_SERVER=https://test-api.endorser.ch VITE_DEFAULT_IMAGE_API_SERVER=https://test-image-api.timesafari.app VITE_DEFAULT_PARTNER_API_SERVER=https://test-partner-api.endorser.ch VITE_PASSKEYS_ENABLED=true npm run build
``` ```
* Production * Production
@@ -62,7 +74,7 @@ npm run build
* `rsync -azvu -e "ssh -i ~/.ssh/..." dist ubuntutest@test.timesafari.app:time-safari` * `rsync -azvu -e "ssh -i ~/.ssh/..." dist ubuntutest@test.timesafari.app:time-safari`
* Commit changes. Record the new hash in the changelog. Edit package.json to increment version & add "-beta", `npm install`, and commit. Also record what version is on production. * Record the new hash in the changelog. Edit package.json to increment version & add "-beta", `npm install`, and commit. Also record what version is on production.
* [Tag with the new version.](https://gitea.anomalistdesign.com/trent_larson/crowd-funder-for-time-pwa/releases) * [Tag with the new version.](https://gitea.anomalistdesign.com/trent_larson/crowd-funder-for-time-pwa/releases)
@@ -97,7 +109,7 @@ It's possible to use the global test Endorser (ledger) server (but currently the
It's possible to run with a minimal set of data: the following starts with the bare minimum of test data (but currently the tests don't all succeed): It's possible to run with a minimal set of data; the following starts with the bare minimum of test data:
``` ```
rm ../endorser-ch-test-local.sqlite3 rm ../endorser-ch-test-local.sqlite3
NODE_ENV=test-local npm run flyway migrate NODE_ENV=test-local npm run flyway migrate
@@ -106,6 +118,13 @@ NODE_ENV=test-local npm run dev
``` ```
To run a single test like above with the screenshots, use the following:
```
npx playwright test -c playwright.config-local.ts --trace on test-playwright/40-add-contact.spec.ts
```
### Register new user on test server ### Register new user on test server
On the test server, User #0 has rights to register others, so you can start On the test server, User #0 has rights to register others, so you can start

2225
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "TimeSafari", "name": "TimeSafari",
"version": "0.3.21-beta", "version": "0.3.35",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"serve": "vite preview", "serve": "vite preview",
@@ -12,6 +12,10 @@
"test-all": "npm run build && npx playwright test -c playwright.config-local.ts --trace on" "test-all": "npm run build && npx playwright test -c playwright.config-local.ts --trace on"
}, },
"dependencies": { "dependencies": {
"@capacitor/android": "^6.1.2",
"@capacitor/cli": "^6.1.2",
"@capacitor/core": "^6.1.2",
"@capacitor/ios": "^6.1.2",
"@dicebear/collection": "^5.4.1", "@dicebear/collection": "^5.4.1",
"@dicebear/core": "^5.4.1", "@dicebear/core": "^5.4.1",
"@ethersproject/hdnode": "^5.7.0", "@ethersproject/hdnode": "^5.7.0",
@@ -41,6 +45,7 @@
"dexie": "^3.2.7", "dexie": "^3.2.7",
"dexie-export-import": "^4.1.1", "dexie-export-import": "^4.1.1",
"did-jwt": "^7.4.7", "did-jwt": "^7.4.7",
"did-resolver": "^4.1.0",
"ethereum-cryptography": "^2.1.3", "ethereum-cryptography": "^2.1.3",
"ethereumjs-util": "^7.1.5", "ethereumjs-util": "^7.1.5",
"jdenticon": "^3.2.0", "jdenticon": "^3.2.0",
@@ -50,6 +55,7 @@
"lru-cache": "^10.2.0", "lru-cache": "^10.2.0",
"luxon": "^3.4.4", "luxon": "^3.4.4",
"merkletreejs": "^0.3.11", "merkletreejs": "^0.3.11",
"nostr-tools": "^2.7.2",
"notiwind": "^2.0.2", "notiwind": "^2.0.2",
"papaparse": "^5.4.1", "papaparse": "^5.4.1",
"pina": "^0.20.2204228", "pina": "^0.20.2204228",

View File

@@ -1,4 +1,4 @@
import { defineConfig, devices } from '@playwright/test'; import { defineConfig, devices } from "@playwright/test";
/** /**
* Read environment variables from file. * Read environment variables from file.
@@ -11,7 +11,7 @@ import { defineConfig, devices } from '@playwright/test';
* See https://playwright.dev/docs/test-configuration. * See https://playwright.dev/docs/test-configuration.
*/ */
export default defineConfig({ export default defineConfig({
testDir: './test-playwright', testDir: "./test-playwright",
/* Run tests in files in parallel */ /* Run tests in files in parallel */
fullyParallel: true, fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */ /* Fail the build on CI if you accidentally left test.only in the source code. */
@@ -21,44 +21,44 @@ export default defineConfig({
/* Opt out of parallel tests on CI. */ /* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined, workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ /* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html', reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: { use: {
/* Base URL to use in actions like `await page.goto('/')`. */ /* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://localhost:8080', baseURL: "http://localhost:8080",
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry', trace: "on-first-retry",
}, },
/* Configure projects for major browsers */ /* Configure projects for major browsers */
projects: [ projects: [
{ {
name: 'chromium', name: "chromium",
use: { use: {
...devices['Desktop Chrome'], ...devices["Desktop Chrome"],
permissions: ["clipboard-read"], permissions: ["clipboard-read"],
}, },
}, },
{ {
name: 'firefox', name: "firefox",
use: { ...devices['Desktop Firefox'] }, use: { ...devices["Desktop Firefox"] },
}, },
{ {
name: 'webkit', name: "webkit",
use: { ...devices['Desktop Safari'] }, use: { ...devices["Desktop Safari"] },
}, },
/* Test against mobile viewports. */ /* Test against mobile viewports. */
{ {
name: 'Mobile Chrome', name: "Mobile Chrome",
use: { ...devices['Pixel 5'] }, use: { ...devices["Pixel 5"] },
}, },
{ {
name: 'Mobile Safari', name: "Mobile Safari",
use: { ...devices['iPhone 12'] }, use: { ...devices["iPhone 12"] },
}, },
/* Test against branded browsers. */ /* Test against branded browsers. */
@@ -67,14 +67,14 @@ export default defineConfig({
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, // use: { ...devices['Desktop Edge'], channel: 'msedge' },
// }, // },
{ {
name: 'Google Chrome', name: "Google Chrome",
use: { ...devices['Desktop Chrome'], channel: 'chrome' }, use: { ...devices["Desktop Chrome"], channel: "chrome" },
}, },
], ],
/* Configure global timeout; default is 30000 milliseconds */ /* Configure global timeout; default is 30000 milliseconds */
// the image upload will often not succeed at 5 seconds // the image upload will often not succeed at 5 seconds
timeout: 20000, // timeout: 10000,
/* Run your local dev server before starting the tests */ /* Run your local dev server before starting the tests */
/** /**
@@ -91,7 +91,7 @@ export default defineConfig({
*/ */
webServer: { webServer: {
command: command:
"VITE_PASSKEYS_ENABLED=true VITE_DEFAULT_ENDORSER_API_SERVER=http://localhost:3000 npm run dev", "VITE_APP_SERVER=http://localhost:8080 VITE_DEFAULT_ENDORSER_API_SERVER=http://localhost:3000 VITE_PASSKEYS_ENABLED=true npm run dev",
url: "http://localhost:8080", url: "http://localhost:8080",
reuseExistingServer: !process.env.CI, reuseExistingServer: !process.env.CI,
}, },

View File

@@ -0,0 +1,86 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="512.000000pt" height="512.000000pt" viewBox="0 0 512.000000 512.000000"
preserveAspectRatio="xMidYMid meet">
<g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M2480 4005 c-25 -7 -58 -20 -75 -29 -16 -9 -40 -16 -52 -16 -17 0
-24 -7 -28 -27 -3 -16 -14 -45 -24 -65 -21 -41 -13 -55 18 -38 25 13 67 13 92
-1 15 -8 35 -4 87 17 99 39 130 41 197 10 64 -29 77 -31 107 -15 20 11 20 11
-3 35 -12 13 -30 24 -38 24 -24 1 -132 38 -148 51 -8 7 -11 20 -7 32 12 37
-40 47 -126 22z"/>
<path d="M1450 3775 c-7 -8 -18 -15 -24 -15 -7 0 -31 -14 -54 -32 -29 -22 -38
-34 -29 -40 17 -11 77 -10 77 1 0 5 16 16 35 25 60 29 220 19 290 -18 17 -9
33 -16 37 -16 4 0 31 -15 60 -34 108 -70 224 -215 282 -353 30 -71 53 -190 42
-218 -10 -27 -23 -8 -52 75 -30 90 -88 188 -120 202 -13 6 -26 9 -29 6 -3 -2
11 -51 30 -108 28 -83 35 -119 35 -179 0 -120 -22 -127 -54 -17 -11 37 -13 21
-18 -154 -5 -180 -8 -200 -32 -264 -51 -132 -129 -245 -199 -288 -21 -12 -79
-49 -129 -80 -161 -102 -294 -141 -473 -141 -228 0 -384 76 -535 259 -81 99
-118 174 -154 312 -31 121 -35 273 -11 437 19 127 19 125 -4 125 -23 0 -51
-34 -87 -104 -14 -28 -33 -64 -41 -81 -19 -34 -22 -253 -7 -445 9 -106 12
-119 44 -170 19 -30 42 -67 50 -81 64 -113 85 -140 130 -169 28 -18 53 -44 61
-62 8 -20 36 -45 83 -76 62 -39 80 -46 151 -54 44 -5 96 -13 115 -18 78 -20
238 -31 282 -19 24 6 66 8 95 5 76 -9 169 24 319 114 32 19 80 56 106 82 27
26 52 48 58 48 5 0 27 26 50 58 48 66 56 70 132 71 62 1 165 29 238 64 112 55
177 121 239 245 37 76 39 113 10 267 -12 61 -23 131 -26 156 -5 46 -5 47 46
87 92 73 182 70 263 -8 l51 -49 -6 -61 c-4 -34 -13 -85 -21 -113 -28 -103 -30
-161 -4 -228 16 -44 32 -67 55 -83 18 -11 39 -37 47 -58 10 -23 37 -53 73 -81
32 -25 69 -57 82 -71 14 -14 34 -26 47 -26 12 0 37 -7 56 -15 20 -8 66 -17
104 -20 107 -10 110 -11 150 -71 50 -75 157 -177 197 -187 18 -5 53 -24 78
-42 71 -51 176 -82 304 -89 61 -4 127 -12 147 -18 29 -9 45 -8 77 6 23 9 50
16 60 16 31 0 163 46 216 76 28 15 75 46 105 69 30 23 69 49 85 58 17 8 46 31
64 51 19 20 40 36 47 36 18 0 77 70 100 120 32 66 45 108 55 173 5 32 16 71
24 87 43 84 43 376 0 549 -27 105 -43 127 -135 188 -30 21 -65 46 -77 57 -13
11 -23 17 -23 14 0 -3 21 -46 47 -94 79 -151 85 -166 115 -263 25 -83 28 -110
28 -226 0 -144 -17 -221 -75 -335 -39 -77 -208 -244 -304 -299 -451 -263 -975
-67 -1138 426 -23 70 -26 95 -28 254 -1 108 -7 183 -14 196 -6 12 -11 31 -11
43 0 32 31 122 52 149 10 13 18 28 18 34 0 5 25 40 56 78 60 73 172 170 219
190 30 12 30 13 6 17 -15 2 -29 -2 -37 -12 -6 -9 -16 -16 -22 -16 -6 0 -23
-11 -39 -24 -15 -12 -33 -25 -40 -27 -17 -6 -82 -60 -117 -97 -65 -70 -75 -82
-107 -133 -23 -34 -35 -46 -37 -35 -3 16 20 87 44 134 6 12 9 34 6 48 -4 22
-8 25 -31 19 -14 -3 -38 -15 -53 -26 -34 -24 -34 -21 -6 28 65 112 184 206
291 227 15 3 39 9 55 12 l27 6 -24 9 c-90 35 -304 -66 -478 -225 -39 -36 -74
-66 -77 -66 -22 0 18 82 72 148 19 23 32 46 28 49 -4 4 -26 13 -49 19 -73 21
-161 54 -171 64 -6 6 -20 10 -32 10 -21 0 -21 -1 -8 -40 45 -130 8 -247 -93
-299 -25 -13 -31 0 -14 29 15 22 1 33 -22 17 -56 -36 -117 -22 -117 28 0 13
-16 47 -35 76 -22 34 -33 60 -29 73 4 16 -3 26 -26 39 -16 10 -30 21 -30 25 1
18 54 64 87 76 l38 13 -33 5 c-30 4 -115 -18 -154 -42 -13 -7 -20 -5 -27 8 -9
16 -12 16 -53 1 -160 -61 -258 -104 -258 -114 0 -7 10 -20 21 -31 103 -91 217
-297 249 -449 28 -135 41 -237 35 -276 -14 -91 -48 -170 -97 -220 -44 -47 -68
-60 -68 -40 0 6 4 12 8 15 5 3 24 35 42 72 l33 67 -6 141 c-4 103 -11 158 -26
205 -12 35 -21 70 -21 77 0 7 -20 56 -45 108 -82 173 -227 322 -392 401 -67
33 -90 39 -163 42 -108 5 -130 10 -130 28 0 20 -63 20 -80 0z"/>
<path d="M3710 3765 c0 -20 8 -28 39 -41 22 -8 42 -22 45 -30 5 -14 42 -19 70
-8 10 4 -7 21 -58 55 -41 27 -79 49 -85 49 -6 0 -11 -11 -11 -25z"/>
<path d="M3173 3734 c-9 -25 10 -36 35 -18 12 8 22 19 22 25 0 16 -50 10 -57
-7z"/>
<path d="M1982 3728 c6 -16 36 -34 44 -26 3 4 4 14 1 23 -7 17 -51 21 -45 3z"/>
<path d="M1540 3620 c0 -5 7 -10 16 -10 8 0 12 5 9 10 -3 6 -10 10 -16 10 -5
0 -9 -4 -9 -10z"/>
<path d="M4467 3624 c-4 -4 23 -27 60 -50 84 -56 99 -58 67 -9 -28 43 -107 79
-127 59z"/>
<path d="M655 3552 c-11 -2 -26 -9 -33 -14 -7 -6 -27 -18 -45 -27 -36 -18 -58
-64 -39 -83 9 -9 25 1 70 43 53 48 78 78 70 84 -2 1 -12 -1 -23 -3z"/>
<path d="M1015 3460 c-112 -24 -247 -98 -303 -165 -53 -65 -118 -214 -136
-311 -20 -113 -20 -145 -1 -231 20 -88 49 -153 102 -230 79 -113 186 -182 331
-214 108 -24 141 -24 247 1 130 30 202 72 316 181 102 100 153 227 152 384 0
142 -58 293 -150 395 -60 67 -180 145 -261 171 -75 23 -232 34 -297 19z m340
-214 c91 -43 174 -154 175 -234 0 -18 -9 -51 -21 -73 -19 -37 -19 -42 -5 -64
35 -54 12 -121 -48 -142 -22 -7 -47 -19 -55 -27 -9 -8 -41 -27 -71 -42 -50
-26 -64 -29 -155 -29 -111 0 -152 14 -206 68 -49 49 -63 85 -64 162 0 59 4 78
28 118 31 52 96 105 141 114 23 5 33 17 56 68 46 103 121 130 225 81z"/>
<path d="M3985 3464 c-44 -7 -154 -44 -200 -67 -55 -28 -138 -96 -162 -132
-10 -16 -39 -75 -64 -130 l-44 -100 0 -160 0 -160 45 -90 c53 -108 152 -214
245 -264 59 -31 215 -71 281 -71 53 0 206 40 255 67 98 53 203 161 247 253 53
113 74 193 74 280 -1 304 -253 564 -557 575 -49 2 -103 1 -120 -1z m311 -220
c129 -68 202 -209 160 -309 -15 -35 -15 -42 -1 -72 26 -55 -3 -118 -59 -129
-19 -3 -43 -15 -53 -26 -26 -29 -99 -64 -165 -78 -45 -10 -69 -10 -120 -1 -74
15 -113 37 -161 91 -110 120 -50 331 109 385 24 8 44 23 52 39 6 14 18 38 25
53 33 72 127 93 213 47z"/>
<path d="M487 3394 c-21 -12 -27 -21 -25 -40 2 -14 7 -26 12 -27 14 -3 48 48
44 66 -3 14 -6 14 -31 1z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@@ -180,8 +180,9 @@
" "
class="block w-full text-center text-md font-bold uppercase bg-blue-600 text-white px-2 py-2 rounded-md mb-2" class="block w-full text-center text-md font-bold uppercase bg-blue-600 text-white px-2 py-2 rounded-md mb-2"
> >
Yes Yes{{
{{ notification.yesText ? ", " + notification.yesText : "" }} notification.yesText ? ", " + notification.yesText : ""
}}
</button> </button>
<button <button
@@ -193,7 +194,7 @@
" "
class="block w-full text-center text-md font-bold uppercase bg-yellow-600 text-white px-2 py-2 rounded-md mb-2" class="block w-full text-center text-md font-bold uppercase bg-yellow-600 text-white px-2 py-2 rounded-md mb-2"
> >
No {{ notification.noText ? ", " + notification.noText : "" }} No{{ notification.noText ? ", " + notification.noText : "" }}
</button> </button>
<label <label
@@ -228,7 +229,7 @@
? notification.onCancel(stopAsking) ? notification.onCancel(stopAsking)
: null; : null;
close(notification.id); close(notification.id);
stopAsking = false; // reset value stopAsking = false; // reset value for next time they open this modal
" "
class="block w-full text-center text-md font-bold uppercase bg-slate-600 text-white px-2 py-2 rounded-md" class="block w-full text-center text-md font-bold uppercase bg-slate-600 text-white px-2 py-2 rounded-md"
> >
@@ -237,63 +238,7 @@
</div> </div>
</div> </div>
</div> </div>
<div
v-if="notification.type === 'notification-permission'"
class="absolute inset-0 h-screen flex flex-col items-center justify-center bg-slate-900/50"
>
<div
class="flex w-11/12 max-w-sm mx-auto mb-3 overflow-hidden bg-white rounded-lg shadow-lg"
>
<div class="w-full px-6 py-6 text-slate-900 text-center">
<p v-if="serviceWorkerReady" class="text-lg mb-4">
Would you like to be notified of new activity once a day?
</p>
<p v-else class="text-lg mb-4">
Waiting for system initialization, which may take up to 10
seconds...
<fa icon="spinner" spin />
</p>
<div v-if="serviceWorkerReady">
<span class="flex flex-row justify-center">
<span class="mt-2">Yes, tell me at: </span>
<input
type="number"
class="rounded-l border border-r-0 border-slate-400 ml-2 mt-2 px-2 py-2 text-center w-20"
v-model="hourInput"
/>
<span
class="rounded-r border border-slate-400 bg-slate-200 text-center text-blue-500 mt-2 px-2 py-2 w-20"
@click="hourAm = !hourAm"
>
<span v-if="hourAm"> AM <fa icon="chevron-down" /> </span>
<span v-else> PM <fa icon="chevron-up" /> </span>
</span>
</span>
<button
class="block w-full text-center text-md font-bold uppercase bg-blue-600 text-white mt-2 px-2 py-2 rounded-md"
@click="
() => {
if (checkHour()) {
close(notification.id);
turnOnNotifications();
}
}
"
>
Turn on Daily Message
</button>
</div>
<button
@click="close(notification.id)"
class="block w-full text-center text-md font-bold uppercase bg-slate-600 text-white mt-4 px-2 py-2 rounded-md"
>
No, Not Now
</button>
</div>
</div>
</div>
<div <div
v-if="notification.type === 'notification-mute'" v-if="notification.type === 'notification-mute'"
class="absolute inset-0 h-screen flex flex-col items-center justify-center bg-slate-900/50" class="absolute inset-0 h-screen flex flex-col items-center justify-center bg-slate-900/50"
@@ -307,17 +252,17 @@
<button <button
class="block w-full text-center text-md font-bold uppercase bg-blue-600 text-white px-2 py-2 rounded-md mb-2" class="block w-full text-center text-md font-bold uppercase bg-blue-600 text-white px-2 py-2 rounded-md mb-2"
> >
For 1 Hour For 1 Day
</button> </button>
<button <button
class="block w-full text-center text-md font-bold uppercase bg-blue-600 text-white px-2 py-2 rounded-md mb-2" class="block w-full text-center text-md font-bold uppercase bg-blue-600 text-white px-2 py-2 rounded-md mb-2"
> >
For 8 Hours For 2 Days
</button> </button>
<button <button
class="block w-full text-center text-md font-bold uppercase bg-blue-600 text-white px-2 py-2 rounded-md mb-2" class="block w-full text-center text-md font-bold uppercase bg-blue-600 text-white px-2 py-2 rounded-md mb-2"
> >
For 24 Hours For 1 Week
</button> </button>
<button <button
class="block w-full text-center text-md font-bold uppercase bg-blue-600 text-white px-2 py-2 rounded-md mb-2" class="block w-full text-center text-md font-bold uppercase bg-blue-600 text-white px-2 py-2 rounded-md mb-2"
@@ -333,6 +278,7 @@
</div> </div>
</div> </div>
</div> </div>
<div <div
v-if="notification.type === 'notification-off'" v-if="notification.type === 'notification-off'"
class="absolute inset-0 h-screen flex flex-col items-center justify-center bg-slate-900/50" class="absolute inset-0 h-screen flex flex-col items-center justify-center bg-slate-900/50"
@@ -342,17 +288,17 @@
> >
<div class="w-full px-6 py-6 text-slate-900 text-center"> <div class="w-full px-6 py-6 text-slate-900 text-center">
<p class="text-lg mb-4"> <p class="text-lg mb-4">
Would you like to <b>turn off</b> notifications for this app? Would you like to <b>turn off</b> this notification?
</p> </p>
<button <button
@click=" @click="
close(notification.id); close(notification.id);
turnOffNotifications(); turnOffNotifications(notification);
" "
class="block w-full text-center text-md font-bold uppercase bg-rose-600 text-white px-2 py-2 rounded-md mb-2" class="block w-full text-center text-md font-bold uppercase bg-rose-600 text-white px-2 py-2 rounded-md mb-2"
> >
Turn Off Notifications Turn Off Notification
</button> </button>
<button <button
@click="close(notification.id)" @click="close(notification.id)"
@@ -372,420 +318,108 @@
<style></style> <style></style>
<script lang="ts"> <script lang="ts">
import axios from "axios";
import { Vue, Component } from "vue-facing-decorator"; import { Vue, Component } from "vue-facing-decorator";
import * as libsUtil from "@/libs/util"; import { logConsoleAndDb, retrieveSettingsForActiveAccount } from "@/db/index";
import { NotificationIface } from "./constants/app";
interface ServiceWorkerMessage {
type: string;
data: string;
}
interface ServiceWorkerResponse {
// Define the properties and their types
success: boolean;
message?: string;
}
// Example interface for error
interface ErrorResponse {
message: string;
// Other properties as needed
}
interface VapidResponse {
data: {
vapidKey: string;
};
}
interface PushSubscriptionWithTime extends PushSubscriptionJSON {
notifyTime: { utcHour: number };
}
import { DEFAULT_PUSH_SERVER, NotificationIface } from "@/constants/app";
import { db } from "@/db/index";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { sendTestThroughPushServer } from "@/libs/util";
@Component @Component
export default class App extends Vue { export default class App extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void; $notify!: (notification: NotificationIface, timeout?: number) => void;
stopAsking = false; stopAsking = false;
b64 = "";
hourAm = true;
hourInput = "8";
serviceWorkerReady = true;
async mounted() { async turnOffNotifications(notification: NotificationIface) {
try { let subscription: object | null = null;
await db.open();
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
let pushUrl = DEFAULT_PUSH_SERVER;
if (settings?.webPushServer) {
pushUrl = settings.webPushServer;
}
if (pushUrl.startsWith("http://localhost")) { let allGoingOff = false;
console.log("Not checking for VAPID in this local environment."); const settings = await retrieveSettingsForActiveAccount();
} else { const notifyingNewActivity = !!settings?.notifyingNewActivityTime;
await axios const notifyingReminder = !!settings?.notifyingReminderTime;
.get(pushUrl + "/web-push/vapid") if (!notifyingNewActivity || !notifyingReminder) {
.then((response: VapidResponse) => { // the other notification is already off, so fully unsubscribe now
this.b64 = response.data?.vapidKey || ""; allGoingOff = true;
console.log("Got vapid key:", this.b64);
navigator.serviceWorker.addEventListener("controllerchange", () => {
console.log("New service worker is now controlling the page");
});
});
if (!this.b64) {
this.$notify(
{
group: "alert",
type: "danger",
title: "Error Setting Notifications",
text: "Could not set notifications.",
},
-1,
);
}
}
} catch (error) {
if (window.location.host.startsWith("localhost")) {
console.log("Ignoring the error getting VAPID for local development.");
} else {
console.error("Got an error initializing notifications:", error);
this.$notify(
{
group: "alert",
type: "danger",
title: "Error Setting Notifications",
text: "Got an error setting notifications.",
},
-1,
);
}
}
// there may be a long pause here on first initialization
navigator.serviceWorker?.ready.then(() => {
this.serviceWorkerReady = true;
});
}
private sendMessageToServiceWorker(
message: ServiceWorkerMessage,
): Promise<unknown> {
return new Promise((resolve, reject) => {
if (navigator.serviceWorker.controller) {
const messageChannel = new MessageChannel();
messageChannel.port1.onmessage = (event: MessageEvent) => {
if (event.data.error) {
reject(event.data.error as ErrorResponse);
} else {
resolve(event.data as ServiceWorkerResponse);
}
};
navigator.serviceWorker.controller.postMessage(message, [
messageChannel.port2,
]);
} else {
reject("Service worker controller not available");
}
});
}
private askPermission(): Promise<NotificationPermission> {
console.log("Requesting permission for notifications:", navigator);
if (!("serviceWorker" in navigator && navigator.serviceWorker.controller)) {
return Promise.reject("Service worker not available.");
} }
const secret = localStorage.getItem("secret"); await navigator.serviceWorker?.ready
if (!secret) {
return Promise.reject("No secret found.");
}
return this.sendSecretToServiceWorker(secret)
.then(() => this.checkNotificationSupport())
.then(() => this.requestNotificationPermission())
.catch((error) => Promise.reject(error));
}
private sendSecretToServiceWorker(secret: string): Promise<void> {
const message: ServiceWorkerMessage = {
type: "SEND_LOCAL_DATA",
data: secret,
};
return this.sendMessageToServiceWorker(message).then((response) => {
console.log("Response from service worker:", response);
});
}
private checkNotificationSupport(): Promise<void> {
if (!("Notification" in window)) {
alert("This browser does not support notifications.");
return Promise.reject("This browser does not support notifications.");
}
if (Notification.permission === "granted") {
return Promise.resolve();
}
return Promise.resolve();
}
private requestNotificationPermission(): Promise<NotificationPermission> {
return Notification.requestPermission().then((permission) => {
if (permission !== "granted") {
alert(
"Allow this app permission to make notifications for personal reminders." +
" You can adjust them at any time in your settings.",
);
throw new Error("We weren't granted permission.");
}
return permission;
});
}
// this allows us to show an error without closing the dialog
checkHour() {
if (!libsUtil.isNumeric(this.hourInput)) {
this.$notify(
{
group: "alert",
type: "danger",
title: "Not a Number",
text: "The time must be an hour number.",
},
5000,
);
return false;
}
const hourNum = libsUtil.numberOrZero(this.hourInput);
if (!Number.isInteger(hourNum)) {
this.$notify(
{
group: "alert",
type: "danger",
title: "Not a Whole Number",
text: "The time must be a whole hour number.",
},
5000,
);
return false;
}
if (hourNum < 1 || 12 < hourNum) {
this.$notify(
{
group: "alert",
type: "danger",
title: "Not a Whole Number",
text: "The time must be an hour between 1 and 12.",
},
5000,
);
return false;
}
return true;
}
public async turnOnNotifications() {
return this.askPermission()
.then((permission) => {
console.log("Permission granted:", permission);
// Call the function and handle promises
this.subscribeToPush()
.then(() => {
console.log("Subscribed successfully.");
return navigator.serviceWorker?.ready;
})
.then((registration) => {
return registration.pushManager.getSubscription();
})
.then(async (subscription) => {
if (subscription) {
await this.$notify(
{
group: "alert",
type: "info",
title: "Notification Setup Underway",
text: "Setting up notifications for interesting activity, which takes about 10 seconds. If you don't see a final confirmation, check the 'Troubleshoot' page.",
},
-1,
);
// we already checked that this is a valid hour number
const rawHourNum = libsUtil.numberOrZero(this.hourInput);
const adjHourNum = rawHourNum + (this.hourAm ? 0 : 12);
const hourNum = adjHourNum % 24;
const utcHour =
hourNum + Math.round(new Date().getTimezoneOffset() / 60);
const finalUtcHour = (utcHour + (utcHour < 0 ? 24 : 0)) % 24;
const subscriptionWithTime: PushSubscriptionWithTime = {
notifyTime: { utcHour: finalUtcHour },
...subscription.toJSON(),
};
await this.sendSubscriptionToServer(subscriptionWithTime);
return subscriptionWithTime;
} else {
throw new Error("Subscription object is not available.");
}
})
.then(async (subscription: PushSubscriptionWithTime) => {
console.log(
"Subscription data sent to server and all finished successfully.",
);
await sendTestThroughPushServer(subscription, true);
this.$notify(
{
group: "alert",
type: "success",
title: "Notifications Turned On",
text: "Notifications are on. You should see at least one on your device; if not, check the 'Troubleshoot' page.",
},
-1,
);
})
.catch((error) => {
console.error(
"Subscription or server communication failed:",
error,
);
alert(
"Subscription or server communication failed. Try again in a while.",
);
});
})
.catch((error) => {
console.error(
"An error occurred setting notification permissions:",
error,
);
alert("Some error occurred setting notification permissions.");
});
}
private urlBase64ToUint8Array(base64String: string): Uint8Array {
const padding = "=".repeat((4 - (base64String.length % 4)) % 4);
const base64 = (base64String + padding)
.replace(/-/g, "+")
.replace(/_/g, "/");
const rawData = window.atob(base64);
const outputArray = new Uint8Array(rawData.length);
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i);
}
return outputArray;
}
private subscribeToPush(): Promise<void> {
return new Promise<void>((resolve, reject) => {
if (!("serviceWorker" in navigator && "PushManager" in window)) {
const errorMsg = "Push messaging is not supported";
console.warn(errorMsg);
return reject(new Error(errorMsg));
}
if (Notification.permission !== "granted") {
const errorMsg = "Notification permission not granted";
console.warn(errorMsg);
return reject(new Error(errorMsg));
}
const applicationServerKey = this.urlBase64ToUint8Array(this.b64);
const options: PushSubscriptionOptions = {
userVisibleOnly: true,
applicationServerKey: applicationServerKey,
};
navigator.serviceWorker.ready
.then((registration) => {
return registration.pushManager.subscribe(options);
})
.then((subscription) => {
console.log("Push subscription successful:", subscription);
resolve();
})
.catch((error) => {
console.error("Push subscription failed:", error, options);
// Inform the user about the issue
alert(
"We encountered an issue setting up push notifications. " +
"If you wish to revoke notification permissions, please do so in your browser settings.",
);
reject(error);
});
});
}
private sendSubscriptionToServer(
subscription: PushSubscriptionWithTime,
): Promise<void> {
console.log("About to send subscription...", subscription);
return fetch("/web-push/subscribe", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(subscription),
}).then((response) => {
if (!response.ok) {
throw new Error("Failed to send subscription to server");
}
console.log("Subscription sent to server successfully.");
});
}
async turnOffNotifications() {
let subscription;
const pushProviderSuccess = await navigator.serviceWorker?.ready
.then((registration) => { .then((registration) => {
return registration.pushManager.getSubscription(); return registration.pushManager.getSubscription();
}) })
.then((subscript) => { .then(async (subscript: PushSubscription | null) => {
subscription = subscript; if (subscript) {
if (subscription) { subscription = subscript.toJSON();
return subscription.unsubscribe(); if (allGoingOff) {
await subscript.unsubscribe();
}
} else { } else {
console.log("Subscription object is not available."); logConsoleAndDb("Subscription object is not available.");
return false;
} }
}) })
.catch((error) => { .catch((error) => {
console.error("Push provider server communication failed:", error); logConsoleAndDb(
return false; "Push provider server communication failed: " + JSON.stringify(error),
true,
);
}); });
if (!subscription) {
// there is no endpoint or auth for the server to compare, so we're done
this.$notify(
{
group: "alert",
type: "info",
title: "Finished",
text: "Notifications are off.", // a different message so I know there are none stored
},
5000,
);
return true;
}
const serverSubscription = {
...subscription,
};
if (!allGoingOff) {
serverSubscription["notifyType"] = notification.title;
}
const pushServerSuccess = await fetch("/web-push/unsubscribe", { const pushServerSuccess = await fetch("/web-push/unsubscribe", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify(subscription), body: JSON.stringify(serverSubscription),
}) })
.then((response) => { .then((response) => {
return response.ok; return response.ok;
}) })
.catch((error) => { .catch((error) => {
console.error("Push server communication failed:", error); logConsoleAndDb(
"Push server communication failed: " + JSON.stringify(error),
true,
);
return false; return false;
}); });
alert( let message;
"Notifications are off. Push provider unsubscribe " + if (pushServerSuccess) {
(pushProviderSuccess ? "succeeded" : "failed") + message = "Notification is off.";
(pushProviderSuccess === pushServerSuccess ? " and" : " but") + } else {
" push server unsubscribe " + message = "Notification is still on. Try to turn it off again.";
(pushServerSuccess ? "succeeded" : "failed") + }
".", this.$notify(
{
group: "alert",
type: "info",
title: "Finished",
text: message,
},
5000,
); );
if (notification.callback) {
// it's OK if the local notifications are still on (especially if the other notification is on)
notification.callback(pushServerSuccess);
}
} }
} }
</script> </script>

View File

@@ -0,0 +1,99 @@
<!-- similar to UserNameDialog -->
<template>
<div v-if="visible" class="dialog-overlay">
<div class="dialog">
<h1 class="text-xl font-bold text-center mb-4">{{ title }}</h1>
{{ message }}
Note that their name is only stored on this device.
<input
type="text"
placeholder="Name"
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
v-model="newText"
/>
<div class="mt-8">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-2">
<button
type="button"
class="block w-full text-center text-lg font-bold uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md mb-2"
@click="onClickSaveChanges()"
>
Save
</button>
<button
type="button"
class="block w-full text-center text-md uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md mb-2"
@click="onClickCancel()"
>
Cancel
</button>
</div>
</div>
</div>
</div>
</template>
<script lang="ts">
import { Vue, Component } from "vue-facing-decorator";
@Component
export default class ContactNameDialog extends Vue {
cancelCallback: () => void = () => {};
saveCallback: (name?: string) => void = () => {};
message = "";
newText = "";
title = "Contact Name";
visible = false;
async open(
title?: string,
message?: string,
saveCallback?: (name?: string) => void,
cancelCallback?: () => void,
) {
this.cancelCallback = cancelCallback || this.cancelCallback;
this.saveCallback = saveCallback || this.saveCallback;
this.message = message ?? this.message;
this.title = title ?? this.title;
this.visible = true;
}
async onClickSaveChanges() {
this.visible = false;
if (this.saveCallback) {
this.saveCallback(this.newText);
}
}
onClickCancel() {
this.visible = false;
if (this.cancelCallback) {
this.cancelCallback();
}
}
}
</script>
<style>
.dialog-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
padding: 1.5rem;
}
.dialog {
background-color: white;
padding: 1rem;
border-radius: 0.5rem;
width: 100%;
max-width: 500px;
}
</style>

View File

@@ -100,7 +100,7 @@ import {
} from "@vue-leaflet/vue-leaflet"; } from "@vue-leaflet/vue-leaflet";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { db } from "@/db/index"; import { db, retrieveSettingsForActiveAccount } from "@/db/index";
@Component({ @Component({
components: { components: {
@@ -121,11 +121,10 @@ export default class FeedFilters extends Vue {
async open(onCloseIfChanged: () => void) { async open(onCloseIfChanged: () => void) {
this.onCloseIfChanged = onCloseIfChanged; this.onCloseIfChanged = onCloseIfChanged;
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); this.hasVisibleDid = !!settings.filterFeedByVisible;
this.hasVisibleDid = !!settings?.filterFeedByVisible; this.isNearby = !!settings.filterFeedByNearby;
this.isNearby = !!settings?.filterFeedByNearby; if (settings.searchBoxes && settings.searchBoxes.length > 0) {
if (settings?.searchBoxes && settings.searchBoxes.length > 0) {
this.hasSearchBox = true; this.hasSearchBox = true;
} }

View File

@@ -7,7 +7,7 @@
<input <input
type="text" type="text"
class="block w-full rounded border border-slate-400 mb-2 px-3 py-2" class="block w-full rounded border border-slate-400 mb-2 px-3 py-2"
placeholder="What was given" :placeholder="prompt || 'What was given?'"
v-model="description" v-model="description"
/> />
<div class="flex flex-row justify-center"> <div class="flex flex-row justify-center">
@@ -47,7 +47,7 @@
giverDid: giver?.did, giverDid: giver?.did,
giverName: giver?.name, giverName: giver?.name,
offerId, offerId,
projectId, fulfillsProjectId: projectId,
recipientDid: receiver?.did, recipientDid: receiver?.did,
recipientName: receiver?.name, recipientName: receiver?.name,
unitCode, unitCode,
@@ -89,14 +89,9 @@
import { Vue, Component, Prop } from "vue-facing-decorator"; import { Vue, Component, Prop } from "vue-facing-decorator";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { import { createAndSubmitGive, didInfo } from "@/libs/endorserServer";
createAndSubmitGive,
didInfo,
GiverReceiverInputInfo,
} from "@/libs/endorserServer";
import * as libsUtil from "@/libs/util"; import * as libsUtil from "@/libs/util";
import { accountsDB, db } from "@/db/index"; import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
@Component @Component
@@ -114,25 +109,27 @@ export default class GiftedDialog extends Vue {
callbackOnSuccess?: (amount: number) => void = () => {}; callbackOnSuccess?: (amount: number) => void = () => {};
customTitle?: string; customTitle?: string;
description = ""; description = "";
giver?: GiverReceiverInputInfo; // undefined means no identified giver agent giver?: libsUtil.GiverReceiverInputInfo; // undefined means no identified giver agent
isTrade = false; isTrade = false;
offerId = ""; offerId = "";
receiver?: GiverReceiverInputInfo; prompt = "";
receiver?: libsUtil.GiverReceiverInputInfo;
unitCode = "HUR"; unitCode = "HUR";
visible = false; visible = false;
libsUtil = libsUtil; libsUtil = libsUtil;
async open( async open(
giver?: GiverReceiverInputInfo, giver?: libsUtil.GiverReceiverInputInfo,
receiver?: GiverReceiverInputInfo, receiver?: libsUtil.GiverReceiverInputInfo,
offerId?: string, offerId?: string,
customTitle?: string, customTitle?: string,
prompt?: string,
callbackOnSuccess?: (amount: number) => void, callbackOnSuccess?: (amount: number) => void,
) { ) {
this.customTitle = customTitle; this.customTitle = customTitle;
this.description = "";
this.giver = giver; this.giver = giver;
this.prompt = prompt || "";
this.receiver = receiver; this.receiver = receiver;
// if we show "given to user" selection, default checkbox to true // if we show "given to user" selection, default checkbox to true
this.amountInput = "0"; this.amountInput = "0";
@@ -140,10 +137,9 @@ export default class GiftedDialog extends Vue {
this.offerId = offerId || ""; this.offerId = offerId || "";
try { try {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; this.apiServer = settings.apiServer || "";
this.apiServer = settings?.apiServer || ""; this.activeDid = settings.activeDid || "";
this.activeDid = settings?.activeDid || "";
this.allContacts = await db.contacts.toArray(); this.allContacts = await db.contacts.toArray();
@@ -207,6 +203,7 @@ export default class GiftedDialog extends Vue {
this.description = ""; this.description = "";
this.giver = undefined; this.giver = undefined;
this.amountInput = "0"; this.amountInput = "0";
this.prompt = "";
this.unitCode = "HUR"; this.unitCode = "HUR";
} }

View File

@@ -19,12 +19,12 @@
</span> </span>
<div class="m-2"> <div class="m-2">
<span v-if="currentIdeaIndex < IDEAS.length"> <span v-if="currentCategory === CATEGORY_IDEAS">
<p class="text-center text-lg font-bold"> <p class="text-center text-lg font-bold">
{{ IDEAS[currentIdeaIndex] }} {{ IDEAS[currentIdeaIndex] }}
</p> </p>
</span> </span>
<div v-if="currentIdeaIndex == IDEAS.length + 0"> <div v-if="currentCategory === CATEGORY_CONTACTS">
<p class="text-center"> <p class="text-center">
<span <span
v-if="currentContact == null" v-if="currentContact == null"
@@ -61,7 +61,7 @@
</span> </span>
<button <button
class="block w-full text-center text-md uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md mt-4" class="block w-full text-center text-md uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md mt-4"
@click="cancel" @click="proceed"
> >
That's it! That's it!
</button> </button>
@@ -71,150 +71,168 @@
<script lang="ts"> <script lang="ts">
import { Vue, Component } from "vue-facing-decorator"; import { Vue, Component } from "vue-facing-decorator";
import { Router } from "vue-router";
import { AppString, NotificationIface } from "@/constants/app"; import { AppString, NotificationIface } from "@/constants/app";
import { db } from "@/db/index"; import { db } from "@/db/index";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import { GiverReceiverInputInfo } from "@/libs/util";
@Component @Component
export default class GivenPrompts extends Vue { export default class GivenPrompts extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void; $notify!: (notification: NotificationIface, timeout?: number) => void;
CATEGORY_CONTACTS = 1;
CATEGORY_IDEAS = 0;
IDEAS = [ IDEAS = [
"Did anyone fix food for you?", "What food did someone fix for you?",
"Did a family member do something for you?", "What did a family member do for you?",
"Did anyone give you a compliment?", "What compliment did someone give you?",
"Who is someone you can always rely on, and how did they demonstrate that?", "Who is someone you can always rely on, and how did they demonstrate that?",
"Did you see anyone give to someone else?", "What did you see someone give to someone else?",
"Is there someone who you have never met who has helped you somehow?", "What is a way that someone helped you even though you have never met?",
"How did an artist or musician or author inspire you?", "How did a musician or author or artist inspire you?",
"What inspiration did you get from someone who handled tragedy well?", "What inspiration did you get from someone who handled tragedy well?",
"Did some organization give something worth respect?", "What is something worth respect that an organization gave you?",
"Who last gave you a good laugh?", "Who last gave you a good laugh?",
"Do you recall anything that was given to you while you were young?", "What do you recall someone giving you while you were young?",
"Did someone forgive you or overlook a mistake?", "Who forgave you or overlooked a mistake?",
"Do you know of a way an ancestor contributed to your life?", "What is a way an ancestor contributed to your life?",
"Did anyone give you help at work?", "What kind of help did someone at work give you?",
"How did a teacher or mentor or great example help you?", "How did a teacher or mentor or great example help you?",
]; ];
OTHER_PROMPTS = 1;
CONTACT_PROMPT_INDEX = this.IDEAS.length; // expected after other prompts
callbackOnFullGiftInfo?: (
contactInfo?: GiverReceiverInputInfo,
description?: string,
) => void;
currentCategory = this.CATEGORY_IDEAS; // 0 = IDEAS, 1 = CONTACTS
currentContact: Contact | undefined = undefined; currentContact: Contact | undefined = undefined;
currentIdeaIndex = 0; currentIdeaIndex = 0;
numContacts = 0; numContacts = 0;
shownContactDbIndices: number[] = []; shownContactDbIndices: Array<boolean> = [];
visible = false; visible = false;
AppString = AppString; AppString = AppString;
async open() { async open(
callbackOnFullGiftInfo: (
contactInfo: GiverReceiverInputInfo,
description: string,
) => void,
) {
this.visible = true; this.visible = true;
this.callbackOnFullGiftInfo = callbackOnFullGiftInfo;
await db.open(); await db.open();
this.numContacts = await db.contacts.count(); this.numContacts = await db.contacts.count();
this.shownContactDbIndices = new Array<boolean>(this.numContacts); // all undefined to start
} }
close() { cancel() {
// close the dialog but don't change values (just in case some actions are added later) this.currentCategory = this.CATEGORY_IDEAS;
this.currentContact = undefined;
this.currentIdeaIndex = 0;
this.numContacts = 0;
this.shownContactDbIndices = [];
this.visible = false; this.visible = false;
} }
proceed() {
// proceed with logic but don't change values (just in case some actions are added later)
this.visible = false;
if (this.currentCategory === this.CATEGORY_IDEAS) {
(this.$router as Router).push({
name: "contact-gift",
query: {
prompt: this.IDEAS[this.currentIdeaIndex],
},
});
} else {
// must be this.CATEGORY_CONTACTS
this.callbackOnFullGiftInfo?.(
this.currentContact as GiverReceiverInputInfo,
);
}
}
/** /**
* Get the next idea. * Get the next idea.
* If it is a contact prompt, loop through. * If it is a contact prompt, loop through.
*/ */
async nextIdea() { async nextIdea() {
// if we're incrementing to the contact prompt // check if the next one is an idea or a contact
// or if we're at the contact prompt and there was a previous contact... if (this.currentCategory === this.CATEGORY_IDEAS) {
if ( this.currentIdeaIndex++;
this.currentIdeaIndex == this.CONTACT_PROMPT_INDEX - 1 || if (this.currentIdeaIndex === this.IDEAS.length) {
(this.currentIdeaIndex == this.CONTACT_PROMPT_INDEX && // must have just finished ideas so move to contacts
this.shownContactDbIndices.length < this.numContacts) this.findNextUnshownContact();
) { }
this.currentIdeaIndex = this.CONTACT_PROMPT_INDEX;
this.findNextUnshownContact();
} else { } else {
// we're not at the contact prompt (or we ran out), so increment the idea index // must be this.CATEGORY_CONTACTS
this.currentIdeaIndex = this.findNextUnshownContact();
(this.currentIdeaIndex + 1) % (this.IDEAS.length + this.OTHER_PROMPTS); // when that's finished, it'll reset to ideas
// ... and clear out any other prompt info
this.currentContact = undefined;
this.shownContactDbIndices = [];
} }
} }
prevIdea() { /**
if ( * Get the previous idea.
this.currentIdeaIndex == * If it is a contact prompt, loop through.
(this.CONTACT_PROMPT_INDEX + 1) % */
(this.IDEAS.length + this.OTHER_PROMPTS) || async prevIdea() {
(this.currentIdeaIndex == this.CONTACT_PROMPT_INDEX && // check if the next one is an idea or a contact
this.shownContactDbIndices.length < this.numContacts) if (this.currentCategory === this.CATEGORY_IDEAS) {
) {
this.currentIdeaIndex = this.CONTACT_PROMPT_INDEX;
this.findNextUnshownContact();
} else {
// we're not at the contact prompt (or we ran out), so increment the idea index
this.currentIdeaIndex--; this.currentIdeaIndex--;
if (this.currentIdeaIndex < 0) { if (this.currentIdeaIndex < 0) {
this.currentIdeaIndex = this.IDEAS.length - 1 + this.OTHER_PROMPTS; // must have just finished ideas so move to contacts
this.findNextUnshownContact();
} }
// ... and clear out any other prompt info } else {
this.currentContact = undefined; // must be this.CATEGORY_CONTACTS
this.shownContactDbIndices = []; this.findNextUnshownContact();
// when that's finished, it'll reset to ideas
} }
} }
nextIdeaPastContacts() { nextIdeaPastContacts() {
this.currentIdeaIndex = 0;
this.currentContact = undefined; this.currentContact = undefined;
this.shownContactDbIndices = []; this.shownContactDbIndices = new Array<boolean>(this.numContacts);
this.currentCategory = this.CATEGORY_IDEAS;
// look at the previous idea and switch to the other side of the list
this.currentIdeaIndex =
this.currentIdeaIndex >= this.IDEAS.length ? 0 : this.IDEAS.length - 1;
} }
async findNextUnshownContact() { async findNextUnshownContact() {
// get a random contact if (this.currentCategory === this.CATEGORY_IDEAS) {
if (this.shownContactDbIndices.length === this.numContacts) { // we're not in the contact prompts, so reset index array
// no more contacts to show this.shownContactDbIndices = new Array<boolean>(this.numContacts);
this.currentContact = undefined; }
} else { this.currentCategory = this.CATEGORY_CONTACTS;
// get a random contact that hasn't been shown yet
let someContactDbIndex = Math.floor(Math.random() * this.numContacts);
// and guarantee that one is found by walking past shown contacts
let shownContactIndex =
this.shownContactDbIndices.indexOf(someContactDbIndex);
while (shownContactIndex !== -1) {
// increment both indices until we find a spot where "shown" skips a spot
shownContactIndex = (shownContactIndex + 1) % this.numContacts;
someContactDbIndex = (someContactDbIndex + 1) % this.numContacts;
if (
this.shownContactDbIndices[shownContactIndex] !== someContactDbIndex
) {
// we found a contact that hasn't been shown yet
break;
}
// continue
// ... and there must be at least one because shownContactDbIndices length < numContacts
}
this.shownContactDbIndices.push(someContactDbIndex);
this.shownContactDbIndices.sort();
let someContactDbIndex = Math.floor(Math.random() * this.numContacts);
let count = 0;
// as long as the index has an entry, loop
while (
this.shownContactDbIndices[someContactDbIndex] != null &&
count++ < this.numContacts
) {
someContactDbIndex = (someContactDbIndex + 1) % this.numContacts;
}
if (count >= this.numContacts) {
// all contacts have been shown
this.nextIdeaPastContacts();
} else {
// get the contact at that offset // get the contact at that offset
await db.open(); await db.open();
this.currentContact = await db.contacts this.currentContact = await db.contacts
.offset(someContactDbIndex) .offset(someContactDbIndex)
.first(); .first();
this.shownContactDbIndices[someContactDbIndex] = true;
} }
} }
cancel() {
this.currentContact = undefined;
this.currentIdeaIndex = 0;
this.numContacts = 0;
this.shownContactDbIndices = [];
this.close();
}
} }
</script> </script>

View File

@@ -6,7 +6,7 @@
id="ViewHeading" id="ViewHeading"
class="text-center font-bold absolute top-0 left-0 right-0 px-4 py-0.5 bg-black/50 text-white leading-none" class="text-center font-bold absolute top-0 left-0 right-0 px-4 py-0.5 bg-black/50 text-white leading-none"
> >
Camera or Other? Add Photo
</div> </div>
<div <div
class="text-lg text-center px-2 py-0.5 leading-none absolute right-0 top-0 text-white" class="text-lg text-center px-2 py-0.5 leading-none absolute right-0 top-0 text-white"

View File

@@ -0,0 +1,118 @@
<template>
<div v-if="visible" class="dialog-overlay">
<div class="dialog">
<h1 class="text-xl font-bold text-center mb-4">Invitation & Notes</h1>
These are optional notes for your use; they are comments to help you
recall who it is when they accept it. These notes are sent to the server.
If you want to store your own way, the invitation ID is:
{{ inviteIdentifier }}
<input
type="text"
placeholder="Notes"
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
v-model="text"
/>
<!-- Add date selection element -->
Expiration
<input
type="date"
class="block rounded border border-slate-400 mb-4 px-3 py-2"
v-model="expiresAt"
/>
<div class="mt-8">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-2">
<button
type="button"
class="block w-full text-center text-lg font-bold uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md mb-2"
@click="onClickSaveChanges()"
>
Save
</button>
<!-- SHOW ME instead while processing saving changes -->
<button
type="button"
class="block w-full text-center text-md uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md mb-2"
@click="onClickCancel()"
>
Cancel
</button>
</div>
</div>
</div>
</div>
</template>
<script lang="ts">
import { Vue, Component } from "vue-facing-decorator";
import { NotificationIface } from "@/constants/app";
@Component
export default class InviteDialog extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void;
callback: (text: string, expiresAt: string) => void = () => {};
inviteIdentifier = "";
text = "";
visible = false;
expiresAt = new Date(Date.now() + 1000 * 60 * 60 * 24 * 7)
.toISOString()
.substring(0, 10);
async open(
inviteIdentifier: string,
aCallback: (text: string, expiresAt: string) => void,
) {
this.callback = aCallback;
this.inviteIdentifier = inviteIdentifier;
this.visible = true;
}
async onClickSaveChanges() {
if (!this.expiresAt) {
this.$notify(
{
group: "alert",
type: "warning",
title: "Needs Expiration",
text: "You must select an expiration date.",
},
5000,
);
} else {
this.callback(this.text, this.expiresAt);
this.visible = false;
}
}
onClickCancel() {
this.visible = false;
}
}
</script>
<style>
.dialog-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
padding: 1.5rem;
}
.dialog {
background-color: white;
padding: 1rem;
border-radius: 0.5rem;
width: 100%;
max-width: 500px;
}
</style>

View File

@@ -6,7 +6,7 @@
type="text" type="text"
data-testId="inputDescription" data-testId="inputDescription"
class="block w-full rounded border border-slate-400 mb-2 px-3 py-2" class="block w-full rounded border border-slate-400 mb-2 px-3 py-2"
placeholder="Description, prerequisites, terms, etc." placeholder="Description of what is offered"
v-model="description" v-model="description"
/> />
<div class="flex flex-row mt-2"> <div class="flex flex-row mt-2">
@@ -85,15 +85,14 @@ import { Vue, Component, Prop } from "vue-facing-decorator";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { createAndSubmitOffer } from "@/libs/endorserServer"; import { createAndSubmitOffer } from "@/libs/endorserServer";
import * as libsUtil from "@/libs/util"; import * as libsUtil from "@/libs/util";
import { db } from "@/db/index"; import { retrieveSettingsForActiveAccount } from "@/db/index";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
@Component @Component
export default class OfferDialog extends Vue { export default class OfferDialog extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void; $notify!: (notification: NotificationIface, timeout?: number) => void;
@Prop projectId?; @Prop projectId?: string;
@Prop projectName?; @Prop projectName?: string;
activeDid = ""; activeDid = "";
apiServer = ""; apiServer = "";
@@ -113,10 +112,9 @@ export default class OfferDialog extends Vue {
this.recipientDid = recipientDid; this.recipientDid = recipientDid;
this.recipientName = recipientName; this.recipientName = recipientName;
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; this.apiServer = settings.apiServer || "";
this.apiServer = settings?.apiServer || ""; this.activeDid = settings.activeDid || "";
this.activeDid = settings?.activeDid || "";
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) { } catch (err: any) {
@@ -209,9 +207,9 @@ export default class OfferDialog extends Vue {
group: "alert", group: "alert",
type: "danger", type: "danger",
title: "Error", title: "Error",
text: "You must select an identifier before you can record an offer.", text: "You must select an identity before you can record an offer.",
}, },
-1, 7000,
); );
return; return;
} }
@@ -237,6 +235,7 @@ export default class OfferDialog extends Vue {
description, description,
amount, amount,
unitCode, unitCode,
"",
expirationDateInput, expirationDateInput,
this.recipientDid, this.recipientDid,
this.projectId, this.projectId,
@@ -265,7 +264,7 @@ export default class OfferDialog extends Vue {
title: "Success", title: "Success",
text: "That offer was recorded.", text: "That offer was recorded.",
}, },
10000, 5000,
); );
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any

View File

@@ -0,0 +1,281 @@
<!-- similar to ContactNameDialog -->
<template>
<div v-if="visible" class="dialog-overlay">
<div v-if="page === OnboardPage.Home" class="dialog">
<h1 class="text-xl font-bold text-center mb-4 relative">
Welcome to Time Safari
<br />
- Showcasing Gratitude & Magnifing Time
<div
class="text-lg text-center leading-none absolute right-0 -top-1"
@click="onClickClose(true)"
>
<fa icon="xmark" class="w-[1em]"></fa>
</div>
</h1>
<p v-if="isRegistered" class="mt-4">
You can now log things that you've received or witnessed:
<span v-if="numContacts > 0">
click on {{ firstContactName }}'s name or
</span>
click on "Unnamed" to express your appreciation for... whatever -- like
thanks for showing you all these fascinating stories of
<em>gratitude</em>.
</p>
<p v-else class="mt-4">
The feed underneath this pop-up shows the latest gifts recognized by
others. Once someone registers you, you'll be able to log your
appreciation, too.
</p>
<p class="mt-4">
The more you illuminate cool things people are doing, the more you
attract people to work together with you.
</p>
<p class="mt-4 flex items-center">
The
<fa
icon="house-chimney"
class="ml-1 mr-1 text-lg text-white bg-slate-400 px-2 py-2 rounded"
/>
button below brings you back to this feed screen.
</p>
<div class="mt-8">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-2">
<button
type="button"
data-testId="closeOnboardingAndFinish"
class="block w-full text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md mb-2"
@click="onClickClose(true)"
>
That's enough help, thanks.
</button>
<button
type="button"
class="block w-full text-center text-md bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md mb-2"
@click="$router.push({ name: 'discover' })"
>
Show me more!
</button>
</div>
</div>
<p class="mt-4 flex items-center">
To see these instructions and more, click above on
<span
class="ml-1 mr-1 text-xs uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-1 rounded-md"
>
Help
</span>
</p>
</div>
<div v-if="page === OnboardPage.Discover" class="dialog">
<h1 class="text-xl font-bold text-center mb-4 relative">
Offer to Interesting Events & People
<div
class="text-lg text-center leading-none absolute right-0 -top-1"
@click="onClickClose(true)"
>
<fa icon="xmark" class="w-[1em]"></fa>
</div>
</h1>
<p>
Once you've seen things that others have given or done, you may find
ways you want to contribute, too. It turns out others have proposed
activities together, and this page is where you find projects.
</p>
<p class="mt-4">
Search for a topic, or search around your neighborhod under "Nearby".
</p>
<p class="mt-4">
When you find some that seem interesting, you can offer your help. You
are welcome to make your offer conditional, for example if they get 2
other people, too.
</p>
<p class="mt-4 flex items-center">
The
<fa
icon="magnifying-glass"
class="ml-1 mr-1 text-lg text-white bg-slate-400 px-2 py-2 rounded"
/>
button below brings you to this discovery screen.
</p>
<div class="mt-8">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-2">
<button
type="button"
data-testId="closeOnboardingAndFinish"
class="block w-full text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md mb-2"
@click="onClickClose(true)"
>
No more help, thanks.
</button>
<button
type="button"
class="block w-full text-center text-md bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md mb-2"
@click="$router.push({ name: 'projects' })"
>
Show me even more.
</button>
</div>
</div>
</div>
<div v-if="page === OnboardPage.Create" class="dialog">
<h1 class="text-xl font-bold text-center mb-4 relative">
Fish for Others with Your Projects
<div
class="text-lg text-center leading-none absolute right-0 -top-1"
@click="onClickClose(true)"
>
<fa icon="xmark" class="w-[1em]"></fa>
</div>
</h1>
<p class="relative">
Now you can take a turn: click on the
<span class="bg-green-600 text-white rounded-full">
<fa icon="plus" class="fa-fw"></fa>
</span>
button to throw out projects of your own... anything you'd like to see
happen. If your first idea doesn't catch anyone, try, try again... and
let others know that this is a good place to find help.
</p>
<p class="mt-4 flex items-center">
The
<fa
icon="hand"
class="ml-1 mr-1 text-lg text-white bg-slate-400 px-2 py-2 rounded"
/>
button below brings you here to see your ideas.
</p>
<p class="mt-4">
By the way, one good way to get to know your neighbors and their
interests is to offer time directly to them. You can do this on the
contacts screen
<fa icon="users" class="text-slate-500" />
which is a great way to get to know a neighbor's interests.
</p>
<div class="mt-8">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-2">
<button
type="button"
data-testId="closeOnboardingAndFinish"
class="block w-full text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md mb-2"
@click="onClickClose(true, true)"
>
Let's go!
<br />
See & record gratitude.
</button>
<button
type="button"
class="block w-full text-center text-md bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md mb-2"
@click="$router.push({ name: 'help' })"
>
I want to read more Help.
</button>
</div>
</div>
</div>
</div>
</template>
<script lang="ts">
import { Component, Vue } from "vue-facing-decorator";
import { Router } from "vue-router";
import { NotificationIface } from "@/constants/app";
import {
db,
retrieveSettingsForActiveAccount,
updateAccountSettings,
} from "@/db/index";
import { OnboardPage } from "@/libs/util";
@Component({
computed: {
OnboardPage() {
return OnboardPage;
},
},
components: { OnboardPage },
})
export default class OnboardingDialog extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void;
activeDid = "";
firstContactName = null;
givenName = "";
isRegistered = false;
numContacts = 0;
page = OnboardPage.Home;
visible = false;
async open(page: OnboardPage) {
this.page = page;
const settings = await retrieveSettingsForActiveAccount();
this.activeDid = settings.activeDid || "";
this.isRegistered = !!settings.isRegistered;
const contacts = await db.contacts.toArray();
this.numContacts = contacts.length;
if (this.numContacts > 0) {
this.firstContactName = contacts[0].name;
}
this.visible = true;
if (this.page === OnboardPage.Create) {
// we'll assume that they've been through all the other pages
await updateAccountSettings(this.activeDid, {
finishedOnboarding: true,
});
}
}
async onClickClose(done?: boolean, goHome?: boolean) {
this.visible = false;
if (done) {
await updateAccountSettings(this.activeDid, {
finishedOnboarding: true,
});
if (goHome) {
(this.$router as Router).push({ name: "home" });
}
}
}
}
</script>
<style>
.dialog-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
padding: 1.5rem;
}
.dialog {
background-color: white;
padding: 1rem;
border-radius: 0.5rem;
width: 100%;
max-width: 500px;
}
</style>

View File

@@ -76,7 +76,8 @@
</div> </div>
<div v-else ref="cameraContainer"> <div v-else ref="cameraContainer">
<!-- <!--
Camera "resolution" doesn't change how it shows on screen but rather stretches the result, eg the following which just stretches it vertically: Camera "resolution" doesn't change how it shows on screen but rather stretches the result,
eg. the following which just stretches it vertically:
:resolution="{ width: 375, height: 812 }" :resolution="{ width: 375, height: 812 }"
--> -->
<camera <camera
@@ -126,8 +127,7 @@ import { Component, Vue } from "vue-facing-decorator";
import VuePictureCropper, { cropper } from "vue-picture-cropper"; import VuePictureCropper, { cropper } from "vue-picture-cropper";
import { DEFAULT_IMAGE_API_SERVER, NotificationIface } from "@/constants/app"; import { DEFAULT_IMAGE_API_SERVER, NotificationIface } from "@/constants/app";
import { db } from "@/db/index"; import { retrieveSettingsForActiveAccount } from "@/db/index";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
import { accessToken } from "@/libs/crypto"; import { accessToken } from "@/libs/crypto";
@Component({ components: { Camera, VuePictureCropper } }) @Component({ components: { Camera, VuePictureCropper } })
@@ -151,9 +151,8 @@ export default class PhotoDialog extends Vue {
async mounted() { async mounted() {
try { try {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; this.activeDid = settings.activeDid || "";
this.activeDid = settings?.activeDid || "";
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) { } catch (err: any) {
console.error("Error retrieving settings from database:", err); console.error("Error retrieving settings from database:", err);

View File

@@ -0,0 +1,568 @@
<template>
<transition
enter-active-class="transform ease-out duration-300 transition"
enter-from-class="translate-y-2 opacity-0 sm:translate-y-4"
enter-to-class="translate-y-0 opacity-100 sm:translate-y-0"
leave-active-class="transition ease-in duration-500"
leave-from-class="opacity-100"
leave-to-class="opacity-0"
>
<div
v-if="isVisible"
class="fixed z-[100] top-0 inset-x-0 w-full absolute inset-0 h-screen flex flex-col items-center justify-center bg-slate-900/50"
>
<div
class="flex w-11/12 max-w-sm mx-auto mb-3 overflow-hidden bg-white rounded-lg shadow-lg"
>
<div class="w-full px-6 py-6 text-slate-900 text-center">
<p v-if="serviceWorkerReady && vapidKey" class="text-lg mb-4">
<span v-if="pushType === DAILY_CHECK_TITLE">
Would you like to be notified of new activity, up to once a day?
</span>
<span v-else>
Would you like to get a reminder message once a day?
</span>
</p>
<p v-else class="text-lg mb-4">
Waiting for system initialization, which may take up to 5 seconds...
<fa icon="spinner" spin />
</p>
<div v-if="serviceWorkerReady && vapidKey">
<div v-if="pushType === DAILY_CHECK_TITLE">
<span>Yes, send me a message when there is new data for me</span>
</div>
<div v-else>
<span>Yes, send me this message:</span>
<!-- eslint-disable -->
<textarea
type="text"
id="push-message"
v-model="messageInput"
class="rounded border border-slate-400 mt-2 px-2 py-2 w-full"
maxlength="100"
></textarea
>
<!-- eslint-enable -->
<span class="w-full flex justify-between text-xs text-slate-500">
<span></span>
<span>(100 characters max)</span>
</span>
</div>
<div>
<span class="flex flex-row justify-center">
<span class="mt-2">... at: </span>
<input
type="number"
@change="checkHourInput"
class="rounded-l border border-r-0 border-slate-400 ml-2 mt-2 px-2 py-2 text-center w-20"
v-model="hourInput"
/>
<input
type="number"
@change="checkMinuteInput"
class="border border-slate-400 mt-2 px-2 py-2 text-center w-20"
v-model="minuteInput"
/>
<span
class="rounded-r border border-slate-400 bg-slate-200 text-center text-blue-500 mt-2 px-2 py-2 w-20"
@click="hourAm = !hourAm"
>
<span v-if="hourAm"> AM <fa icon="chevron-down" /> </span>
<span v-else> PM <fa icon="chevron-up" /> </span>
</span>
</span>
</div>
<button
class="block w-full text-center text-md font-bold uppercase bg-blue-600 text-white mt-2 px-2 py-2 rounded-md"
@click="
close();
turnOnNotifications();
"
>
Turn on Daily Message
</button>
</div>
<button
@click="close()"
class="block w-full text-center text-md font-bold uppercase bg-slate-600 text-white mt-4 px-2 py-2 rounded-md"
>
No, Not Now
</button>
</div>
</div>
</div>
</transition>
</template>
<script lang="ts">
import { Component, Vue } from "vue-facing-decorator";
import { DEFAULT_PUSH_SERVER, NotificationIface } from "@/constants/app";
import { logConsoleAndDb, retrieveSettingsForActiveAccount } from "@/db/index";
import { urlBase64ToUint8Array } from "@/libs/crypto/vc/util";
import * as libsUtil from "@/libs/util";
// Example interface for error
interface ErrorResponse {
message: string;
}
// PushSubscriptionJSON is defined in the Push API https://www.w3.org/TR/push-api/#dom-pushsubscriptionjson
interface PushSubscriptionWithTime extends PushSubscriptionJSON {
message?: string;
notifyTime: { utcHour: number; minute: number };
notifyType: string;
}
interface ServiceWorkerMessage {
type: string;
data: string;
}
interface ServiceWorkerResponse {
// Define the properties and their types
success: boolean;
message?: string;
}
interface VapidResponse {
data: {
vapidKey: string;
};
}
@Component
export default class PushNotificationPermission extends Vue {
// eslint-disable-next-line
$notify!: (notification: NotificationIface, timeout?: number) => Promise<() => void>;
DAILY_CHECK_TITLE = libsUtil.DAILY_CHECK_TITLE;
DIRECT_PUSH_TITLE = libsUtil.DIRECT_PUSH_TITLE;
callback: (success: boolean, time: string, message?: string) => void =
() => {};
hourAm = true;
hourInput = "8";
isVisible = false;
messageInput = "";
minuteInput = "00";
pushType = "";
serviceWorkerReady = false;
vapidKey = "";
async open(
pushType: string,
callback?: (success: boolean, time: string, message?: string) => void,
) {
this.callback = callback || this.callback;
this.isVisible = true;
this.pushType = pushType;
try {
const settings = await retrieveSettingsForActiveAccount();
let pushUrl = DEFAULT_PUSH_SERVER;
if (settings?.webPushServer) {
pushUrl = settings.webPushServer;
}
if (pushUrl.startsWith("http://localhost")) {
logConsoleAndDb("Not checking for VAPID in this local environment.");
} else {
let responseData = "";
await this.axios
.get(pushUrl + "/web-push/vapid")
.then((response: VapidResponse) => {
this.vapidKey = response.data?.vapidKey || "";
logConsoleAndDb("Got vapid key: " + this.vapidKey);
responseData = JSON.stringify(response.data);
navigator.serviceWorker?.addEventListener(
"controllerchange",
() => {
logConsoleAndDb(
"New service worker is now controlling the page",
);
},
);
});
if (!this.vapidKey) {
this.$notify(
{
group: "alert",
type: "danger",
title: "Error Setting Notifications",
text: "Could not set notifications.",
},
5000,
);
logConsoleAndDb(
"Error Setting Notifications: web push server response didn't have vapidKey: " +
responseData,
true,
);
}
}
} catch (error) {
if (window.location.host.startsWith("localhost")) {
logConsoleAndDb(
"Ignoring the error getting VAPID for local development.",
);
} else {
logConsoleAndDb(
"Got an error initializing notifications: " + JSON.stringify(error),
true,
);
this.$notify(
{
group: "alert",
type: "danger",
title: "Error Setting Notifications",
text: "Got an error setting notifications.",
},
5000,
);
}
}
// there may be a long pause here on first initialization
navigator.serviceWorker?.ready.then(() => {
this.serviceWorkerReady = true;
});
if (this.pushType === this.DIRECT_PUSH_TITLE) {
this.messageInput =
"Just a friendly reminder: click and share some gratitude with the world.";
// focus on the message input
setTimeout(function () {
document.getElementById("push-message")?.focus();
}, 100);
} else {
// not critical but doesn't make sense in a daily check
this.messageInput = "";
}
}
private close() {
this.isVisible = false;
}
private sendMessageToServiceWorker(
message: ServiceWorkerMessage,
): Promise<unknown> {
return new Promise((resolve, reject) => {
if (navigator.serviceWorker?.controller) {
const messageChannel = new MessageChannel();
messageChannel.port1.onmessage = (event: MessageEvent) => {
if (event.data.error) {
reject(event.data.error as ErrorResponse);
} else {
resolve(event.data as ServiceWorkerResponse);
}
};
navigator.serviceWorker?.controller.postMessage(message, [
messageChannel.port2,
]);
} else {
reject("Service worker controller not available");
}
});
}
private askPermission(): Promise<NotificationPermission> {
logConsoleAndDb(
"Requesting permission for notifications: " + JSON.stringify(navigator),
);
if (
!("serviceWorker" in navigator && navigator.serviceWorker?.controller)
) {
return Promise.reject("Service worker not available.");
}
const secret = localStorage.getItem("secret");
if (!secret) {
return Promise.reject("No secret found.");
}
return this.sendSecretToServiceWorker(secret)
.then(() => this.checkNotificationSupport())
.then(() => this.requestNotificationPermission())
.catch((error) => Promise.reject(error));
}
private sendSecretToServiceWorker(secret: string): Promise<void> {
const message: ServiceWorkerMessage = {
type: "SEND_LOCAL_DATA",
data: secret,
};
return this.sendMessageToServiceWorker(message).then((response) => {
logConsoleAndDb(
"Response from service worker: " + JSON.stringify(response),
);
});
}
private checkNotificationSupport(): Promise<void> {
if (!("Notification" in window)) {
this.$notify(
{
group: "alert",
type: "danger",
title: "Browser Notifications Are Not Supported",
text: "This browser does not support notifications.",
},
3000,
);
return Promise.reject("This browser does not support notifications.");
}
if (window.Notification.permission === "granted") {
return Promise.resolve();
}
return Promise.resolve();
}
private requestNotificationPermission(): Promise<NotificationPermission> {
return window.Notification.requestPermission().then(
(permission: string) => {
if (permission !== "granted") {
this.$notify(
{
group: "alert",
type: "danger",
title: "Error Requesting Notification Permission",
text:
"Allow this app permission to make notifications for personal reminders." +
" You can adjust them at any time in your settings.",
},
-1,
);
throw new Error("We weren't granted permission.");
}
return permission;
},
);
}
private checkHourInput() {
const hourNum = parseInt(this.hourInput);
if (isNaN(hourNum)) {
this.hourInput = "12";
} else if (hourNum < 1) {
this.hourInput = "12";
this.hourAm = !this.hourAm;
} else if (hourNum > 12) {
this.hourInput = "1";
this.hourAm = !this.hourAm;
} else {
this.hourInput = hourNum.toString();
}
}
private checkMinuteInput() {
const minuteNum = parseInt(this.minuteInput);
if (isNaN(minuteNum)) {
this.minuteInput = "00";
} else if (minuteNum < 0) {
this.minuteInput = "59";
} else if (minuteNum < 10) {
this.minuteInput = "0" + minuteNum;
} else if (minuteNum > 59) {
this.minuteInput = "00";
} else {
this.minuteInput = minuteNum.toString();
}
}
private async turnOnNotifications() {
let notifyCloser = () => {};
return this.askPermission()
.then((permission) => {
logConsoleAndDb("Permission granted: " + JSON.stringify(permission));
// Call the function and handle promises
return this.subscribeToPush();
})
.then(() => {
logConsoleAndDb("Subscribed successfully.");
return navigator.serviceWorker?.ready;
})
.then((registration) => {
return registration.pushManager.getSubscription();
})
.then(async (subscription) => {
if (subscription) {
notifyCloser = await this.$notify(
{
group: "alert",
type: "info",
title: "Notification Setup Underway",
text: "Setting up notifications for interesting activity, which takes about 10 seconds. If you don't see a final confirmation, check the 'Troubleshoot' page.",
},
-1,
);
// we already checked that this is a valid hour number
const rawHourNum = libsUtil.numberOrZero(this.hourInput);
const adjHourNum = this.hourAm
? // If it's AM, then we'll change it to 0 for 12 AM but otherwise use rawHourNum
rawHourNum === 12
? 0
: rawHourNum
: // Otherwise it's PM, so keep a 12 but otherwise add 12
rawHourNum === 12
? 12
: rawHourNum + 12;
const hourNum = adjHourNum % 24; // probably unnecessary now
const utcHour =
hourNum + Math.round(new Date().getTimezoneOffset() / 60);
const finalUtcHour = (utcHour + (utcHour < 0 ? 24 : 0)) % 24;
const minuteNum = libsUtil.numberOrZero(this.minuteInput);
const utcMinute =
minuteNum + Math.round(new Date().getTimezoneOffset() % 60);
const finalUtcMinute = (utcMinute + (utcMinute < 0 ? 60 : 0)) % 60;
const subscriptionWithTime: PushSubscriptionWithTime = {
notifyTime: { utcHour: finalUtcHour, minute: finalUtcMinute },
notifyType: this.pushType,
message: this.messageInput,
...subscription.toJSON(),
};
await this.sendSubscriptionToServer(subscriptionWithTime);
// To help investigate potential issues with this: https://firebase.google.com/docs/cloud-messaging/migrate-v1
logConsoleAndDb(
"Subscription data sent to server with endpoint: " +
subscription.endpoint,
);
return subscriptionWithTime;
} else {
throw new Error("Subscription object is not available.");
}
})
.then(async (subscription: PushSubscriptionWithTime) => {
logConsoleAndDb(
"Subscription data sent to server and all finished successfully.",
);
await libsUtil.sendTestThroughPushServer(subscription, true);
notifyCloser();
setTimeout(() => {
this.$notify(
{
group: "alert",
type: "success",
title: "Notification Is On",
text: "You should see at least one on your device; if not, check the 'Troubleshoot' link.",
},
7000,
);
}, 500);
const timeText =
// eslint-disable-next-line
this.hourInput + ":" + this.minuteInput + " " + (this.hourAm ? "AM" : "PM");
this.callback(true, timeText, this.messageInput);
})
.catch((error) => {
logConsoleAndDb(
"Got an error setting notification permissions: " +
" string " +
error.toString() +
" JSON " +
JSON.stringify(error),
true,
);
this.$notify(
{
group: "alert",
type: "danger",
title: "Error Setting Notification Permissions",
text: "Could not set notification permissions.",
},
3000,
);
// if we want to also unsubscribe, be sure to do that only if no other notification is active
});
}
private subscribeToPush(): Promise<void> {
return new Promise<void>((resolve, reject) => {
if (!("serviceWorker" in navigator && "PushManager" in window)) {
const errorMsg = "Push messaging is not supported";
console.warn(errorMsg);
return reject(new Error(errorMsg));
}
if (window.Notification.permission !== "granted") {
const errorMsg = "Notification permission not granted";
console.warn(errorMsg);
return reject(new Error(errorMsg));
}
const applicationServerKey = urlBase64ToUint8Array(this.vapidKey);
const options: PushSubscriptionOptions = {
userVisibleOnly: true,
applicationServerKey: applicationServerKey,
};
navigator.serviceWorker?.ready
.then((registration) => {
return registration.pushManager.subscribe(options);
})
.then((subscription) => {
logConsoleAndDb(
"Push subscription successful: " + JSON.stringify(subscription),
);
resolve();
})
.catch((error) => {
logConsoleAndDb(
"Push subscription failed: " +
JSON.stringify(error) +
" - " +
JSON.stringify(options),
true,
);
// Inform the user about the issue
this.$notify(
{
group: "alert",
type: "danger",
title: "Error Setting Push Notifications",
text:
"We encountered an issue setting up push notifications. " +
"If you wish to revoke notification permissions, please do so in your browser settings.",
},
-1,
);
reject(error);
});
});
}
private sendSubscriptionToServer(
subscription: PushSubscriptionWithTime,
): Promise<void> {
logConsoleAndDb(
"About to send subscription... " + JSON.stringify(subscription),
);
return fetch("/web-push/subscribe", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(subscription),
}).then((response) => {
if (!response.ok) {
console.error("Bad response subscribing to web push: ", response);
throw new Error("Failed to send push subscription to server");
}
logConsoleAndDb("Push subscription sent to server successfully.");
});
}
}
</script>
<style scoped>
/* Add any specific styles for this component here */
</style>

View File

@@ -16,8 +16,7 @@
import { Component, Vue, Prop } from "vue-facing-decorator"; import { Component, Vue, Prop } from "vue-facing-decorator";
import { AppString, NotificationIface } from "@/constants/app"; import { AppString, NotificationIface } from "@/constants/app";
import { db } from "@/db/index"; import { retrieveSettingsForActiveAccount } from "@/db/index";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
@Component @Component
export default class TopMessage extends Vue { export default class TopMessage extends Vue {
@@ -29,17 +28,15 @@ export default class TopMessage extends Vue {
async mounted() { async mounted() {
try { try {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
if ( if (
settings?.warnIfTestServer && settings.warnIfTestServer &&
settings.apiServer !== AppString.PROD_ENDORSER_API_SERVER settings.apiServer !== AppString.PROD_ENDORSER_API_SERVER
) { ) {
const didPrefix = settings.activeDid?.slice(11, 15); const didPrefix = settings.activeDid?.slice(11, 15);
this.message = "You're linked to a non-prod server, user " + didPrefix; this.message = "You're linked to a non-prod server, user " + didPrefix;
} else if ( } else if (
settings?.warnIfProdServer && settings.warnIfProdServer &&
settings.apiServer === AppString.PROD_ENDORSER_API_SERVER settings.apiServer === AppString.PROD_ENDORSER_API_SERVER
) { ) {
const didPrefix = settings.activeDid?.slice(11, 15); const didPrefix = settings.activeDid?.slice(11, 15);

View File

@@ -0,0 +1,98 @@
<!-- similar to ContactNameDialog -->
<template>
<div v-if="visible" class="dialog-overlay">
<div class="dialog">
<h1 class="text-xl font-bold text-center mb-4">Set Your Name</h1>
This is not sent to servers. It is only shared with people when you send
it to them.
<input
type="text"
placeholder="Name"
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
v-model="givenName"
/>
<div class="mt-8">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-2">
<button
type="button"
class="block w-full text-center text-lg font-bold uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md mb-2"
@click="onClickSaveChanges()"
>
Save
</button>
<button
type="button"
class="block w-full text-center text-md uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md mb-2"
@click="onClickCancel()"
>
Cancel
</button>
</div>
</div>
</div>
</div>
</template>
<script lang="ts">
import { Vue, Component } from "vue-facing-decorator";
import { NotificationIface } from "@/constants/app";
import { db, retrieveSettingsForActiveAccount } from "@/db/index";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
@Component
export default class UserNameDialog extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void;
callback: (name: string) => void = () => {};
givenName = "";
visible = false;
/**
* @param aCallback - callback function for name, which may be ""
*/
async open(aCallback?: (name: string) => void) {
this.callback = aCallback || this.callback;
const settings = await retrieveSettingsForActiveAccount();
this.givenName = settings.firstName || "";
this.visible = true;
}
async onClickSaveChanges() {
await db.settings.update(MASTER_SETTINGS_KEY, {
firstName: this.givenName,
});
this.visible = false;
this.callback(this.givenName);
}
onClickCancel() {
this.visible = false;
}
}
</script>
<style>
.dialog-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
padding: 1.5rem;
}
.dialog {
background-color: white;
padding: 1rem;
border-radius: 0.5rem;
width: 100%;
max-width: 500px;
}
</style>

View File

@@ -3,8 +3,7 @@ import * as THREE from "three";
import { GLTFLoader } from "three/addons/loaders/GLTFLoader"; import { GLTFLoader } from "three/addons/loaders/GLTFLoader";
import * as SkeletonUtils from "three/addons/utils/SkeletonUtils"; import * as SkeletonUtils from "three/addons/utils/SkeletonUtils";
import * as TWEEN from "@tweenjs/tween.js"; import * as TWEEN from "@tweenjs/tween.js";
import { db } from "@/db"; import { retrieveSettingsForActiveAccount } from "@/db";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { getHeaders } from "@/libs/endorserServer"; import { getHeaders } from "@/libs/endorserServer";
const ANIMATION_DURATION_SECS = 10; const ANIMATION_DURATION_SECS = 10;
@@ -14,10 +13,9 @@ export async function loadLandmarks(vue, world, scene, loop) {
vue.setWorldProperty("animationDurationSeconds", ANIMATION_DURATION_SECS); vue.setWorldProperty("animationDurationSeconds", ANIMATION_DURATION_SECS);
try { try {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); const activeDid = settings.activeDid || "";
const activeDid = settings?.activeDid || ""; const apiServer = settings.apiServer;
const apiServer = settings?.apiServer;
const headers = await getHeaders(activeDid); const headers = await getHeaders(activeDid);
const url = apiServer + "/api/v2/report/claims?claimType=GiveAction"; const url = apiServer + "/api/v2/report/claims?claimType=GiveAction";

View File

@@ -12,17 +12,24 @@ export enum AppString {
TEST_ENDORSER_API_SERVER = "https://test-api.endorser.ch", TEST_ENDORSER_API_SERVER = "https://test-api.endorser.ch",
LOCAL_ENDORSER_API_SERVER = "http://localhost:3000", LOCAL_ENDORSER_API_SERVER = "http://localhost:3000",
PROD_PUSH_SERVER = "https://timesafari.app",
TEST1_PUSH_SERVER = "https://test.timesafari.app",
TEST2_PUSH_SERVER = "https://timesafari-pwa.anomalistlabs.com",
PROD_IMAGE_API_SERVER = "https://image-api.timesafari.app", PROD_IMAGE_API_SERVER = "https://image-api.timesafari.app",
TEST_IMAGE_API_SERVER = "https://test-image-api.timesafari.app", TEST_IMAGE_API_SERVER = "https://test-image-api.timesafari.app",
LOCAL_IMAGE_API_SERVER = "http://localhost:3001", LOCAL_IMAGE_API_SERVER = "http://localhost:3001",
PROD_PARTNER_API_SERVER = "https://partner-api.endorser.ch",
TEST_PARTNER_API_SERVER = "https://test-partner-api.endorser.ch",
LOCAL_PARTNER_API_SERVER = LOCAL_ENDORSER_API_SERVER,
PROD_PUSH_SERVER = "https://timesafari.app",
TEST1_PUSH_SERVER = "https://test.timesafari.app",
TEST2_PUSH_SERVER = "https://timesafari-pwa.anomalistlabs.com",
NO_CONTACT_NAME = "(no name)", NO_CONTACT_NAME = "(no name)",
} }
export const APP_SERVER =
import.meta.env.VITE_APP_SERVER || "https://timesafari.app";
export const DEFAULT_ENDORSER_API_SERVER = export const DEFAULT_ENDORSER_API_SERVER =
import.meta.env.VITE_DEFAULT_ENDORSER_API_SERVER || import.meta.env.VITE_DEFAULT_ENDORSER_API_SERVER ||
AppString.TEST_ENDORSER_API_SERVER; AppString.TEST_ENDORSER_API_SERVER;
@@ -31,6 +38,10 @@ export const DEFAULT_IMAGE_API_SERVER =
import.meta.env.VITE_DEFAULT_IMAGE_API_SERVER || import.meta.env.VITE_DEFAULT_IMAGE_API_SERVER ||
AppString.TEST_IMAGE_API_SERVER; AppString.TEST_IMAGE_API_SERVER;
export const DEFAULT_PARTNER_API_SERVER =
import.meta.env.VITE_DEFAULT_PARTNER_API_SERVER ||
AppString.TEST_PARTNER_API_SERVER;
export const DEFAULT_PUSH_SERVER = export const DEFAULT_PUSH_SERVER =
window.location.protocol + "//" + window.location.host; window.location.protocol + "//" + window.location.host;
@@ -41,16 +52,17 @@ export const PASSKEYS_ENABLED =
/** /**
* The possible values for "group" and "type" are in App.vue. * The possible values for "group" and "type" are in App.vue.
* From the notiwind package * Some of this comes from the notiwind package, some is custom.
*/ */
export interface NotificationIface { export interface NotificationIface {
group: string; // "alert" | "modal" group: string; // "alert" | "modal"
type: string; // "toast" | "info" | "success" | "warning" | "danger" type: string; // "toast" | "info" | "success" | "warning" | "danger"
title: string; title: string;
text?: string; text?: string;
callback?: (success: boolean) => Promise<void>; // if this triggered an action
noText?: string; noText?: string;
onCancel?: (stopAsking: boolean) => Promise<void>; onCancel?: (stopAsking?: boolean) => Promise<void>;
onNo?: (stopAsking: boolean) => Promise<void>; onNo?: (stopAsking?: boolean) => Promise<void>;
onYes?: () => Promise<void>; onYes?: () => Promise<void>;
promptToStopAsking?: boolean; promptToStopAsking?: boolean;
yesText?: string; yesText?: string;

View File

@@ -1,5 +1,7 @@
import BaseDexie, { Table } from "dexie"; import BaseDexie, { Table } from "dexie";
import { encrypted, Encryption } from "@pvermeer/dexie-encrypted-addon"; import { encrypted, Encryption } from "@pvermeer/dexie-encrypted-addon";
import * as R from "ramda";
import { Account, AccountsSchema } from "./tables/accounts"; import { Account, AccountsSchema } from "./tables/accounts";
import { Contact, ContactSchema } from "./tables/contacts"; import { Contact, ContactSchema } from "./tables/contacts";
import { Log, LogSchema } from "./tables/logs"; import { Log, LogSchema } from "./tables/logs";
@@ -45,15 +47,111 @@ accountsDB.version(1).stores(AccountsSchema);
db.version(2).stores({ db.version(2).stores({
...ContactSchema, ...ContactSchema,
...LogSchema, ...LogSchema,
...SettingsSchema, ...{ settings: "id" }, // old Settings schema
}); });
// v3 added Temp // v3 added Temp
db.version(3).stores(TempSchema); db.version(3).stores(TempSchema);
db.version(4)
.stores(SettingsSchema)
.upgrade((tx) => {
return tx
.table("settings")
.toCollection()
.modify((settings) => {
settings.accountDid = ""; // make it non-null for the default master settings, but still indexable
});
});
const DEFAULT_SETTINGS = {
id: MASTER_SETTINGS_KEY,
activeDid: undefined,
apiServer: DEFAULT_ENDORSER_API_SERVER,
};
// Event handler to initialize the non-sensitive database with default settings // Event handler to initialize the non-sensitive database with default settings
db.on("populate", async () => { db.on("populate", async () => {
await db.settings.add({ await db.settings.add(DEFAULT_SETTINGS);
id: MASTER_SETTINGS_KEY,
apiServer: DEFAULT_ENDORSER_API_SERVER,
});
}); });
// retrieves default settings
// calls db.open()
export async function retrieveSettingsForDefaultAccount(): Promise<Settings> {
await db.open();
return (await db.settings.get(MASTER_SETTINGS_KEY)) || DEFAULT_SETTINGS;
}
export async function retrieveSettingsForActiveAccount(): Promise<Settings> {
const defaultSettings = await retrieveSettingsForDefaultAccount();
if (!defaultSettings.activeDid) {
return defaultSettings;
} else {
const overrideSettings =
(await db.settings
.where("accountDid")
.equals(defaultSettings.activeDid)
.first()) || {};
return R.mergeDeepRight(defaultSettings, overrideSettings);
}
}
// Update settings for the given account, or in MASTER_SETTINGS_KEY if no accountDid is provided.
// Don't expose this because we should be explicit on whether we're updating the default settings or account settings.
async function updateSettings(settingsChanges: Settings): Promise<void> {
await db.open();
if (!settingsChanges.accountDid) {
// ensure there is no "id" that would override the key
delete settingsChanges.id;
await db.settings.update(MASTER_SETTINGS_KEY, settingsChanges);
} else {
const result = await db.settings
.where("accountDid")
.equals(settingsChanges.accountDid)
.modify(settingsChanges);
if (result === 0) {
if (!settingsChanges.id) {
// It is unfortunate that we have to set this explicitly.
// We didn't make id a "++id" at the beginning and Dexie won't let us change it,
// plus we made our first settings objects MASTER_SETTINGS_KEY = 1 instead of 0
settingsChanges.id = (await db.settings.count()) + 1;
}
await db.settings.add(settingsChanges);
}
}
}
export async function updateDefaultSettings(settings: Settings): Promise<void> {
delete settings.accountDid; // just in case
await updateSettings(settings);
}
export async function updateAccountSettings(
accountDid: string,
settings: Settings,
): Promise<void> {
settings.accountDid = accountDid;
await updateSettings(settings);
}
// similar method is in the sw_scripts/additional-scripts.js file
export async function logConsoleAndDb(
message: string,
isError = false,
): Promise<void> {
if (isError) {
console.error(`${new Date().toISOString()} ${message}`);
} else {
console.log(`${new Date().toISOString()} ${message}`);
}
await db.open();
const todayKey = new Date().toDateString();
// only keep one day's worth of logs
const previous = await db.logs.get(todayKey);
if (!previous) {
// when this is today's first log, clear out everything previous
await db.logs.clear();
}
const prevMessages = (previous && previous.message) || "";
const fullMessage = `${prevMessages}\n${new Date().toISOString()} ${message}`;
await db.logs.update(todayKey, { message: fullMessage });
}

1
src/db/tables/README.md Normal file
View File

@@ -0,0 +1 @@
Check the contact & settings export to see whether you want your new table to be included in it.

View File

@@ -12,24 +12,42 @@ export type BoundingBox = {
* Settings type encompasses user-specific configuration details. * Settings type encompasses user-specific configuration details.
*/ */
export type Settings = { export type Settings = {
id: number; // Only one entry, keyed with MASTER_SETTINGS_KEY // default entry is keyed with MASTER_SETTINGS_KEY; other entries are linked to an account with account ID
id?: number; // this is only blank on input, when the database assigns it
// if supplied, this settings record overrides the master record when the user switches to this account
accountDid?: string; // not used in the MASTER_SETTINGS_KEY entry
// active Decentralized ID
activeDid?: string; // only used in the MASTER_SETTINGS_KEY entry
activeDid?: string; // Active Decentralized ID
apiServer?: string; // API server URL apiServer?: string; // API server URL
filterFeedByNearby?: boolean; // filter by nearby filterFeedByNearby?: boolean; // filter by nearby
filterFeedByVisible?: boolean; // filter by visible users ie. anyone not hidden filterFeedByVisible?: boolean; // filter by visible users ie. anyone not hidden
finishedOnboarding?: boolean; // the user has completed the onboarding process
firstName?: string; // user's full name firstName?: string; // user's full name, may be null if unwanted for a particular account
hideRegisterPromptOnNewContact?: boolean; hideRegisterPromptOnNewContact?: boolean;
isRegistered?: boolean; isRegistered?: boolean;
imageServer?: string;
lastName?: string; // deprecated - put all names in firstName lastName?: string; // deprecated - put all names in firstName
lastAckedOfferToUserJwtId?: string; // the last JWT ID for offer-to-user that they've acknowledged seeing
lastAckedOfferToUserProjectsJwtId?: string; // the last JWT ID for offers-to-user's-projects that they've acknowledged seeing
// The claim list has a most recent one used in notifications that's separate from the last viewed
lastNotifiedClaimId?: string; lastNotifiedClaimId?: string;
lastViewedClaimId?: string; lastViewedClaimId?: string;
notifyingNewActivityTime?: string; // set to their chosen time if they have turned on daily check for new activity via the push server
notifyingReminderMessage?: string; // set to their chosen message for a daily reminder
notifyingReminderTime?: string; // set to their chosen time for a daily reminder
partnerApiServer?: string; // partner server API URL
passkeyExpirationMinutes?: number; // passkey access token time-to-live in minutes passkeyExpirationMinutes?: number; // passkey access token time-to-live in minutes
profileImageUrl?: string;
reminderTime?: number; // Time in milliseconds since UNIX epoch for reminders profileImageUrl?: string; // may be null if unwanted for a particular account
reminderOn?: boolean; // Toggle to enable or disable reminders
// Array of named search boxes defined by bounding boxes // Array of named search boxes defined by bounding boxes
searchBoxes?: Array<{ searchBoxes?: Array<{
@@ -46,7 +64,7 @@ export type Settings = {
webPushServer?: string; // Web Push server URL webPushServer?: string; // Web Push server URL
}; };
export function isAnyFeedFilterOn(settings: Settings): boolean { export function checkIsAnyFeedFilterOn(settings: Settings): boolean {
return !!(settings?.filterFeedByNearby || settings?.filterFeedByVisible); return !!(settings?.filterFeedByNearby || settings?.filterFeedByVisible);
} }
@@ -54,7 +72,7 @@ export function isAnyFeedFilterOn(settings: Settings): boolean {
* Schema for the Settings table in the database. * Schema for the Settings table in the database.
*/ */
export const SettingsSchema = { export const SettingsSchema = {
settings: "id", settings: "id, &accountDid",
}; };
/** /**

View File

@@ -0,0 +1,46 @@
/**
* This did:ethr resolver instructs the did-jwt machinery to use the
* EcdsaSecp256k1RecoveryMethod2020Uses verification method which adds the recovery bit to the
* signature to recover the DID's public key from a signature.
*
* This effectively hard codes the did:ethr DID resolver to use the address as the public key.
* @param did : string
* @returns {Promise<DIDResolutionResult>}
*
* Similar code resides in image-api
*/
export const didEthLocalResolver = async (did: string) => {
const didRegex = /^did:ethr:(0x[0-9a-fA-F]{40})$/;
const match = did.match(didRegex);
if (match) {
const address = match[1]; // Extract eth address: 0x...
const publicKeyHex = address; // Use the address directly as a public key placeholder
return {
didDocumentMetadata: {},
didResolutionMetadata: {
contentType: "application/did+ld+json",
},
didDocument: {
"@context": [
"https://www.w3.org/ns/did/v1",
"https://w3id.org/security/suites/secp256k1recovery-2020/v2",
],
id: did,
verificationMethod: [
{
id: `${did}#controller`,
type: "EcdsaSec256k1RecoveryMethod2020",
controller: did,
blockchainAccountId: "eip155:1:" + publicKeyHex,
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`],
},
};
}
throw new Error(`Unsupported DID format: ${did}`);
};

View File

@@ -6,14 +6,22 @@
* *
*/ */
import { Buffer } from "buffer/";
import * as didJwt from "did-jwt"; import * as didJwt from "did-jwt";
import { JWTVerified } from "did-jwt";
import { JWTDecoded } from "did-jwt/lib/JWT"; import { JWTDecoded } from "did-jwt/lib/JWT";
import { Resolver } from "did-resolver";
import { IIdentifier } from "@veramo/core"; import { IIdentifier } from "@veramo/core";
import * as u8a from "uint8arrays"; import * as u8a from "uint8arrays";
import { createDidPeerJwt } from "@/libs/crypto/vc/passkeyDidPeer"; import { didEthLocalResolver } from "./did-eth-local-resolver";
import { PEER_DID_PREFIX, verifyPeerSignature } from "./didPeer";
import { base64urlDecodeString, createDidPeerJwt } from "./passkeyDidPeer";
import { urlBase64ToUint8Array } from "./util";
export const ETHR_DID_PREFIX = "did:ethr:"; export const ETHR_DID_PREFIX = "did:ethr:";
export const JWT_VERIFY_FAILED_CODE = "JWT_VERIFY_FAILED";
export const UNSUPPORTED_DID_METHOD_CODE = "UNSUPPORTED_DID_METHOD";
/** /**
* Meta info about a key * Meta info about a key
@@ -33,6 +41,8 @@ export interface KeyMeta {
passkeyCredIdHex?: string; passkeyCredIdHex?: string;
} }
const resolver = new Resolver({ ethr: didEthLocalResolver });
/** /**
* Tell whether a key is from a passkey * Tell whether a key is from a passkey
* @param keyMeta contains info about the key, whose passkeyCredIdHex determines if the key is from a passkey * @param keyMeta contains info about the key, whose passkeyCredIdHex determines if the key is from a passkey
@@ -44,16 +54,22 @@ export function isFromPasskey(keyMeta?: KeyMeta): boolean {
export async function createEndorserJwtForKey( export async function createEndorserJwtForKey(
account: KeyMeta, account: KeyMeta,
payload: object, payload: object,
expiresIn?: number,
) { ) {
if (account?.identity) { if (account?.identity) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const identity: IIdentifier = JSON.parse(account.identity!); const identity: IIdentifier = JSON.parse(account.identity!);
const privateKeyHex = identity.keys[0].privateKeyHex; const privateKeyHex = identity.keys[0].privateKeyHex;
const signer = await SimpleSigner(privateKeyHex as string); const signer = await SimpleSigner(privateKeyHex as string);
return didJwt.createJWT(payload, { const options = {
issuer: account.did, issuer: account.did,
signer: signer, signer: signer,
}); expiresIn: undefined as number | undefined,
};
if (expiresIn) {
options.expiresIn = expiresIn;
}
return didJwt.createJWT(payload, options);
} else if (account?.passkeyCredIdHex) { } else if (account?.passkeyCredIdHex) {
return createDidPeerJwt(account.did, account.passkeyCredIdHex, payload); return createDidPeerJwt(account.did, account.passkeyCredIdHex, payload);
} else { } else {
@@ -107,6 +123,78 @@ function bytesToHex(b: Uint8Array): string {
return u8a.toString(b, "base16"); return u8a.toString(b, "base16");
} }
// We should be calling 'verify' in more places, showing warnings if it fails.
export function decodeEndorserJwt(jwt: string): JWTDecoded { export function decodeEndorserJwt(jwt: string): JWTDecoded {
return didJwt.decodeJWT(jwt); return didJwt.decodeJWT(jwt);
} }
// return Promise of at least { issuer, payload, verified boolean }
// ... and also if successfully verified by did-jwt (not JWANT): data, doc, signature, signer
export async function decodeAndVerifyJwt(
jwt: string,
): Promise<Omit<JWTVerified, "didResolutionResult" | "signer" | "jwt">> {
const pieces = jwt.split(".");
console.log("WTF decodeAndVerifyJwt", typeof jwt, jwt, pieces);
const header = JSON.parse(base64urlDecodeString(pieces[0]));
const payload = JSON.parse(base64urlDecodeString(pieces[1]));
console.log("WTF decodeAndVerifyJwt after", header, payload);
const issuerDid = payload.iss;
if (!issuerDid) {
return Promise.reject({
clientError: {
message: `Missing "iss" field in JWT.`,
},
});
}
if (issuerDid.startsWith(ETHR_DID_PREFIX)) {
try {
const verified = await didJwt.verifyJWT(jwt, { resolver });
return verified;
} catch (e: unknown) {
return Promise.reject({
clientError: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
message: `JWT failed verification: ` + e.toString(),
code: JWT_VERIFY_FAILED_CODE,
},
});
}
}
if (issuerDid.startsWith(PEER_DID_PREFIX) && header.typ === "JWANT") {
const verified = await verifyPeerSignature(
Buffer.from(payload),
issuerDid,
urlBase64ToUint8Array(pieces[2]),
);
if (!verified) {
return Promise.reject({
clientError: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
message: `JWT failed verification: ` + e.toString(),
code: JWT_VERIFY_FAILED_CODE,
},
});
} else {
return { issuer: issuerDid, payload: payload, verified: true };
}
}
if (issuerDid.startsWith(PEER_DID_PREFIX)) {
return Promise.reject({
clientError: {
message: `JWT with a PEER DID currently only supported with typ == JWANT. Contact us us for JWT suport since it should be straightforward.`,
},
});
}
return Promise.reject({
clientError: {
message: `Unsupported DID method ${issuerDid}`,
code: UNSUPPORTED_DID_METHOD_CODE,
},
});
}

View File

@@ -470,8 +470,18 @@ ${pubKeyBuffer.toString("base64")}
return pem; return pem;
} }
// tried the base64url library but got an error using their Buffer
export function base64urlDecodeString(input: string) {
return atob(input.replace(/-/g, "+").replace(/_/g, "/"));
}
// tried the base64url library but got an error using their Buffer
export function base64urlEncodeString(input: string) {
return btoa(input).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
function base64urlDecode(input: string) { function base64urlDecodeArrayBuffer(input: string) {
input = input.replace(/-/g, "+").replace(/_/g, "/"); input = input.replace(/-/g, "+").replace(/_/g, "/");
const pad = input.length % 4 === 0 ? "" : "====".slice(input.length % 4); const pad = input.length % 4 === 0 ? "" : "====".slice(input.length % 4);
const str = atob(input + pad); const str = atob(input + pad);
@@ -483,9 +493,9 @@ function base64urlDecode(input: string) {
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
function base64urlEncode(buffer: ArrayBuffer) { function base64urlEncodeArrayBuffer(buffer: ArrayBuffer) {
const str = String.fromCharCode(...new Uint8Array(buffer)); const str = String.fromCharCode(...new Uint8Array(buffer));
return btoa(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); return base64urlEncodeString(str);
} }
// from @simplewebauthn/browser // from @simplewebauthn/browser

View File

@@ -0,0 +1,11 @@
export function urlBase64ToUint8Array(base64String: string): Uint8Array {
const padding = "=".repeat((4 - (base64String.length % 4)) % 4);
const base64 = (base64String + padding).replace(/-/g, "+").replace(/_/g, "/");
const rawData = window.atob(base64);
const outputArray = new Uint8Array(rawData.length);
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i);
}
return outputArray;
}

View File

@@ -1,13 +1,20 @@
import { Axios, AxiosRequestConfig, AxiosResponse } from "axios"; import { Axios, AxiosRequestConfig, AxiosResponse } from "axios";
import { Buffer } from "buffer";
import { sha256 } from "ethereum-cryptography/sha256";
import { LRUCache } from "lru-cache"; import { LRUCache } from "lru-cache";
import * as R from "ramda"; import * as R from "ramda";
import { DEFAULT_IMAGE_API_SERVER } from "@/constants/app"; import { DEFAULT_IMAGE_API_SERVER } from "@/constants/app";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import { accessToken } from "@/libs/crypto"; import { accessToken, deriveAddress, nextDerivationPath } from "@/libs/crypto";
import { NonsensitiveDexie } from "@/db/index"; import { NonsensitiveDexie } from "@/db/index";
import { getAccount, getPasskeyExpirationSeconds } from "@/libs/util"; import {
getAccount,
getPasskeyExpirationSeconds,
GiverReceiverInputInfo,
} from "@/libs/util";
import { createEndorserJwtForKey, KeyMeta } from "@/libs/crypto/vc"; import { createEndorserJwtForKey, KeyMeta } from "@/libs/crypto/vc";
import { Account } from "@/db/tables/accounts";
export const SCHEMA_ORG_CONTEXT = "https://schema.org"; export const SCHEMA_ORG_CONTEXT = "https://schema.org";
// the object in RegisterAction claims // the object in RegisterAction claims
@@ -29,11 +36,6 @@ export interface AgreeVerifiableCredential {
object: Record<string, any>; object: Record<string, any>;
} }
export interface GiverReceiverInputInfo {
did?: string;
name?: string;
}
export interface GiverOutputInfo { export interface GiverOutputInfo {
action: string; action: string;
giver?: GiverReceiverInputInfo; giver?: GiverReceiverInputInfo;
@@ -47,6 +49,7 @@ export interface ClaimResult {
error: { code: string; message: string }; error: { code: string; message: string };
} }
// similar to VerifiableCredentialSubject... maybe rename this
export interface GenericVerifiableCredential { export interface GenericVerifiableCredential {
"@context"?: string; // optional when embedded, eg. in an Agree "@context"?: string; // optional when embedded, eg. in an Agree
"@type": string; "@type": string;
@@ -54,8 +57,6 @@ export interface GenericVerifiableCredential {
} }
export interface GenericCredWrapper<T extends GenericVerifiableCredential> { export interface GenericCredWrapper<T extends GenericVerifiableCredential> {
"@context": string;
"@type": string;
claim: T; claim: T;
claimType?: string; claimType?: string;
handleId: string; handleId: string;
@@ -66,8 +67,6 @@ export interface GenericCredWrapper<T extends GenericVerifiableCredential> {
} }
export const BLANK_GENERIC_SERVER_RECORD: GenericCredWrapper<GenericVerifiableCredential> = export const BLANK_GENERIC_SERVER_RECORD: GenericCredWrapper<GenericVerifiableCredential> =
{ {
"@context": SCHEMA_ORG_CONTEXT,
"@type": "",
claim: { "@type": "" }, claim: { "@type": "" },
handleId: "", handleId: "",
id: "", id: "",
@@ -82,11 +81,14 @@ export interface GiveSummaryRecord {
amountConfirmed: number; amountConfirmed: number;
description: string; description: string;
fullClaim: GiveVerifiableCredential; fullClaim: GiveVerifiableCredential;
fulfillsPlanHandleId: string; fulfillsHandleId: string;
fulfillsPlanHandleId?: string;
fulfillsType?: string;
handleId: string; handleId: string;
issuedAt: string; issuedAt: string;
issuerDid: string; issuerDid: string;
jwtId: string; jwtId: string;
providerPlanHandleId?: string;
recipientDid: string; recipientDid: string;
unit: string; unit: string;
} }
@@ -110,6 +112,10 @@ export interface OfferSummaryRecord {
validThrough: string; validThrough: string;
} }
export interface OfferToPlanSummaryRecord extends OfferSummaryRecord {
planName: string;
}
// a summary record; the VC is not currently part of this record // a summary record; the VC is not currently part of this record
export interface PlanSummaryRecord { export interface PlanSummaryRecord {
agentDid?: string; // optional, if the issuer wants someone else to manage as well agentDid?: string; // optional, if the issuer wants someone else to manage as well
@@ -137,6 +143,7 @@ export interface GiveVerifiableCredential extends GenericVerifiableCredential {
identifier?: string; identifier?: string;
image?: string; image?: string;
object?: { amountOfThisGood: number; unitCode: string }; object?: { amountOfThisGood: number; unitCode: string };
provider?: GenericVerifiableCredential; // typically @type & identifier
recipient?: { identifier: string }; recipient?: { identifier: string };
} }
@@ -217,11 +224,21 @@ export interface ImageRateLimits {
} }
export interface VerifiableCredential { export interface VerifiableCredential {
exp?: number;
iat: number;
iss: string;
vc: {
"@context": string[];
type: string[];
credentialSubject: VerifiableCredentialSubject;
};
}
// similar to GenericVerifiableCredential... maybe replace that one
export interface VerifiableCredentialSubject {
"@context": string; "@context": string;
"@type": string; "@type": string;
name: string; [key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
description: string;
identifier?: string;
} }
export interface WorldProperties { export interface WorldProperties {
@@ -229,12 +246,14 @@ export interface WorldProperties {
endTime?: string; endTime?: string;
} }
// AKA Registration & RegisterAction
export interface RegisterVerifiableCredential { export interface RegisterVerifiableCredential {
"@context": string; "@context": typeof SCHEMA_ORG_CONTEXT;
"@type": string; "@type": "RegisterAction";
agent: { identifier: string }; agent: { identifier: string };
identifier?: string; // used for invites (when participant ID isn't known)
object: string; object: string;
participant: { identifier: string }; participant?: { identifier: string }; // used when person is known (not an invite)
} }
// now for some of the error & other wrapper types // now for some of the error & other wrapper types
@@ -266,6 +285,14 @@ export interface ErrorResult extends ResultWithType {
export type CreateAndSubmitClaimResult = SuccessResult | ErrorResult; export type CreateAndSubmitClaimResult = SuccessResult | ErrorResult;
export interface UserInfo {
name: string;
publicEncKey: string;
registered: boolean;
profileImageUrl?: string;
nextPublicEncKeyHash?: string;
}
// This is used to check for hidden info. // This is used to check for hidden info.
// See https://github.com/trentlarson/endorser-ch/blob/0cb626f803028e7d9c67f095858a9fc8542e3dbd/server/api/services/util.js#L6 // See https://github.com/trentlarson/endorser-ch/blob/0cb626f803028e7d9c67f095858a9fc8542e3dbd/server/api/services/util.js#L6
const HIDDEN_DID = "did:none:HIDDEN"; const HIDDEN_DID = "did:none:HIDDEN";
@@ -517,7 +544,7 @@ const planCache: LRUCache<string, PlanSummaryRecord> = new LRUCache({
* @param apiServer * @param apiServer
*/ */
export async function getPlanFromCache( export async function getPlanFromCache(
handleId: string | null, handleId: string | undefined,
axios: Axios, axios: Axios,
apiServer: string, apiServer: string,
requesterDid?: string, requesterDid?: string,
@@ -564,6 +591,52 @@ export async function setPlanInCache(
planCache.set(handleId, planSummary); planCache.set(handleId, planSummary);
} }
/**
*
* @returns { data: Array<OfferSummaryRecord>, hitLimit: boolean true if maximum was hit and there may be more }
*/
export async function getNewOffersToUser(
axios: Axios,
apiServer: string,
activeDid: string,
afterOfferJwtId?: string,
beforeOfferJwtId?: string,
) {
let url = `${apiServer}/api/v2/report/offers?recipientDid=${activeDid}`;
if (afterOfferJwtId) {
url += "&afterId=" + afterOfferJwtId;
}
if (beforeOfferJwtId) {
url += "&beforeId=" + beforeOfferJwtId;
}
const headers = await getHeaders(activeDid);
const response = await axios.get(url, { headers });
return response.data;
}
/**
*
* @returns { data: Array<OfferToPlanSummaryRecord>, hitLimit: boolean true if maximum was hit and there may be more }
*/
export async function getNewOffersToUserProjects(
axios: Axios,
apiServer: string,
activeDid: string,
afterOfferJwtId?: string,
beforeOfferJwtId?: string,
) {
let url = `${apiServer}/api/v2/report/offersToPlansOwnedByMe`;
if (afterOfferJwtId) {
url += "?afterId=" + afterOfferJwtId;
}
if (beforeOfferJwtId) {
url += afterOfferJwtId ? "&" : "?";
url += "beforeId=" + beforeOfferJwtId;
}
const headers = await getHeaders(activeDid);
const response = await axios.get(url, { headers });
return response.data;
}
/** /**
* Construct GiveAction VC for submission to server * Construct GiveAction VC for submission to server
* *
@@ -580,6 +653,7 @@ export function hydrateGive(
fulfillsOfferHandleId?: string, fulfillsOfferHandleId?: string,
isTrade: boolean = false, isTrade: boolean = false,
imageUrl?: string, imageUrl?: string,
providerPlanHandleId?: string,
lastClaimId?: string, lastClaimId?: string,
): GiveVerifiableCredential { ): GiveVerifiableCredential {
// Remember: replace values or erase if it's null // Remember: replace values or erase if it's null
@@ -638,6 +712,10 @@ export function hydrateGive(
vcClaim.image = imageUrl || undefined; vcClaim.image = imageUrl || undefined;
vcClaim.provider = providerPlanHandleId
? { "@type": "PlanAction", identifier: providerPlanHandleId }
: undefined;
return vcClaim; return vcClaim;
} }
@@ -662,6 +740,7 @@ export async function createAndSubmitGive(
fulfillsOfferHandleId?: string, fulfillsOfferHandleId?: string,
isTrade: boolean = false, isTrade: boolean = false,
imageUrl?: string, imageUrl?: string,
providerPlanHandleId?: string,
): Promise<CreateAndSubmitClaimResult> { ): Promise<CreateAndSubmitClaimResult> {
const vcClaim = hydrateGive( const vcClaim = hydrateGive(
undefined, undefined,
@@ -674,6 +753,7 @@ export async function createAndSubmitGive(
fulfillsOfferHandleId, fulfillsOfferHandleId,
isTrade, isTrade,
imageUrl, imageUrl,
providerPlanHandleId,
undefined, undefined,
); );
return createAndSubmitClaim( return createAndSubmitClaim(
@@ -706,6 +786,7 @@ export async function editAndSubmitGive(
fulfillsOfferHandleId?: string, fulfillsOfferHandleId?: string,
isTrade: boolean = false, isTrade: boolean = false,
imageUrl?: string, imageUrl?: string,
providerPlanHandleId?: string,
): Promise<CreateAndSubmitClaimResult> { ): Promise<CreateAndSubmitClaimResult> {
const vcClaim = hydrateGive( const vcClaim = hydrateGive(
fullClaim.claim, fullClaim.claim,
@@ -718,6 +799,7 @@ export async function editAndSubmitGive(
fulfillsOfferHandleId, fulfillsOfferHandleId,
isTrade, isTrade,
imageUrl, imageUrl,
providerPlanHandleId,
fullClaim.id, fullClaim.id,
); );
return createAndSubmitClaim( return createAndSubmitClaim(
@@ -925,12 +1007,55 @@ export async function createAndSubmitClaim(
} }
} }
export async function generateEndorserJwtForAccount(
account: Account,
isRegistered?: boolean,
name?: string,
profileImageUrl?: string,
// note that including the next key pushes QR codes to the next resolution smaller
includeNextKeyIfDerived?: boolean,
) {
const publicKeyHex = account.publicKeyHex;
const publicEncKey = Buffer.from(publicKeyHex, "hex").toString("base64");
const contactInfo = {
iat: Date.now(),
iss: account.did,
own: {
name: name ?? "",
publicEncKey,
registered: !!isRegistered,
} as UserInfo,
};
if (profileImageUrl) {
contactInfo.own.profileImageUrl = profileImageUrl;
}
if (includeNextKeyIfDerived && account?.mnemonic && account?.derivationPath) {
const newDerivPath = nextDerivationPath(account.derivationPath as string);
const nextPublicHex = deriveAddress(
account.mnemonic as string,
newDerivPath,
)[2];
const nextPublicEncKey = Buffer.from(nextPublicHex, "hex");
const nextPublicEncKeyHash = sha256(nextPublicEncKey);
const nextPublicEncKeyHashBase64 =
Buffer.from(nextPublicEncKeyHash).toString("base64");
contactInfo.own.nextPublicEncKeyHash = nextPublicEncKeyHashBase64;
}
const vcJwt = await createEndorserJwtForDid(account.did, contactInfo);
const viewPrefix = CONTACT_URL_PREFIX + ENDORSER_JWT_URL_LOCATION;
return viewPrefix + vcJwt;
}
export async function createEndorserJwtForDid( export async function createEndorserJwtForDid(
issuerDid: string, issuerDid: string,
payload: object, payload: object,
expiresIn?: number,
) { ) {
const account = await getAccount(issuerDid); const account = await getAccount(issuerDid);
return createEndorserJwtForKey(account as KeyMeta, payload); return createEndorserJwtForKey(account as KeyMeta, payload, expiresIn);
} }
/** /**
@@ -1126,7 +1251,7 @@ export const claimSpecialDescription = (
export const BVC_MEETUPS_PROJECT_CLAIM_ID = export const BVC_MEETUPS_PROJECT_CLAIM_ID =
import.meta.env.VITE_BVC_MEETUPS_PROJECT_CLAIM_ID || import.meta.env.VITE_BVC_MEETUPS_PROJECT_CLAIM_ID ||
"https://endorser.ch/entity/01HNTZYJJXTGT0EZS3VEJGX7AK"; // this won't resolve as a URL on production; it's a URN only found in the test system "https://endorser.ch/entity/01GXYPFF7FA03NXKPYY142PY4H"; // production value, which seems like the safest value if forgotten
export const bvcMeetingJoinClaim = (did: string, startTime: string) => { export const bvcMeetingJoinClaim = (did: string, startTime: string) => {
return { return {
@@ -1160,19 +1285,24 @@ export async function createEndorserJwtVcFromClaim(
return createEndorserJwtForDid(issuerDid, vcPayload); return createEndorserJwtForDid(issuerDid, vcPayload);
} }
export async function register( export async function createInviteJwt(
activeDid: string, activeDid: string,
apiServer: string, contact?: Contact,
axios: Axios, inviteId?: string,
contact: Contact, expiresIn?: number,
) { ): Promise<string> {
const vcClaim: RegisterVerifiableCredential = { const vcClaim: RegisterVerifiableCredential = {
"@context": SCHEMA_ORG_CONTEXT, "@context": SCHEMA_ORG_CONTEXT,
"@type": "RegisterAction", "@type": "RegisterAction",
agent: { identifier: activeDid }, agent: { identifier: activeDid },
object: SERVICE_ID, object: SERVICE_ID,
participant: { identifier: contact.did },
}; };
if (contact) {
vcClaim.participant = { identifier: contact.did };
}
if (inviteId) {
vcClaim.identifier = inviteId;
}
// Make a payload for the claim // Make a payload for the claim
const vcPayload = { const vcPayload = {
vc: { vc: {
@@ -1182,7 +1312,17 @@ export async function register(
}, },
}; };
// Create a signature using private key of identity // Create a signature using private key of identity
const vcJwt = await createEndorserJwtForDid(activeDid, vcPayload); const vcJwt = await createEndorserJwtForDid(activeDid, vcPayload, expiresIn);
return vcJwt;
}
export async function register(
activeDid: string,
apiServer: string,
axios: Axios,
contact: Contact,
): Promise<{ success?: boolean; error?: string }> {
const vcJwt = await createInviteJwt(activeDid, contact);
const url = apiServer + "/api/v2/claim"; const url = apiServer + "/api/v2/claim";
const resp = await axios.post(url, { jwtEncoded: vcJwt }); const resp = await axios.post(url, { jwtEncoded: vcJwt });

View File

@@ -6,25 +6,40 @@ import * as R from "ramda";
import { useClipboard } from "@vueuse/core"; import { useClipboard } from "@vueuse/core";
import { DEFAULT_PUSH_SERVER } from "@/constants/app"; import { DEFAULT_PUSH_SERVER } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import {
accountsDB,
retrieveSettingsForActiveAccount,
updateAccountSettings,
updateDefaultSettings,
} from "@/db/index";
import { Account } from "@/db/tables/accounts"; import { Account } from "@/db/tables/accounts";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import { import { DEFAULT_PASSKEY_EXPIRATION_MINUTES } from "@/db/tables/settings";
DEFAULT_PASSKEY_EXPIRATION_MINUTES,
MASTER_SETTINGS_KEY,
} from "@/db/tables/settings";
import { deriveAddress, generateSeed, newIdentifier } from "@/libs/crypto"; import { deriveAddress, generateSeed, newIdentifier } from "@/libs/crypto";
import * as serverUtil from "@/libs/endorserServer";
import { import {
containsHiddenDid, containsHiddenDid,
GenericCredWrapper, GenericCredWrapper,
GenericVerifiableCredential, GenericVerifiableCredential,
OfferVerifiableCredential, OfferVerifiableCredential,
} from "@/libs/endorserServer"; } from "@/libs/endorserServer";
import * as serverUtil from "@/libs/endorserServer";
import { KeyMeta } from "@/libs/crypto/vc"; import { KeyMeta } from "@/libs/crypto/vc";
import { createPeerDid } from "@/libs/crypto/vc/didPeer"; import { createPeerDid } from "@/libs/crypto/vc/didPeer";
import { registerCredential } from "@/libs/crypto/vc/passkeyDidPeer"; import { registerCredential } from "@/libs/crypto/vc/passkeyDidPeer";
export interface GiverReceiverInputInfo {
did?: string;
name?: string;
}
export enum OnboardPage {
Home = "HOME",
Discover = "DISCOVER",
Create = "CREATE",
Contact = "CONTACT",
Account = "ACCOUNT",
}
export const PRIVACY_MESSAGE = export const PRIVACY_MESSAGE =
"The data you send will be visible to the world -- except: your IDs and the IDs of anyone you tag will stay private, only visible to them and others you explicitly allow."; "The data you send will be visible to the world -- except: your IDs and the IDs of anyone you tag will stay private, only visible to them and others you explicitly allow.";
export const SHARED_PHOTO_BASE64_KEY = "shared-photo-base64"; export const SHARED_PHOTO_BASE64_KEY = "shared-photo-base64";
@@ -306,9 +321,9 @@ export const generateSaveAndActivateIdentity = async (): Promise<string> => {
publicKeyHex: newId.keys[0].publicKeyHex, publicKeyHex: newId.keys[0].publicKeyHex,
}); });
await db.settings.update(MASTER_SETTINGS_KEY, { await updateDefaultSettings({ activeDid: newId.did });
activeDid: newId.did, //console.log("Updated default settings in util");
}); await updateAccountSettings(newId.did, { isRegistered: false });
return newId.did; return newId.did;
}; };
@@ -336,45 +351,40 @@ export const registerSaveAndActivatePasskey = async (
keyName: string, keyName: string,
): Promise<Account> => { ): Promise<Account> => {
const account = await registerAndSavePasskey(keyName); const account = await registerAndSavePasskey(keyName);
await updateDefaultSettings({ activeDid: account.did });
await db.open(); await updateAccountSettings(account.did, { isRegistered: false });
await db.settings.update(MASTER_SETTINGS_KEY, {
activeDid: account.did,
});
return account; return account;
}; };
export const getPasskeyExpirationSeconds = async (): Promise<number> => { export const getPasskeyExpirationSeconds = async (): Promise<number> => {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); return (
const passkeyExpirationSeconds =
(settings?.passkeyExpirationMinutes ?? DEFAULT_PASSKEY_EXPIRATION_MINUTES) * (settings?.passkeyExpirationMinutes ?? DEFAULT_PASSKEY_EXPIRATION_MINUTES) *
60; 60
return passkeyExpirationSeconds; );
}; };
// These are shared with the service worker and should be a constant. Look for the same name in additional-scripts.js
export const DAILY_CHECK_TITLE = "DAILY_CHECK";
// This is a special value that tells the service worker to send a direct notification to the device, skipping filters.
export const DIRECT_PUSH_TITLE = "DIRECT_NOTIFICATION";
export const sendTestThroughPushServer = async ( export const sendTestThroughPushServer = async (
subscriptionJSON: PushSubscriptionJSON, subscriptionJSON: PushSubscriptionJSON,
skipFilter: boolean, skipFilter: boolean,
): Promise<AxiosResponse> => { ): Promise<AxiosResponse> => {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
let pushUrl: string = DEFAULT_PUSH_SERVER as string; let pushUrl: string = DEFAULT_PUSH_SERVER as string;
if (settings?.webPushServer) { if (settings?.webPushServer) {
pushUrl = settings.webPushServer; pushUrl = settings.webPushServer;
} }
// This is a special value that tells the service worker to send a direct notification to the device, skipping filters.
// This is shared with the service worker and should be a constant. Look for the same name in additional-scripts.js
// Use something other than "Daily Update" https://gitea.anomalistdesign.com/trent_larson/py-push-server/src/commit/3c0e196c11bc98060ec5934e99e7dbd591b5da4d/app.py#L213
const DIRECT_PUSH_TITLE = "DIRECT_NOTIFICATION";
const newPayload = { const newPayload = {
...subscriptionJSON,
// ... overridden with the following
// eslint-disable-next-line prettier/prettier // eslint-disable-next-line prettier/prettier
message: `Test, where you will see this message ${ skipFilter ? "un" : "" }filtered.`, message: `Test, where you will see this message ${ skipFilter ? "un" : "" }filtered.`,
title: skipFilter ? DIRECT_PUSH_TITLE : "Your Web Push", title: skipFilter ? DIRECT_PUSH_TITLE : "Your Web Push",
...subscriptionJSON,
}; };
console.log("Sending a test web push message:", newPayload); console.log("Sending a test web push message:", newPayload);
const payloadStr = JSON.stringify(newPayload); const payloadStr = JSON.stringify(newPayload);

View File

@@ -39,9 +39,12 @@ import {
faDollar, faDollar,
faEllipsis, faEllipsis,
faEllipsisVertical, faEllipsisVertical,
faEnvelopeOpenText,
faEraser,
faEye, faEye,
faEyeSlash, faEyeSlash,
faFileLines, faFileLines,
faFilter,
faFloppyDisk, faFloppyDisk,
faFolderOpen, faFolderOpen,
faForward, faForward,
@@ -54,6 +57,7 @@ import {
faHouseChimney, faHouseChimney,
faImagePortrait, faImagePortrait,
faLeftRight, faLeftRight,
faLightbulb,
faLocationDot, faLocationDot,
faLongArrowAltLeft, faLongArrowAltLeft,
faLongArrowAltRight, faLongArrowAltRight,
@@ -109,9 +113,12 @@ library.add(
faDollar, faDollar,
faEllipsis, faEllipsis,
faEllipsisVertical, faEllipsisVertical,
faEnvelopeOpenText,
faEraser,
faEye, faEye,
faEyeSlash, faEyeSlash,
faFileLines, faFileLines,
faFilter,
faFloppyDisk, faFloppyDisk,
faFolderOpen, faFolderOpen,
faForward, faForward,
@@ -124,6 +131,7 @@ library.add(
faHouseChimney, faHouseChimney,
faImagePortrait, faImagePortrait,
faLeftRight, faLeftRight,
faLightbulb,
faLocationDot, faLocationDot,
faLongArrowAltLeft, faLongArrowAltLeft,
faLongArrowAltRight, faLongArrowAltRight,

View File

@@ -103,6 +103,11 @@ const routes: Array<RouteRecordRaw> = [
name: "help-notifications", name: "help-notifications",
component: () => import("../views/HelpNotificationsView.vue"), component: () => import("../views/HelpNotificationsView.vue"),
}, },
{
path: "/help-notification-types",
name: "help-notification-types",
component: () => import("../views/HelpNotificationTypesView.vue"),
},
{ {
path: "/help-onboarding", path: "/help-onboarding",
name: "help-onboarding", name: "help-onboarding",
@@ -128,6 +133,16 @@ const routes: Array<RouteRecordRaw> = [
name: "import-derive", name: "import-derive",
component: () => import("../views/ImportDerivedAccountView.vue"), component: () => import("../views/ImportDerivedAccountView.vue"),
}, },
{
path: "/invite-one",
name: "invite-one",
component: () => import("../views/InviteOneView.vue"),
},
{
path: "/new-activity",
name: "new-activity",
component: () => import("../views/NewActivityView.vue"),
},
{ {
path: "/new-edit-account", path: "/new-edit-account",
name: "new-edit-account", name: "new-edit-account",
@@ -174,6 +189,16 @@ const routes: Array<RouteRecordRaw> = [
name: "quick-action-bvc-end", name: "quick-action-bvc-end",
component: () => import("../views/QuickActionBvcEndView.vue"), component: () => import("../views/QuickActionBvcEndView.vue"),
}, },
{
path: "/recent-offers-to-user",
name: "recent-offers-to-user",
component: () => import("../views/RecentOffersToUserView.vue"),
},
{
path: "/recent-offers-to-user-projects",
name: "recent-offers-to-user-projects",
component: () => import("../views/RecentOffersToUserProjectsView.vue"),
},
{ {
path: "/scan-contact", path: "/scan-contact",
name: "scan-contact", name: "scan-contact",
@@ -189,6 +214,11 @@ const routes: Array<RouteRecordRaw> = [
name: "seed-backup", name: "seed-backup",
component: () => import("../views/SeedBackupView.vue"), component: () => import("../views/SeedBackupView.vue"),
}, },
{
path: "/share-my-contact-info",
name: "share-my-contact-info",
component: () => import("@/views/ShareMyContactInfoView.vue"),
},
{ {
path: "/shared-photo", path: "/shared-photo",
name: "shared-photo", name: "shared-photo",

View File

@@ -1,20 +0,0 @@
// @ts-check
import { defineStore } from "pinia";
export const useAppStore = defineStore({
id: "app",
state: () => ({
_projectId:
typeof localStorage.getItem("projectId") === "undefined"
? ""
: localStorage.getItem("projectId"),
}),
getters: {
projectId: (state): string => state._projectId as string,
},
actions: {
async setProjectId(newProjectId: string) {
localStorage.setItem("projectId", newProjectId);
},
},
});

View File

@@ -1,10 +1,9 @@
import axios from "axios"; import axios from "axios";
import * as didJwt from "did-jwt"; import * as didJwt from "did-jwt";
import { AppString } from "@/constants/app"; import { AppString } from "@/constants/app";
import { db } from "../db"; import { retrieveSettingsForActiveAccount } from "../db";
import { SERVICE_ID } from "../libs/endorserServer"; import { SERVICE_ID } from "@/libs/endorserServer";
import { deriveAddress, newIdentifier } from "../libs/crypto"; import { deriveAddress, newIdentifier } from "@/libs/crypto";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
/** /**
* Get User #0 to sign & submit a RegisterAction for the user's activeDid. * Get User #0 to sign & submit a RegisterAction for the user's activeDid.
@@ -17,8 +16,7 @@ export async function testServerRegisterUser() {
const identity0 = newIdentifier(addr, publicHex, privateHex, deriPath); const identity0 = newIdentifier(addr, publicHex, privateHex, deriPath);
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
// Make a claim // Make a claim
const vcClaim = { const vcClaim = {
@@ -26,7 +24,7 @@ export async function testServerRegisterUser() {
"@type": "RegisterAction", "@type": "RegisterAction",
agent: { did: identity0.did }, agent: { did: identity0.did },
object: SERVICE_ID, object: SERVICE_ID,
participant: { did: settings?.activeDid }, participant: { did: settings.activeDid },
}; };
// Make a payload for the claim // Make a payload for the claim
const vcPayload = { const vcPayload = {
@@ -53,7 +51,7 @@ export async function testServerRegisterUser() {
const payload = JSON.stringify({ jwtEncoded: vcJwt }); const payload = JSON.stringify({ jwtEncoded: vcJwt });
const endorserApiServer = const endorserApiServer =
settings?.apiServer || AppString.TEST_ENDORSER_API_SERVER; settings.apiServer || AppString.TEST_ENDORSER_API_SERVER;
const url = endorserApiServer + "/api/claim"; const url = endorserApiServer + "/api/claim";
const headers = { const headers = {
"Content-Type": "application/json", "Content-Type": "application/json",

View File

@@ -5,28 +5,15 @@
<!-- CONTENT --> <!-- CONTENT -->
<section id="Content" class="p-6 pb-24 max-w-3xl mx-auto"> <section id="Content" class="p-6 pb-24 max-w-3xl mx-auto">
<!-- Heading --> <!-- Heading -->
<h1 id="ViewHeading" class="text-4xl text-center font-light pt-4 mb-4"> <h1 id="ViewHeading" class="text-4xl text-center font-light">
Your Identity Your Identity
</h1> </h1>
<div class="flex justify-between">
<span />
<span class="whitespace-nowrap">
<router-link
:to="{ name: 'contact-qr' }"
class="text-xs bg-slate-500 text-white px-1.5 py-1 rounded-md"
>
<fa icon="qrcode" class="fa-fw"></fa>
</router-link>
</span>
<span />
</div>
<!-- ID notice --> <!-- ID notice -->
<div <div
v-if="!activeDid" v-if="!activeDid"
id="noticeBeforeShare" id="noticeBeforeShare"
class="bg-amber-200 text-amber-900 border-amber-500 border-dashed border text-center rounded-md overflow-hidden px-4 py-3 mb-4" class="bg-amber-200 text-amber-900 border-amber-500 border-dashed border text-center rounded-md overflow-hidden px-4 py-3 mt-4"
> >
<p class="mb-4"> <p class="mb-4">
<b>Note:</b> Before you can share with others or take any action, you <b>Note:</b> Before you can share with others or take any action, you
@@ -43,10 +30,18 @@
<!-- Identity Details --> <!-- Identity Details -->
<div <div
id="sectionIdentityDetails" id="sectionIdentityDetails"
class="bg-slate-100 rounded-md overflow-hidden px-4 py-3 mb-4" class="bg-slate-100 rounded-md overflow-hidden px-4 py-3 mt-4"
> >
<div v-if="givenName"> <div v-if="givenName">
<h2 class="text-xl font-semibold mb-2"> <h2 class="text-xl font-semibold mb-2">
<span class="whitespace-nowrap">
<router-link
:to="{ name: 'contact-qr' }"
class="bg-slate-500 text-white px-1.5 py-1 rounded-md"
>
<fa icon="qrcode" class="fa-fw text-xl"></fa>
</router-link>
</span>
{{ givenName }} {{ givenName }}
<router-link :to="{ name: 'new-edit-account' }"> <router-link :to="{ name: 'new-edit-account' }">
<fa icon="pen" class="text-xs text-blue-500 ml-2 mb-1"></fa> <fa icon="pen" class="text-xs text-blue-500 ml-2 mb-1"></fa>
@@ -55,14 +50,20 @@
</div> </div>
<span <span
v-else v-else
class="block w-full text-center text-md bg-amber-200 text-blue-500 uppercase border border-dashed border-slate-400 px-1.5 py-2 rounded-md mb-2" class="block w-full text-center text-md bg-amber-200 border border-dashed border-slate-400 px-1.5 py-2 rounded-md mb-2"
> >
<router-link <button
:to="{ name: 'new-edit-account' }" @click="
class="inline-block text-md bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-4 py-2 rounded-md" () =>
(this.$refs.userNameDialog as UserNameDialog).open(
(name) => (this.givenName = name),
)
"
class="inline-block text-md uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-4 py-2 rounded-md"
> >
Set Your Name Set Your Name
</router-link> </button>
<UserNameDialog ref="userNameDialog" />
</span> </span>
<div class="flex justify-center mt-4"> <div class="flex justify-center mt-4">
<span v-if="profileImageUrl" class="flex justify-between"> <span v-if="profileImageUrl" class="flex justify-between">
@@ -129,7 +130,10 @@
</div> </div>
<div class="text-slate-500 text-sm font-bold">ID</div> <div class="text-slate-500 text-sm font-bold">ID</div>
<div class="text-sm text-slate-500 flex justify-start items-center mb-1"> <div
class="text-sm text-slate-500 flex justify-start items-center mb-1"
data-testId="didWrapper"
>
<code class="truncate">{{ activeDid }}</code> <code class="truncate">{{ activeDid }}</code>
<button <button
@click=" @click="
@@ -150,11 +154,14 @@
</div> </div>
<!-- Registration notice --> <!-- Registration notice -->
<!-- We won't show any loading indicator because it usually doesn't change anything. We'll just pop the message in only if we discover that they need it. --> <!--
We won't show any loading indicator because it usually doesn't change anything.
We'll just pop the message in only if we discover that they need it.
-->
<div <div
v-if="!loadingLimits && !endorserLimits?.nextWeekBeginDateTime" v-if="!loadingLimits && !endorserLimits?.nextWeekBeginDateTime"
id="noticeBeforeAnnounce" id="noticeBeforeAnnounce"
class="bg-amber-200 text-amber-900 border-amber-500 border-dashed border text-center rounded-md overflow-hidden px-4 py-3 mb-4" class="bg-amber-200 text-amber-900 border-amber-500 border-dashed border text-center rounded-md overflow-hidden px-4 py-3 mt-4"
> >
<p class="mb-4"> <p class="mb-4">
<b>Note:</b> Before you can publicly announce a new project or time <b>Note:</b> Before you can publicly announce a new project or time
@@ -174,20 +181,54 @@
> >
<!-- label --> <!-- label -->
<div class="mb-2 font-bold">Notifications</div> <div class="mb-2 font-bold">Notifications</div>
<div <div class="flex items-center justify-between">
v-if="!notificationMaybeChanged"
class="flex items-center justify-between cursor-pointer"
@click="showNotificationChoice()"
>
<!-- label --> <!-- label -->
<div>App Notifications</div> <div>
Reminder Notification
<fa
icon="question-circle"
class="text-slate-400 fa-fw ml-2 cursor-pointer"
@click.stop="showReminderNotificationInfo"
/>
</div>
<!-- toggle --> <!-- toggle -->
<div class="relative ml-2"> <div
class="relative ml-2 cursor-pointer"
@click="showReminderNotificationChoice()"
>
<!-- input -->
<input type="checkbox" v-model="notifyingReminder" class="sr-only" />
<!-- line -->
<div class="block bg-slate-500 w-14 h-8 rounded-full"></div>
<!-- dot -->
<div
class="dot absolute left-1 top-1 bg-slate-400 w-6 h-6 rounded-full transition"
></div>
</div>
</div>
<div v-if="notifyingReminder" class="w-full flex justify-between">
<span class="ml-8 mr-8">Message: "{{ notifyingReminderMessage }}"</span>
<span>{{ notifyingReminderTime.replace(" ", "&nbsp;") }}</span>
</div>
<div class="mt-2 flex items-center justify-between">
<!-- label -->
<div>
New Activity Notification
<fa
icon="question-circle"
class="text-slate-400 fa-fw ml-2 cursor-pointer"
@click.stop="showNewActivityNotificationInfo"
/>
</div>
<!-- toggle -->
<div
class="relative ml-2 cursor-pointer"
@click="showNewActivityNotificationChoice()"
>
<!-- input --> <!-- input -->
<input <input
type="checkbox" type="checkbox"
v-model="isSubscribed" v-model="notifyingNewActivity"
name="toggleNotificationsInput"
class="sr-only" class="sr-only"
/> />
<!-- line --> <!-- line -->
@@ -198,14 +239,14 @@
></div> ></div>
</div> </div>
</div> </div>
<div v-else> <div v-if="notifyingNewActivityTime" class="w-full text-right">
Notification status may have changed. Refresh this page to see the {{ notifyingNewActivityTime.replace(" ", "&nbsp;") }}
latest setting.
</div> </div>
<router-link class="pl-4 text-sm text-blue-500" to="/help-notifications"> <router-link class="pl-4 text-sm text-blue-500" to="/help-notifications">
Troubleshoot your notification setup. Troubleshoot your notification setup.
</router-link> </router-link>
</div> </div>
<PushNotificationPermission ref="pushNotificationPermission" />
<div <div
id="sectionSearchLocation" id="sectionSearchLocation"
@@ -250,10 +291,7 @@
<b>{{ endorserLimits.doneRegistrationsThisMonth }} registrations</b> <b>{{ endorserLimits.doneRegistrationsThisMonth }} registrations</b>
out of <b>{{ endorserLimits.maxRegistrationsPerMonth }}</b> for this out of <b>{{ endorserLimits.maxRegistrationsPerMonth }}</b> for this
month. month.
<i <i>(You cannot register anyone else on your first day.)</i>
>(You can register nobody on your first day, and after that only one
a day in your first month.)</i
>
Your registration counter resets at Your registration counter resets at
<b class="whitespace-nowrap"> <b class="whitespace-nowrap">
{{ readableDate(endorserLimits.nextMonthBeginDateTime) }} {{ readableDate(endorserLimits.nextMonthBeginDateTime) }}
@@ -306,7 +344,7 @@
> >
If no download happened yet, click again here to download now. If no download happened yet, click again here to download now.
</a> </a>
<div> <div class="mt-4">
<p> <p>
After the download, you can save the file in your preferred storage After the download, you can save the file in your preferred storage
location. location.
@@ -422,24 +460,37 @@
<div class="ml-4 mt-2"> <div class="ml-4 mt-2">
<input type="file" @change="uploadImportFile" class="ml-2" /> <input type="file" @change="uploadImportFile" class="ml-2" />
<div v-if="showContactImport()" class="mt-4"> <transition
<button enter-active-class="transform ease-out duration-300 transition"
class="block text-center text-md bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md mb-6" enter-from-class="translate-y-2 opacity-0 sm:translate-y-4"
@click="confirmSubmitImportFile()" enter-to-class="translate-y-0 opacity-100 sm:translate-y-0"
> leave-active-class="transition ease-in duration-500"
Overwrite Settings & Contacts leave-from-class="opacity-100"
<br /> leave-to-class="opacity-0"
(which doesn't include Identifier Data) >
</button> <div v-if="showContactImport()" class="mt-4">
<button <div class="flex justify-center">
class="block text-center text-md bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md mb-6" <button
@click="checkContactImports()" class="block text-center text-md bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md mb-6"
> @click="confirmSubmitImportFile()"
Import Contacts >
<br /> Overwrite Settings & Contacts
after comparing <br />
</button> (which doesn't include Identifier Data)
</div> </button>
</div>
<div class="flex justify-center">
<button
class="block text-center text-md bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md mb-6"
@click="checkContactImports()"
>
Import Only Contacts
<br />
after comparing
</button>
</div>
</div>
</transition>
</div> </div>
</div> </div>
@@ -586,6 +637,45 @@
{{ DEFAULT_PUSH_SERVER }} {{ DEFAULT_PUSH_SERVER }}
</span> </span>
<h2 class="text-slate-500 text-sm font-bold mb-2">Partner Server URL</h2>
<div class="px-3 py-4">
<input
type="text"
class="block w-full rounded border border-slate-400 px-3 py-2"
v-model="partnerApiServerInput"
/>
<button
v-if="partnerApiServerInput != partnerApiServer"
class="w-full px-4 rounded bg-yellow-500 border border-slate-400"
@click="onClickSavePartnerServer()"
>
<fa icon="floppy-disk" class="fa-fw" color="white"></fa>
</button>
<button
class="px-3 rounded bg-slate-200 border border-slate-400"
@click="partnerApiServerInput = AppConstants.PROD_PARTNER_API_SERVER"
>
Use Prod
</button>
<button
class="px-3 rounded bg-slate-200 border border-slate-400"
@click="partnerApiServerInput = AppConstants.TEST_PARTNER_API_SERVER"
>
Use Test
</button>
<button
class="px-3 rounded bg-slate-200 border border-slate-400"
@click="partnerApiServerInput = AppConstants.LOCAL_PARTNER_API_SERVER"
>
Use Local
</button>
</div>
<span class="px-4 text-sm" v-if="!partnerApiServerInput">
When that setting is blank, this app will use the default partner server
URL:
{{ DEFAULT_PARTNER_API_SERVER }}
</span>
<div id="sectionImageServerURL" class="mt-2"> <div id="sectionImageServerURL" class="mt-2">
<span class="text-slate-500 text-sm font-bold">Image Server URL</span> <span class="text-slate-500 text-sm font-bold">Image Server URL</span>
&nbsp; &nbsp;
@@ -715,22 +805,29 @@ import { useClipboard } from "@vueuse/core";
import EntityIcon from "@/components/EntityIcon.vue"; import EntityIcon from "@/components/EntityIcon.vue";
import ImageMethodDialog from "@/components/ImageMethodDialog.vue"; import ImageMethodDialog from "@/components/ImageMethodDialog.vue";
import PushNotificationPermission from "@/components/PushNotificationPermission.vue";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import TopMessage from "@/components/TopMessage.vue"; import TopMessage from "@/components/TopMessage.vue";
import UserNameDialog from "@/components/UserNameDialog.vue";
import { import {
AppString, AppString,
DEFAULT_IMAGE_API_SERVER, DEFAULT_IMAGE_API_SERVER,
DEFAULT_PARTNER_API_SERVER,
DEFAULT_PUSH_SERVER, DEFAULT_PUSH_SERVER,
IMAGE_TYPE_PROFILE, IMAGE_TYPE_PROFILE,
NotificationIface, NotificationIface,
} from "@/constants/app"; } from "@/constants/app";
import { db, accountsDB } from "@/db/index"; import {
db,
accountsDB,
retrieveSettingsForActiveAccount,
updateAccountSettings,
} from "@/db/index";
import { Account } from "@/db/tables/accounts"; import { Account } from "@/db/tables/accounts";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import { import {
DEFAULT_PASSKEY_EXPIRATION_MINUTES, DEFAULT_PASSKEY_EXPIRATION_MINUTES,
MASTER_SETTINGS_KEY, MASTER_SETTINGS_KEY,
Settings,
} from "@/db/tables/settings"; } from "@/db/tables/settings";
import { import {
clearPasskeyToken, clearPasskeyToken,
@@ -742,12 +839,19 @@ import {
ImageRateLimits, ImageRateLimits,
tokenExpiryTimeDescription, tokenExpiryTimeDescription,
} from "@/libs/endorserServer"; } from "@/libs/endorserServer";
import { getAccount } from "@/libs/util"; import { DAILY_CHECK_TITLE, DIRECT_PUSH_TITLE, getAccount } from "@/libs/util";
const inputImportFileNameRef = ref<Blob>(); const inputImportFileNameRef = ref<Blob>();
@Component({ @Component({
components: { EntityIcon, ImageMethodDialog, QuickNav, TopMessage }, components: {
EntityIcon,
ImageMethodDialog,
PushNotificationPermission,
QuickNav,
TopMessage,
UserNameDialog,
},
}) })
export default class AccountViewView extends Vue { export default class AccountViewView extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void; $notify!: (notification: NotificationIface, timeout?: number) => void;
@@ -755,6 +859,7 @@ export default class AccountViewView extends Vue {
AppConstants = AppString; AppConstants = AppString;
DEFAULT_PUSH_SERVER = DEFAULT_PUSH_SERVER; DEFAULT_PUSH_SERVER = DEFAULT_PUSH_SERVER;
DEFAULT_IMAGE_API_SERVER = DEFAULT_IMAGE_API_SERVER; DEFAULT_IMAGE_API_SERVER = DEFAULT_IMAGE_API_SERVER;
DEFAULT_PARTNER_API_SERVER = DEFAULT_PARTNER_API_SERVER;
activeDid = ""; activeDid = "";
apiServer = ""; apiServer = "";
@@ -767,10 +872,15 @@ export default class AccountViewView extends Vue {
imageLimits: ImageRateLimits | null = null; imageLimits: ImageRateLimits | null = null;
imageServer = ""; imageServer = "";
isRegistered = false; isRegistered = false;
isSubscribed = false;
limitsMessage = ""; limitsMessage = "";
loadingLimits = false; loadingLimits = false;
notificationMaybeChanged = false; notifyingNewActivity = false;
notifyingNewActivityTime = "";
notifyingReminder = false;
notifyingReminderMessage = "";
notifyingReminderTime = "";
partnerApiServer = "";
partnerApiServerInput = "";
passkeyExpirationDescription = ""; passkeyExpirationDescription = "";
passkeyExpirationMinutes = DEFAULT_PASSKEY_EXPIRATION_MINUTES; passkeyExpirationMinutes = DEFAULT_PASSKEY_EXPIRATION_MINUTES;
previousPasskeyExpirationMinutes = DEFAULT_PASSKEY_EXPIRATION_MINUTES; previousPasskeyExpirationMinutes = DEFAULT_PASSKEY_EXPIRATION_MINUTES;
@@ -811,10 +921,15 @@ export default class AccountViewView extends Vue {
/** /**
* Beware! I've seen where this "ready" never resolves. * Beware! I've seen where this "ready" never resolves.
*/ */
const registration = await navigator.serviceWorker.ready; const registration = await navigator.serviceWorker?.ready;
this.subscription = await registration.pushManager.getSubscription(); this.subscription = await registration.pushManager.getSubscription();
this.isSubscribed = !!this.subscription; if (!this.subscription) {
console.log("Got to the end of 'mounted' call."); if (this.notifyingNewActivity || this.notifyingReminder) {
// the app thought there was a subscription but there isn't, so fix the settings
this.turnOffNotifyingFlags();
}
}
// console.log("Got to the end of 'mounted' call in AccountViewView.");
/** /**
* Beware! I've seen where we never get to this point because "ready" never resolves. * Beware! I've seen where we never get to this point because "ready" never resolves.
*/ */
@@ -852,31 +967,36 @@ export default class AccountViewView extends Vue {
*/ */
async initializeState() { async initializeState() {
await db.open(); await db.open();
const settings: Settings | undefined = const settings = await retrieveSettingsForActiveAccount();
await db.settings.get(MASTER_SETTINGS_KEY);
this.activeDid = (settings?.activeDid as string) || ""; this.activeDid = settings.activeDid || "";
this.apiServer = (settings?.apiServer as string) || ""; this.apiServer = settings.apiServer || "";
this.apiServerInput = (settings?.apiServer as string) || ""; this.apiServerInput = settings.apiServer || "";
this.givenName = this.givenName =
(settings?.firstName || "") + (settings?.firstName || "") +
(settings?.lastName ? ` ${settings.lastName}` : ""); // pre v 0.1.3 (settings?.lastName ? ` ${settings.lastName}` : ""); // pre v 0.1.3
this.isRegistered = !!settings?.isRegistered;
this.imageServer = (settings?.imageServer as string) || "";
this.profileImageUrl = settings?.profileImageUrl as string;
this.showContactGives = !!settings?.showContactGivesInline;
this.hideRegisterPromptOnNewContact = this.hideRegisterPromptOnNewContact =
!!settings?.hideRegisterPromptOnNewContact; !!settings.hideRegisterPromptOnNewContact;
this.isRegistered = !!settings?.isRegistered;
this.imageServer = settings.imageServer || "";
this.notifyingNewActivity = !!settings.notifyingNewActivityTime;
this.notifyingNewActivityTime = settings.notifyingNewActivityTime || "";
this.notifyingReminder = !!settings.notifyingReminderTime;
this.notifyingReminderMessage = settings.notifyingReminderMessage || "";
this.notifyingReminderTime = settings.notifyingReminderTime || "";
this.partnerApiServer = settings.partnerApiServer || "";
this.partnerApiServerInput = settings.partnerApiServer || "";
this.profileImageUrl = settings.profileImageUrl;
this.showContactGives = !!settings.showContactGivesInline;
this.passkeyExpirationMinutes = this.passkeyExpirationMinutes =
(settings?.passkeyExpirationMinutes as number) ?? settings.passkeyExpirationMinutes ?? DEFAULT_PASSKEY_EXPIRATION_MINUTES;
DEFAULT_PASSKEY_EXPIRATION_MINUTES;
this.previousPasskeyExpirationMinutes = this.passkeyExpirationMinutes; this.previousPasskeyExpirationMinutes = this.passkeyExpirationMinutes;
this.showGeneralAdvanced = !!settings?.showGeneralAdvanced; this.showGeneralAdvanced = !!settings.showGeneralAdvanced;
this.showShortcutBvc = !!settings?.showShortcutBvc; this.showShortcutBvc = !!settings.showShortcutBvc;
this.warnIfProdServer = !!settings?.warnIfProdServer; this.warnIfProdServer = !!settings.warnIfProdServer;
this.warnIfTestServer = !!settings?.warnIfTestServer; this.warnIfTestServer = !!settings.warnIfTestServer;
this.webPushServer = (settings?.webPushServer as string) || ""; this.webPushServer = settings.webPushServer || "";
this.webPushServerInput = (settings?.webPushServer as string) || ""; this.webPushServerInput = settings.webPushServer || "";
} }
// call fn, copy text to the clipboard, then redo fn after 2 seconds // call fn, copy text to the clipboard, then redo fn after 2 seconds
@@ -887,29 +1007,44 @@ export default class AccountViewView extends Vue {
.then(() => setTimeout(fn, 2000)); .then(() => setTimeout(fn, 2000));
} }
toggleShowContactAmounts() { async toggleShowContactAmounts() {
this.showContactGives = !this.showContactGives; this.showContactGives = !this.showContactGives;
this.updateShowContactAmounts(); await db.open();
await db.settings.update(MASTER_SETTINGS_KEY, {
showContactGivesInline: this.showContactGives,
});
} }
toggleShowGeneralAdvanced() { async toggleShowGeneralAdvanced() {
this.showGeneralAdvanced = !this.showGeneralAdvanced; this.showGeneralAdvanced = !this.showGeneralAdvanced;
this.updateShowGeneralAdvanced(); await db.open();
await db.settings.update(MASTER_SETTINGS_KEY, {
showGeneralAdvanced: this.showGeneralAdvanced,
});
} }
toggleProdWarning() { async toggleProdWarning() {
this.warnIfProdServer = !this.warnIfProdServer; this.warnIfProdServer = !this.warnIfProdServer;
this.updateWarnIfProdServer(this.warnIfProdServer); await db.open();
await db.settings.update(MASTER_SETTINGS_KEY, {
warnIfProdServer: this.warnIfProdServer,
});
} }
toggleTestWarning() { async toggleTestWarning() {
this.warnIfTestServer = !this.warnIfTestServer; this.warnIfTestServer = !this.warnIfTestServer;
this.updateWarnIfTestServer(this.warnIfTestServer); await db.open();
await db.settings.update(MASTER_SETTINGS_KEY, {
warnIfTestServer: this.warnIfTestServer,
});
} }
toggleShowShortcutBvc() { async toggleShowShortcutBvc() {
this.showShortcutBvc = !this.showShortcutBvc; this.showShortcutBvc = !this.showShortcutBvc;
this.updateShowShortcutBvc(this.showShortcutBvc); await db.open();
await db.settings.update(MASTER_SETTINGS_KEY, {
showShortcutBvc: this.showShortcutBvc,
});
} }
readableDate(timeStr: string) { readableDate(timeStr: string) {
@@ -934,73 +1069,127 @@ export default class AccountViewView extends Vue {
} }
} }
async showNotificationChoice() { async showNewActivityNotificationInfo() {
if (!this.subscription) { this.$notify(
{
group: "modal",
type: "confirm",
title: "New Activity Notification",
text: `
This will only notify you when there is new relevant activity for you personally.
Note that it runs on your device and many factors may affect delivery,
so if you want a reliable but simple daily notification then choose a 'Reminder'.
Do you want more details?
`,
onYes: async () => {
await (this.$router as Router).push({
name: "help-notification-types",
});
},
yesText: "tell me more.",
},
-1,
);
}
async showNewActivityNotificationChoice() {
if (!this.notifyingNewActivity) {
(
this.$refs.pushNotificationPermission as PushNotificationPermission
).open(DAILY_CHECK_TITLE, async (success: boolean, timeText: string) => {
if (success) {
await db.settings.update(MASTER_SETTINGS_KEY, {
notifyingNewActivityTime: timeText,
});
this.notifyingNewActivity = true;
this.notifyingNewActivityTime = timeText;
}
});
} else {
this.$notify( this.$notify(
{ {
group: "modal", group: "modal",
type: "notification-permission", type: "notification-off",
title: "", // unused, only here to satisfy type check title: DAILY_CHECK_TITLE, // repurposed to indicate the type of notification
text: "", // unused, only here to satisfy type check text: "", // unused, only here to satisfy type check
callback: async (success) => {
if (success) {
await db.settings.update(MASTER_SETTINGS_KEY, {
notifyingNewActivityTime: "",
});
this.notifyingNewActivity = false;
this.notifyingNewActivityTime = "";
}
},
}, },
-1, -1,
); );
}
}
async showReminderNotificationInfo() {
this.$notify(
{
group: "modal",
type: "confirm",
title: "Reminder Notification",
text: `
This will notify you at a specific time each day.
Note that it does not give you personalized notifications,
so if you want less reliable but personalized notification then choose a 'New Activity' Notification.
Do you want more details?
`,
onYes: async () => {
await (this.$router as Router).push({
name: "help-notification-types",
});
},
yesText: "tell me more.",
},
-1,
);
}
async showReminderNotificationChoice() {
if (!this.notifyingReminder) {
(
this.$refs.pushNotificationPermission as PushNotificationPermission
).open(
DIRECT_PUSH_TITLE,
async (success: boolean, timeText: string, message?: string) => {
if (success) {
await db.settings.update(MASTER_SETTINGS_KEY, {
notifyingReminderMessage: message,
notifyingReminderTime: timeText,
});
this.notifyingReminder = true;
this.notifyingReminderMessage = message || "";
this.notifyingReminderTime = timeText;
}
},
);
} else { } else {
this.$notify( this.$notify(
{ {
group: "modal", group: "modal",
type: "notification-off", type: "notification-off",
title: "", // unused, only here to satisfy type check title: DIRECT_PUSH_TITLE, // repurposed to indicate the type of notification
text: "", // unused, only here to satisfy type check text: "", // unused, only here to satisfy type check
callback: async (success) => {
if (success) {
await db.settings.update(MASTER_SETTINGS_KEY, {
notifyingReminderMessage: "",
notifyingReminderTime: "",
});
this.notifyingReminder = false;
this.notifyingReminderMessage = "";
this.notifyingReminderTime = "";
}
},
}, },
-1, -1,
); );
} }
this.notificationMaybeChanged = true;
}
public async updateShowContactAmounts() {
await db.open();
await db.settings.update(MASTER_SETTINGS_KEY, {
showContactGivesInline: this.showContactGives,
});
}
public async updateShowGeneralAdvanced() {
await db.open();
await db.settings.update(MASTER_SETTINGS_KEY, {
showGeneralAdvanced: this.showGeneralAdvanced,
});
}
public async updateWarnIfProdServer(newSetting: boolean) {
try {
await db.open();
await db.settings.update(MASTER_SETTINGS_KEY, {
warnIfProdServer: newSetting,
});
} catch (err) {
this.$notify(
{
group: "alert",
type: "danger",
title: "Error Updating Prod Warning",
text: "The setting may not have saved. Try again, maybe after restarting the app.",
},
-1,
);
console.error(
"Telling user to try again after prod-server-warning setting update because:",
err,
);
}
}
public async updateWarnIfTestServer(newSetting: boolean) {
await db.open();
await db.settings.update(MASTER_SETTINGS_KEY, {
warnIfTestServer: newSetting,
});
} }
public async toggleHideRegisterPromptOnNewContact() { public async toggleHideRegisterPromptOnNewContact() {
@@ -1021,11 +1210,19 @@ export default class AccountViewView extends Vue {
this.passkeyExpirationDescription = tokenExpiryTimeDescription(); this.passkeyExpirationDescription = tokenExpiryTimeDescription();
} }
public async updateShowShortcutBvc(newSetting: boolean) { public async turnOffNotifyingFlags() {
// should tell the push server as well
await db.open(); await db.open();
await db.settings.update(MASTER_SETTINGS_KEY, { await db.settings.update(MASTER_SETTINGS_KEY, {
showShortcutBvc: newSetting, notifyingNewActivityTime: "",
notifyingReminderMessage: "",
notifyingReminderTime: "",
}); });
this.notifyingNewActivity = false;
this.notifyingNewActivityTime = "";
this.notifyingReminder = false;
this.notifyingReminderMessage = "";
this.notifyingReminderTime = "";
} }
/** /**
@@ -1118,16 +1315,16 @@ export default class AccountViewView extends Vue {
* @param {Error} error - The error object. * @param {Error} error - The error object.
*/ */
private handleExportError(error: unknown) { private handleExportError(error: unknown) {
console.error("Export Error:", error);
this.$notify( this.$notify(
{ {
group: "alert", group: "alert",
type: "danger", type: "danger",
title: "Export Error", title: "Export Error",
text: "See console logs for more info.", text: "There was an error exporting the data.",
}, },
-1, -1,
); );
console.error("Export Error:", error);
} }
async uploadImportFile(event: Event) { async uploadImportFile(event: Event) {
@@ -1208,7 +1405,7 @@ export default class AccountViewView extends Vue {
`Import progress: ${progress.completedRows} of ${progress.totalRows} rows completed.`, `Import progress: ${progress.completedRows} of ${progress.totalRows} rows completed.`,
); );
if (progress.done) { if (progress.done) {
console.log(`Imported ${progress.completedTables} tables.`); // console.log(`Imported ${progress.completedTables} tables.`);
this.$notify( this.$notify(
{ {
group: "alert", group: "alert",
@@ -1251,10 +1448,7 @@ export default class AccountViewView extends Vue {
if (!this.isRegistered) { if (!this.isRegistered) {
// the user was not known to be registered, but now they are (because we got no error) so let's record it // the user was not known to be registered, but now they are (because we got no error) so let's record it
try { try {
await db.open(); await updateAccountSettings(did, { isRegistered: true });
await db.settings.update(MASTER_SETTINGS_KEY, {
isRegistered: true,
});
this.isRegistered = true; this.isRegistered = true;
} catch (err) { } catch (err) {
console.error("Got an error updating settings:", err); console.error("Got an error updating settings:", err);
@@ -1377,6 +1571,14 @@ export default class AccountViewView extends Vue {
this.apiServer = this.apiServerInput; this.apiServer = this.apiServerInput;
} }
async onClickSavePartnerServer() {
await db.open();
await db.settings.update(MASTER_SETTINGS_KEY, {
partnerApiServer: this.partnerApiServerInput,
});
this.partnerApiServer = this.partnerApiServerInput;
}
async onClickSavePushServer() { async onClickSavePushServer() {
await db.open(); await db.open();
await db.settings.update(MASTER_SETTINGS_KEY, { await db.settings.update(MASTER_SETTINGS_KEY, {
@@ -1465,8 +1667,7 @@ export default class AccountViewView extends Vue {
if ((error as any).response.status === 404) { if ((error as any).response.status === 404) {
console.error("The image was already deleted:", error); console.error("The image was already deleted:", error);
await db.open(); await updateAccountSettings(this.activeDid, {
await db.settings.update(MASTER_SETTINGS_KEY, {
profileImageUrl: undefined, profileImageUrl: undefined,
}); });

View File

@@ -33,8 +33,7 @@ import { Component, Vue } from "vue-facing-decorator";
import { Router } from "vue-router"; import { Router } from "vue-router";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { db } from "@/db/index"; import { retrieveSettingsForActiveAccount } from "@/db/index";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
import * as serverUtil from "@/libs/endorserServer"; import * as serverUtil from "@/libs/endorserServer";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
@@ -50,10 +49,9 @@ export default class ClaimAddRawView extends Vue {
claimStr = ""; claimStr = "";
async mounted() { async mounted() {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; this.activeDid = settings.activeDid || "";
this.activeDid = settings?.activeDid || ""; this.apiServer = settings.apiServer || "";
this.apiServer = settings?.apiServer || "";
this.claimStr = (this.$route as Router).query["claim"]; this.claimStr = (this.$route as Router).query["claim"];
try { try {
@@ -89,7 +87,7 @@ export default class ClaimAddRawView extends Vue {
group: "alert", group: "alert",
type: "danger", type: "danger",
title: "Error", title: "Error",
text: "There was a problem submitting the claim. See logs for more info.", text: "There was a problem submitting the claim.",
}, },
-1, -1,
); );

View File

@@ -36,21 +36,6 @@
</button> </button>
</h2> </h2>
<div class="text-sm"> <div class="text-sm">
<div>
{{ veriClaim.id }}
<button
@click="
libsUtil.doCopyTwoSecRedo(
veriClaim.id as string,
() => (showIdCopy = !showIdCopy),
)
"
class="ml-2 mr-2"
>
<fa icon="copy" class="text-slate-400 fa-fw" />
</button>
<span v-show="showIdCopy">Copied ID</span>
</div>
<div data-testId="description"> <div data-testId="description">
<fa icon="message" class="fa-fw text-slate-400" /> <fa icon="message" class="fa-fw text-slate-400" />
{{ {{
@@ -60,21 +45,7 @@
</div> </div>
<div> <div>
<fa icon="user" class="fa-fw text-slate-400" /> <fa icon="user" class="fa-fw text-slate-400" />
{{ veriClaim.issuer }} {{ didInfo(veriClaim.issuer) }}
<span v-if="!serverUtil.isEmptyOrHiddenDid(veriClaim.issuer)">
<button
@click="
libsUtil.doCopyTwoSecRedo(
veriClaim.issuer as string,
() => (showDidCopy = !showDidCopy),
)
"
class="ml-2 mr-2"
>
<fa icon="copy" class="text-slate-400 fa-fw" />
</button>
<span v-show="showDidCopy">Copied DID</span>
</span>
</div> </div>
<div> <div>
<fa icon="calendar" class="fa-fw text-slate-400" /> <fa icon="calendar" class="fa-fw text-slate-400" />
@@ -86,10 +57,19 @@
</a> </a>
</div> </div>
<div v-if="veriClaim.claimType === 'PlanAction'" class="mt-4">
<router-link
:to="'/project/' + encodeURIComponent(veriClaim.handleId)"
class="text-blue-500 mt-2"
>
Go to Project page
</router-link>
</div>
<!-- Fullfills Links --> <!-- Fullfills Links -->
<!-- fullfills links for a give --> <!-- fullfills links for a give -->
<div v-if="detailsForGive?.fulfillsPlanHandleId"> <div v-if="detailsForGive?.fulfillsPlanHandleId" class="mt-4">
<router-link <router-link
:to=" :to="
'/project/' + '/project/' +
@@ -113,7 +93,7 @@
@click=" @click="
showDifferentClaimPage(detailsForGive?.fulfillsHandleId) showDifferentClaimPage(detailsForGive?.fulfillsHandleId)
" "
class="text-blue-500 mt-4" class="text-blue-500 mt-4 cursor-pointer"
> >
Fulfills Fulfills
{{ {{
@@ -136,6 +116,36 @@
Offered to a bigger plan... Offered to a bigger plan...
</router-link> </router-link>
</div> </div>
<!-- Providers -->
<div v-if="providersForGive?.length > 0" class="mt-4">
<span>Other assistance provided by:</span>
<ul class="ml-4">
<li
v-for="provider of providersForGive"
:key="provider.identifier"
class="list-disc ml-4"
>
<div class="flex gap-4">
<div class="grow overflow-hidden">
<a
@click="
provider.identifier.startsWith('did:')
? this.$router.push(
'/did/' +
encodeURIComponent(provider.identifier),
)
: showDifferentClaimPage(provider.identifier)
"
class="text-blue-500 mt-4 cursor-pointer"
>
an activity...
</a>
</div>
</div>
</li>
</ul>
</div>
</div> </div>
</div> </div>
</div> </div>
@@ -151,6 +161,7 @@
<fa icon="hand-holding-heart" class="ml-2 text-white cursor-pointer" /> <fa icon="hand-holding-heart" class="ml-2 text-white cursor-pointer" />
</button> </button>
</div> </div>
<GiftedDialog ref="customGiveDialog" />
<div v-if="libsUtil.isGiveAction(veriClaim)"> <div v-if="libsUtil.isGiveAction(veriClaim)">
<div class="flex columns-3"> <div class="flex columns-3">
@@ -182,7 +193,6 @@
</router-link> </router-link>
</span> </span>
</div> </div>
<GiftedDialog ref="customGiveDialog" />
<span v-if="totalConfirmers() === 0">Nobody has confirmed this.</span> <span v-if="totalConfirmers() === 0">Nobody has confirmed this.</span>
<span v-else-if="totalConfirmers() === 1"> <span v-else-if="totalConfirmers() === 1">
@@ -293,6 +303,7 @@
</div> </div>
</div> </div>
<!-- Note that a similar section is found in ConfirmGiftView.vue -->
<div> <div>
<h2 class="font-bold uppercase text-xl mt-8 mb-2"> <h2 class="font-bold uppercase text-xl mt-8 mb-2">
{{ serverUtil.containsHiddenDid(veriClaim) ? "Visible " : "" }}Details {{ serverUtil.containsHiddenDid(veriClaim) ? "Visible " : "" }}Details
@@ -320,7 +331,7 @@
If you'd like to ask any of your contacts to take a look and see if If you'd like to ask any of your contacts to take a look and see if
their contacts can see more details, their contacts can see more details,
<a <a
@click="copyToClipboard('This page location', windowLocation)" @click="copyToClipboard('A link to this page', windowLocation)"
class="text-blue-500" class="text-blue-500"
>share this page with them</a >share this page with them</a
> >
@@ -341,7 +352,7 @@
<span v-else> <span v-else>
If you'd like an introduction, If you'd like an introduction,
<a <a
@click="copyToClipboard('Location', windowLocation)" @click="copyToClipboard('A link to this page', windowLocation)"
class="text-blue-500" class="text-blue-500"
>share this page with them and ask if they'll tell you more about >share this page with them and ask if they'll tell you more about
about the participants.</a about the participants.</a
@@ -454,19 +465,22 @@ import { useClipboard } from "@vueuse/core";
import GiftedDialog from "@/components/GiftedDialog.vue"; import GiftedDialog from "@/components/GiftedDialog.vue";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
import * as serverUtil from "@/libs/endorserServer"; import * as serverUtil from "@/libs/endorserServer";
import * as libsUtil from "@/libs/util"; import * as libsUtil from "@/libs/util";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import { Account } from "@/db/tables/accounts"; import { Account } from "@/db/tables/accounts";
import { import {
GenericCredWrapper, GenericCredWrapper,
GiverReceiverInputInfo,
OfferVerifiableCredential, OfferVerifiableCredential,
} from "@/libs/endorserServer"; } from "@/libs/endorserServer";
interface ProviderInfo {
identifier: string; // could be a DID or a handleId
linkConfirmed: boolean;
}
@Component({ @Component({
components: { GiftedDialog, QuickNav }, components: { GiftedDialog, QuickNav },
}) })
@@ -490,7 +504,7 @@ export default class ClaimView extends Vue {
isEditedGlobalId = false; isEditedGlobalId = false;
isRegistered = false; isRegistered = false;
numConfsNotVisible = 0; // number of hidden DIDs in the confirmerIdList, minus the issuer if they aren't visible numConfsNotVisible = 0; // number of hidden DIDs in the confirmerIdList, minus the issuer if they aren't visible
showDidCopy = false; providersForGive: ProviderInfo[] = [];
showIdCopy = false; showIdCopy = false;
showVeriClaimDump = false; showVeriClaimDump = false;
veriClaim = serverUtil.BLANK_GENERIC_SERVER_RECORD; veriClaim = serverUtil.BLANK_GENERIC_SERVER_RECORD;
@@ -513,19 +527,19 @@ export default class ClaimView extends Vue {
this.fullClaimDump = ""; this.fullClaimDump = "";
this.fullClaimMessage = ""; this.fullClaimMessage = "";
this.isEditedGlobalId = false; this.isEditedGlobalId = false;
this.isRegistered = false;
this.numConfsNotVisible = 0; this.numConfsNotVisible = 0;
this.providersForGive = [];
this.veriClaim = serverUtil.BLANK_GENERIC_SERVER_RECORD; this.veriClaim = serverUtil.BLANK_GENERIC_SERVER_RECORD;
this.veriClaimDump = ""; this.veriClaimDump = "";
this.veriClaimDidsVisible = {};
} }
async created() { async created() {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; this.activeDid = settings.activeDid || "";
this.activeDid = settings?.activeDid || ""; this.apiServer = settings.apiServer || "";
this.apiServer = settings?.apiServer || "";
this.allContacts = await db.contacts.toArray(); this.allContacts = await db.contacts.toArray();
this.isRegistered = settings?.isRegistered || false; this.isRegistered = settings.isRegistered || false;
await accountsDB.open(); await accountsDB.open();
const accounts = accountsDB.accounts; const accounts = accountsDB.accounts;
@@ -623,11 +637,39 @@ export default class ClaimView extends Vue {
const giveResp = await this.axios.get(giveUrl, { const giveResp = await this.axios.get(giveUrl, {
headers: giveHeaders, headers: giveHeaders,
}); });
if (giveResp.status === 200) { if (giveResp.status === 200 && giveResp.data.data?.length > 0) {
this.detailsForGive = giveResp.data.data[0]; this.detailsForGive = giveResp.data.data[0];
} else { } else {
console.error("Error getting detailed give info:", giveResp); console.error("Error getting detailed give info:", giveResp);
} }
// look for providers
const providerUrl =
this.apiServer +
"/api/v2/report/providersToGive?handleId=" +
encodeURIComponent(this.veriClaim.handleId as string);
const providerHeaders = await serverUtil.getHeaders(userDid);
const providerResp = await this.axios.get(providerUrl, {
headers: providerHeaders,
});
// should be at least an empty array
if (
providerResp.status === 200 &&
Array.isArray(providerResp.data.data)
) {
this.providersForGive = providerResp.data.data;
} else {
console.error("Error getting give providers:", giveResp);
this.$notify(
{
group: "alert",
type: "warning",
title: "Error",
text: "Got error retrieving linked provider data.",
},
-1,
);
}
} else if (this.veriClaim.claimType === "Offer") { } else if (this.veriClaim.claimType === "Offer") {
const offerUrl = const offerUrl =
this.apiServer + this.apiServer +
@@ -641,6 +683,15 @@ export default class ClaimView extends Vue {
this.detailsForOffer = offerResp.data.data[0]; this.detailsForOffer = offerResp.data.data[0];
} else { } else {
console.error("Error getting detailed offer info:", offerResp); console.error("Error getting detailed offer info:", offerResp);
this.$notify(
{
group: "alert",
type: "warning",
title: "Error",
text: "Got error retrieving linked offer data.",
},
-1,
);
} }
} }
@@ -708,7 +759,7 @@ export default class ClaimView extends Vue {
group: "alert", group: "alert",
type: "danger", type: "danger",
title: "Error", title: "Error",
text: "There was a problem getting that claim. See logs for more info.", text: "There was a problem getting that claim.",
}, },
-1, -1,
); );
@@ -730,7 +781,7 @@ export default class ClaimView extends Vue {
group: "alert", group: "alert",
type: "danger", type: "danger",
title: "Error", title: "Error",
text: "Something went wrong retrieving that claim. See logs for more info.", text: "Something went wrong retrieving that claim.",
}, },
-1, -1,
); );
@@ -793,7 +844,7 @@ export default class ClaimView extends Vue {
group: "alert", group: "alert",
type: "danger", type: "danger",
title: "Error", title: "Error",
text: "There was a problem submitting the confirmation. See logs for more info.", text: "There was a problem submitting the confirmation.",
}, },
-1, -1,
); );
@@ -811,11 +862,12 @@ export default class ClaimView extends Vue {
} }
openFulfillGiftDialog() { openFulfillGiftDialog() {
const giver: GiverReceiverInputInfo = { const giver: libsUtil.GiverReceiverInputInfo = {
did: libsUtil.offerGiverDid( did: libsUtil.offerGiverDid(
this.veriClaim as GenericCredWrapper<OfferVerifiableCredential>, this.veriClaim as GenericCredWrapper<OfferVerifiableCredential>,
), ),
}; };
console.log("giver & dialog", giver, this.$refs.customGiveDialog);
(this.$refs.customGiveDialog as GiftedDialog).open( (this.$refs.customGiveDialog as GiftedDialog).open(
giver, giver,
undefined, undefined,

View File

@@ -25,7 +25,7 @@
> >
Do you agree? Do you agree?
</span> </span>
<span v-else> Details </span> <span v-else> Confirmation Details </span>
</h1> </h1>
</div> </div>
@@ -65,11 +65,11 @@
<!-- Details --> <!-- Details -->
<div class="bg-slate-100 rounded-md overflow-hidden px-4 py-3 mt-4"> <div class="bg-slate-100 rounded-md overflow-hidden px-4 py-3 mt-4">
<div class="block flex gap-4 overflow-hidden"> <div class="flex gap-4 overflow-hidden">
<div class="overflow-hidden"> <div class="overflow-hidden">
<div class="text-sm"> <div class="text-sm">
<div> <div>
<fa icon="arrow-down" class="fa-fw text-slate-400" /> <fa icon="arrow-left" class="fa-fw text-slate-400" />
{{ giverName }} {{ giverName }}
</div> </div>
<div class="ml-6">gave</div> <div class="ml-6">gave</div>
@@ -84,7 +84,7 @@
</div> </div>
<div class="ml-6">to</div> <div class="ml-6">to</div>
<div> <div>
<fa icon="arrow-up" class="fa-fw text-slate-400" /> <fa icon="arrow-right" class="fa-fw text-slate-400" />
{{ recipientName }} {{ recipientName }}
</div> </div>
<div> <div>
@@ -100,7 +100,7 @@
<router-link <router-link
:to=" :to="
'/project/' + '/project/' +
encodeURIComponent(giveDetails?.fulfillsPlanHandleId) encodeURIComponent(giveDetails?.fulfillsPlanHandleId || '')
" "
class="text-blue-500 mt-2 cursor-pointer" class="text-blue-500 mt-2 cursor-pointer"
target="_blank" target="_blank"
@@ -121,7 +121,7 @@
<router-link <router-link
:to=" :to="
'/claim/' + '/claim/' +
encodeURIComponent(giveDetails?.fulfillsHandleId) encodeURIComponent(giveDetails?.fulfillsHandleId || '')
" "
class="text-blue-500 mt-2 cursor-pointer" class="text-blue-500 mt-2 cursor-pointer"
target="_blank" target="_blank"
@@ -129,7 +129,7 @@
This fulfills This fulfills
{{ {{
capitalizeAndInsertSpacesBeforeCapsWithAPrefix( capitalizeAndInsertSpacesBeforeCapsWithAPrefix(
giveDetails.fulfillsType, giveDetails?.fulfillsType || "",
) )
}} }}
<fa icon="arrow-up-right-from-square" class="fa-fw" /> <fa icon="arrow-up-right-from-square" class="fa-fw" />
@@ -257,10 +257,11 @@
count as confirming it. count as confirming it.
</div> </div>
<div v-else-if="serverUtil.containsHiddenDid(veriClaim.claim)"> <div v-else-if="serverUtil.containsHiddenDid(veriClaim.claim)">
You cannot confirm this because it contains hidden identifiers. You cannot confirm this because some people are hidden.
</div> </div>
</div> </div>
<!-- Note that a similar section is found in ClaimView.vue -->
<h2 <h2
class="font-bold uppercase text-xl text-blue-500 mt-8 mb-2 cursor-pointer" class="font-bold uppercase text-xl text-blue-500 mt-8 mb-2 cursor-pointer"
@click="showDetails = !showDetails" @click="showDetails = !showDetails"
@@ -405,10 +406,9 @@ import { Router } from "vue-router";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { Account } from "@/db/tables/accounts"; import { Account } from "@/db/tables/accounts";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
import * as serverUtil from "@/libs/endorserServer"; import * as serverUtil from "@/libs/endorserServer";
import { displayAmount, GiveSummaryRecord } from "@/libs/endorserServer"; import { displayAmount, GiveSummaryRecord } from "@/libs/endorserServer";
import * as libsUtil from "@/libs/util"; import * as libsUtil from "@/libs/util";
@@ -464,12 +464,11 @@ export default class ClaimView extends Vue {
async mounted() { async mounted() {
this.isLoading = true; this.isLoading = true;
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; this.activeDid = settings.activeDid || "";
this.activeDid = settings?.activeDid || ""; this.apiServer = settings.apiServer || "";
this.apiServer = settings?.apiServer || "";
this.allContacts = await db.contacts.toArray(); this.allContacts = await db.contacts.toArray();
this.isRegistered = settings?.isRegistered || false; this.isRegistered = settings.isRegistered || false;
await accountsDB.open(); await accountsDB.open();
const accounts = accountsDB.accounts; const accounts = accountsDB.accounts;
@@ -657,7 +656,7 @@ export default class ClaimView extends Vue {
} }
if (this.giveDetails.fulfillsPlanHandleId) { if (this.giveDetails.fulfillsPlanHandleId) {
this.urlForNewGive += this.urlForNewGive +=
"&projectId=" + "&fulfillsProjectId=" +
encodeURIComponent(this.giveDetails.fulfillsPlanHandleId); encodeURIComponent(this.giveDetails.fulfillsPlanHandleId);
} }
@@ -764,7 +763,7 @@ export default class ClaimView extends Vue {
group: "alert", group: "alert",
type: "danger", type: "danger",
title: "Error", title: "Error",
text: "There was a problem submitting the confirmation. See logs for more info.", text: "There was a problem submitting the confirmation.",
}, },
5000, 5000,
); );
@@ -844,7 +843,7 @@ export default class ClaimView extends Vue {
group: "alert", group: "alert",
type: "info", type: "info",
title: "Cannot Confirm", title: "Cannot Confirm",
text: "You cannot confirm this because it contains hidden identifiers.", text: "You cannot confirm this because some people are hidden.",
}, },
3000, 3000,
); );

View File

@@ -112,9 +112,8 @@ import { Router } from "vue-router";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { import {
AgreeVerifiableCredential, AgreeVerifiableCredential,
createEndorserJwtVcFromClaim, createEndorserJwtVcFromClaim,
@@ -144,13 +143,12 @@ export default class ContactAmountssView extends Vue {
async created() { async created() {
try { try {
await db.open();
const contactDid = (this.$route as Router).query["contactDid"] as string; const contactDid = (this.$route as Router).query["contactDid"] as string;
this.contact = (await db.contacts.get(contactDid)) || null; this.contact = (await db.contacts.get(contactDid)) || null;
const settings = await db.settings.get(MASTER_SETTINGS_KEY); const settings = await retrieveSettingsForActiveAccount();
this.activeDid = (settings?.activeDid as string) || ""; this.activeDid = settings?.activeDid || "";
this.apiServer = (settings?.apiServer as string) || ""; this.apiServer = settings?.apiServer || "";
if (this.activeDid && this.contact) { if (this.activeDid && this.contact) {
this.loadGives(this.activeDid, this.contact); this.loadGives(this.activeDid, this.contact);
@@ -280,7 +278,7 @@ export default class ContactAmountssView extends Vue {
(origClaim.object?.amountOfThisGood as number) || 1; (origClaim.object?.amountOfThisGood as number) || 1;
} }
} catch (error) { } catch (error) {
let userMessage = "There was an error. See logs for more info."; let userMessage = "There was an error.";
const serverError = error as AxiosError; const serverError = error as AxiosError;
if (serverError) { if (serverError) {
if (serverError.message) { if (serverError.message) {

View File

@@ -11,8 +11,7 @@
class="text-lg text-center px-2 py-1 absolute -left-2 -top-1" class="text-lg text-center px-2 py-1 absolute -left-2 -top-1"
><fa icon="chevron-left" class="fa-fw"></fa ><fa icon="chevron-left" class="fa-fw"></fa
></router-link> ></router-link>
Given by...
Give to Contacts
</h1> </h1>
</div> </div>
@@ -72,15 +71,15 @@
<script lang="ts"> <script lang="ts">
import { Component, Vue } from "vue-facing-decorator"; import { Component, Vue } from "vue-facing-decorator";
import { Router } from "vue-router";
import GiftedDialog from "@/components/GiftedDialog.vue"; import GiftedDialog from "@/components/GiftedDialog.vue";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import EntityIcon from "@/components/EntityIcon.vue"; import EntityIcon from "@/components/EntityIcon.vue";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { db } from "@/db/index"; import { db, retrieveSettingsForActiveAccount } from "@/db/index";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings"; import { GiverReceiverInputInfo } from "@/libs/util";
import { GiverReceiverInputInfo } from "@/libs/endorserServer";
@Component({ @Component({
components: { GiftedDialog, QuickNav, EntityIcon }, components: { GiftedDialog, QuickNav, EntityIcon },
@@ -91,14 +90,15 @@ export default class ContactGiftingView extends Vue {
activeDid = ""; activeDid = "";
allContacts: Array<Contact> = []; allContacts: Array<Contact> = [];
apiServer = ""; apiServer = "";
projectId = localStorage.getItem("projectId") || ""; description = "";
projectId = "";
prompt = "";
async created() { async created() {
try { try {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; this.apiServer = settings.apiServer || "";
this.apiServer = settings?.apiServer || ""; this.activeDid = settings.activeDid || "";
this.activeDid = settings?.activeDid || "";
// .orderBy("name") wouldn't retrieve any entries with a blank name // .orderBy("name") wouldn't retrieve any entries with a blank name
// .toCollection.sortBy("name") didn't sort in an order I understood // .toCollection.sortBy("name") didn't sort in an order I understood
@@ -107,7 +107,9 @@ export default class ContactGiftingView extends Vue {
(a.name || "").localeCompare(b.name || ""), (a.name || "").localeCompare(b.name || ""),
); );
localStorage.removeItem("projectId"); this.projectId = (this.$route as Router).query["projectId"] || "";
this.prompt = (this.$route as Router).query["prompt"] ?? this.prompt;
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) { } catch (err: any) {
@@ -121,7 +123,7 @@ export default class ContactGiftingView extends Vue {
err.message || err.message ||
"There was an error retrieving your settings or contacts.", "There was an error retrieving your settings or contacts.",
}, },
-1, 5000,
); );
} }
} }
@@ -135,6 +137,7 @@ export default class ContactGiftingView extends Vue {
recipient, recipient,
undefined, undefined,
"Given by " + (giver?.name || "someone not named"), "Given by " + (giver?.name || "someone not named"),
this.prompt,
); );
} }
} }

View File

@@ -16,9 +16,9 @@
Contact Import Contact Import
</h1> </h1>
<span> <span class="flex justify-center">
Note that you will have to make them visible one-by-one in the list of <input type="checkbox" v-model="makeVisible" class="mr-2" />
Contacts. Make my activity visible to these contacts.
</span> </span>
<div v-if="sameCount > 0"> <div v-if="sameCount > 0">
<span v-if="sameCount == 1" <span v-if="sameCount == 1"
@@ -90,12 +90,13 @@ import { Component, Vue } from "vue-facing-decorator";
import { Router } from "vue-router"; import { Router } from "vue-router";
import { AppString, NotificationIface } from "@/constants/app"; import { AppString, NotificationIface } from "@/constants/app";
import { db } from "@/db/index"; import { db, retrieveSettingsForActiveAccount } from "@/db/index";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import * as libsUtil from "@/libs/util"; import * as libsUtil from "@/libs/util";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import EntityIcon from "@/components/EntityIcon.vue"; import EntityIcon from "@/components/EntityIcon.vue";
import OfferDialog from "@/components/OfferDialog.vue"; import OfferDialog from "@/components/OfferDialog.vue";
import { setVisibilityUtil } from "@/libs/endorserServer";
@Component({ @Component({
components: { EntityIcon, OfferDialog, QuickNav }, components: { EntityIcon, OfferDialog, QuickNav },
@@ -107,6 +108,8 @@ export default class ContactImportView extends Vue {
libsUtil = libsUtil; libsUtil = libsUtil;
R = R; R = R;
activeDid = "";
apiServer = "";
contactsExisting: Record<string, Contact> = {}; // user's contacts already in the system, keyed by DID contactsExisting: Record<string, Contact> = {}; // user's contacts already in the system, keyed by DID
contactsImporting: Array<Contact> = []; // contacts from the import contactsImporting: Array<Contact> = []; // contacts from the import
contactsSelected: Array<boolean> = []; // whether each contact in contactsImporting is selected contactsSelected: Array<boolean> = []; // whether each contact in contactsImporting is selected
@@ -115,16 +118,19 @@ export default class ContactImportView extends Vue {
Record<string, { new: string; old: string }> Record<string, { new: string; old: string }>
> = {}; // for existing contacts, it shows the difference between imported and existing contacts for each key > = {}; // for existing contacts, it shows the difference between imported and existing contacts for each key
importing = false; importing = false;
makeVisible = true;
sameCount = 0; sameCount = 0;
async created() { async created() {
const settings = await retrieveSettingsForActiveAccount();
this.activeDid = settings.activeDid || "";
this.apiServer = settings.apiServer || "";
// Retrieve the imported contacts from the query parameter // Retrieve the imported contacts from the query parameter
const importedContacts = const importedContacts =
((this.$route as Router).query["contacts"] as string) || "[]"; ((this.$route as Router).query["contacts"] as string) || "[]";
this.contactsImporting = JSON.parse(importedContacts); this.contactsImporting = JSON.parse(importedContacts);
this.contactsSelected = new Array(this.contactsImporting.length).fill( this.contactsSelected = new Array(this.contactsImporting.length).fill(true);
false,
);
await db.open(); await db.open();
const baseContacts = await db.contacts.toArray(); const baseContacts = await db.contacts.toArray();
@@ -150,9 +156,9 @@ export default class ContactImportView extends Vue {
if (R.isEmpty(differences)) { if (R.isEmpty(differences)) {
this.sameCount++; this.sameCount++;
} }
} else {
// automatically import new data // don't automatically import previous data
this.contactsSelected[i] = true; this.contactsSelected[i] = false;
} }
} }
} }
@@ -175,13 +181,46 @@ export default class ContactImportView extends Vue {
} }
} }
} }
if (this.makeVisible) {
const failedVisibileToContacts = [];
for (let i = 0; i < this.contactsImporting.length; i++) {
const contact = this.contactsImporting[i];
if (contact) {
const visResult = await setVisibilityUtil(
this.activeDid,
this.apiServer,
this.axios,
db,
contact,
true,
);
if (!visResult.success) {
failedVisibileToContacts.push(contact);
}
}
}
if (failedVisibileToContacts.length) {
this.$notify(
{
group: "alert",
type: "danger",
title: "Visibility Error",
text: `Failed to set visibility for ${failedVisibileToContacts.length} contact${
failedVisibileToContacts.length == 1 ? "" : "s"
}. You must set them individually: ${failedVisibileToContacts.map((c) => c.name).join(", ")}`,
},
-1,
);
}
}
this.importing = false; this.importing = false;
this.$notify( this.$notify(
{ {
group: "alert", group: "alert",
type: "success", type: "success",
title: "Import Success", title: "Imported",
text: text:
`${importedCount} contact${importedCount == 1 ? "" : "s"} imported.` + `${importedCount} contact${importedCount == 1 ? "" : "s"} imported.` +
(updatedCount ? ` ${updatedCount} updated.` : ""), (updatedCount ? ` ${updatedCount} updated.` : ""),

View File

@@ -1,5 +1,5 @@
<template> <template>
<QuickNav selected="Profile"></QuickNav> <QuickNav selected="Profile" />
<!-- CONTENT --> <!-- CONTENT -->
<section id="Content" class="p-6 pb-24 max-w-3xl mx-auto"> <section id="Content" class="p-6 pb-24 max-w-3xl mx-auto">
<!-- Breadcrumb --> <!-- Breadcrumb -->
@@ -10,7 +10,7 @@
class="text-lg text-center px-2 py-1 absolute -left-2 -top-1" class="text-lg text-center px-2 py-1 absolute -left-2 -top-1"
@click="$router.back()" @click="$router.back()"
> >
<fa icon="chevron-left" class="fa-fw"></fa> <fa icon="chevron-left" class="fa-fw" />
</h1> </h1>
</div> </div>
@@ -25,14 +25,17 @@
<span class="text-red">Beware!</span> <span class="text-red">Beware!</span>
You aren't sharing your name, so quickly You aren't sharing your name, so quickly
<br /> <br />
<router-link <span
:to="{ name: 'new-edit-account' }" @click="
() => $refs.userNameDialog.open((name) => (this.givenName = name))
"
class="bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-1 rounded-md" class="bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-1 rounded-md"
> >
click here to set it for them. click here to set it for them.
</router-link> </span>
</p> </p>
</div> </div>
<UserNameDialog ref="userNameDialog" />
<div <div
@click="onCopyUrlToClipboard()" @click="onCopyUrlToClipboard()"
@@ -50,7 +53,7 @@
class="flex justify-center" class="flex justify-center"
/> />
<span> <span>
Click this or QR code to copy your contact URL to your clipboard. Click the QR code to copy your contact info to your clipboard.
</span> </span>
</div> </div>
<div v-else-if="activeDid" class="text-center"> <div v-else-if="activeDid" class="text-center">
@@ -87,8 +90,6 @@
<script lang="ts"> <script lang="ts">
import { AxiosError } from "axios"; import { AxiosError } from "axios";
import { Buffer } from "buffer/";
import { sha256 } from "ethereum-cryptography/sha256.js";
import QRCodeVue3 from "qr-code-generator-vue3"; import QRCodeVue3 from "qr-code-generator-vue3";
import * as R from "ramda"; import * as R from "ramda";
import { Component, Vue } from "vue-facing-decorator"; import { Component, Vue } from "vue-facing-decorator";
@@ -96,19 +97,14 @@ import { QrcodeStream } from "vue-qrcode-reader";
import { useClipboard } from "@vueuse/core"; import { useClipboard } from "@vueuse/core";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import UserNameDialog from "@/components/UserNameDialog.vue";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { getContactPayloadFromJwtUrl } from "@/libs/crypto";
import { import {
deriveAddress, generateEndorserJwtForAccount,
getContactPayloadFromJwtUrl,
nextDerivationPath,
} from "@/libs/crypto";
import {
CONTACT_URL_PREFIX,
createEndorserJwtForDid,
ENDORSER_JWT_URL_LOCATION,
isDid, isDid,
register, register,
setVisibilityUtil, setVisibilityUtil,
@@ -120,6 +116,7 @@ import { ETHR_DID_PREFIX } from "@/libs/crypto/vc";
QrcodeStream, QrcodeStream,
QRCodeVue3, QRCodeVue3,
QuickNav, QuickNav,
UserNameDialog,
}, },
}) })
export default class ContactQRScanShow extends Vue { export default class ContactQRScanShow extends Vue {
@@ -135,54 +132,29 @@ export default class ContactQRScanShow extends Vue {
ETHR_DID_PREFIX = ETHR_DID_PREFIX; ETHR_DID_PREFIX = ETHR_DID_PREFIX;
async created() { async created() {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); this.activeDid = settings.activeDid || "";
this.activeDid = (settings?.activeDid as string) || ""; this.apiServer = settings.apiServer || "";
this.apiServer = (settings?.apiServer as string) || ""; this.givenName = settings.firstName || "";
this.givenName = (settings?.firstName as string) || "";
this.hideRegisterPromptOnNewContact = this.hideRegisterPromptOnNewContact =
!!settings?.hideRegisterPromptOnNewContact; !!settings.hideRegisterPromptOnNewContact;
this.isRegistered = !!settings?.isRegistered; this.isRegistered = !!settings.isRegistered;
await accountsDB.open(); await accountsDB.open();
const accounts = await accountsDB.accounts.toArray(); const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === this.activeDid, accounts); const account = R.find((acc) => acc.did === this.activeDid, accounts);
if (account) { if (account) {
const publicKeyHex = account.publicKeyHex; const name =
const publicEncKey = Buffer.from(publicKeyHex, "hex").toString("base64"); (settings.firstName || "") +
(settings.lastName ? ` ${settings.lastName}` : ""); // lastName is deprecated, pre v 0.1.3
const contactInfo = { this.qrValue = await generateEndorserJwtForAccount(
iat: Date.now(), account,
iss: this.activeDid, !!settings.isRegistered,
own: { name,
name: settings.profileImageUrl,
(settings?.firstName || "") + false,
(settings?.lastName ? ` ${settings.lastName}` : ""), // deprecated, pre v 0.1.3 );
publicEncKey,
profileImageUrl: settings?.profileImageUrl,
registered: settings?.isRegistered,
},
};
if (account?.mnemonic && account?.derivationPath) {
const newDerivPath = nextDerivationPath(
account.derivationPath as string,
);
const nextPublicHex = deriveAddress(
account.mnemonic as string,
newDerivPath,
)[2];
const nextPublicEncKey = Buffer.from(nextPublicHex, "hex");
const nextPublicEncKeyHash = sha256(nextPublicEncKey);
const nextPublicEncKeyHashBase64 =
Buffer.from(nextPublicEncKeyHash).toString("base64");
contactInfo.own.nextPublicEncKeyHash = nextPublicEncKeyHashBase64;
}
const vcJwt = await createEndorserJwtForDid(this.activeDid, contactInfo);
const viewPrefix = CONTACT_URL_PREFIX + ENDORSER_JWT_URL_LOCATION;
this.qrValue = viewPrefix + vcJwt;
} }
} }
@@ -390,7 +362,7 @@ export default class ContactQRScanShow extends Vue {
} }
} catch (error) { } catch (error) {
console.error("Error when registering:", error); console.error("Error when registering:", error);
let userMessage = "There was an error. See logs for more info."; let userMessage = "There was an error.";
const serverError = error as AxiosError; const serverError = error as AxiosError;
if (serverError) { if (serverError) {
if (serverError.response?.data?.error?.message) { if (serverError.response?.data?.error?.message) {

View File

@@ -4,11 +4,11 @@
<section id="Content" class="p-6 pb-24 max-w-3xl mx-auto"> <section id="Content" class="p-6 pb-24 max-w-3xl mx-auto">
<!-- Heading --> <!-- Heading -->
<h1 id="ViewHeading" class="text-4xl text-center font-light pt-4 mb-8"> <h1 id="ViewHeading" class="text-4xl text-center font-light">
Your Contacts Your Contacts
</h1> </h1>
<div class="flex justify-between py-2"> <div class="flex justify-between py-2 mt-8">
<span /> <span />
<span> <span>
<a <a
@@ -23,20 +23,28 @@
<!-- New Contact --> <!-- New Contact -->
<div id="formAddNewContact" class="mt-4 mb-4 flex items-stretch"> <div id="formAddNewContact" class="mt-4 mb-4 flex items-stretch">
<router-link
:to="{ name: 'invite-one' }"
class="flex items-center bg-gradient-to-b from-green-400 to-green-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-1 mr-1 rounded-md"
>
<fa icon="envelope-open-text" class="fa-fw text-2xl" />
</router-link>
<router-link <router-link
:to="{ name: 'contact-qr' }" :to="{ name: 'contact-qr' }"
class="flex items-center bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-1 mr-1 rounded-md" class="flex items-center bg-gradient-to-b from-green-400 to-green-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-1 mr-1 rounded-md"
> >
<fa icon="qrcode" class="fa-fw text-2xl" /> <fa icon="qrcode" class="fa-fw text-2xl" />
</router-link> </router-link>
<textarea <textarea
type="text" type="text"
placeholder="URL or DID, Name, Public Key, Next Public Key Hash" placeholder="New URL or DID, Name, Public Key, Next Public Key Hash"
class="block w-full rounded-l border border-r-0 border-slate-400 px-3 py-2 h-10" class="block w-full rounded-l border border-r-0 border-slate-400 px-3 py-2 h-10"
v-model="contactInput" v-model="contactInput"
/> />
<button <button
class="px-4 rounded-r bg-slate-200 border border-l-0 border-slate-400" class="px-4 rounded-r bg-green-200 border border-l-0 border-green-400"
@click="onClickNewContact()" @click="onClickNewContact()"
> >
<fa icon="plus" class="fa-fw" /> <fa icon="plus" class="fa-fw" />
@@ -79,7 +87,9 @@
class="text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1 py-1 rounded-md" class="text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1 py-1 rounded-md"
@click="toggleShowContactAmounts()" @click="toggleShowContactAmounts()"
> >
{{ showGiveNumbers ? "Hide Given Hours" : "Show Given Hours" }} {{
showGiveNumbers ? "Hide Hours, Offer, etc" : "See Hours, Offer, etc"
}}
</button> </button>
</div> </div>
</div> </div>
@@ -158,8 +168,12 @@
}" }"
title="See more about this person" title="See more about this person"
> >
<fa icon="circle-info" class="text-blue-500 ml-4" /> <fa icon="circle-info" class="text-xl text-blue-500 ml-4" />
</router-link> </router-link>
<span class="ml-4 text-sm overflow-hidden"
>{{ shortDid(contact.did) }}...</span
><!-- The first 18 characters of did:peer are the same. -->
</div> </div>
<div id="ContactActions" class="flex gap-1.5 mt-2"> <div id="ContactActions" class="flex gap-1.5 mt-2">
<div <div
@@ -168,6 +182,25 @@
> >
<button <button
class="text-sm bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-1.5 rounded-l-md" class="text-sm bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-1.5 rounded-l-md"
@click="confirmShowGiftedDialog(contact.did, activeDid)"
:title="givenToMeDescriptions[contact.did] || ''"
>
From:
<br />
{{
/* eslint-disable prettier/prettier */
this.showGiveTotals
? ((givenToMeConfirmed[contact.did] || 0)
+ (givenToMeUnconfirmed[contact.did] || 0))
: this.showGiveConfirmed
? (givenToMeConfirmed[contact.did] || 0)
: (givenToMeUnconfirmed[contact.did] || 0)
/* eslint-enable prettier/prettier */
}}
</button>
<button
class="text-sm bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white -ml-1.5 px-2 py-1.5 rounded-r-md border-l"
@click="confirmShowGiftedDialog(activeDid, contact.did)" @click="confirmShowGiftedDialog(activeDid, contact.did)"
:title="givenByMeDescriptions[contact.did] || ''" :title="givenByMeDescriptions[contact.did] || ''"
> >
@@ -183,34 +216,12 @@
: (givenByMeUnconfirmed[contact.did] || 0) : (givenByMeUnconfirmed[contact.did] || 0)
/* eslint-enable prettier/prettier */ /* eslint-enable prettier/prettier */
}} }}
<br />
<fa icon="plus" />
</button>
<button
class="text-sm bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white -ml-1.5 px-2 py-1.5 rounded-r-md border-l"
@click="confirmShowGiftedDialog(contact.did, this.activeDid)"
:title="givenToMeDescriptions[contact.did] || ''"
>
From:
<br />
{{
/* eslint-disable prettier/prettier */
this.showGiveTotals
? ((givenToMeConfirmed[contact.did] || 0)
+ (givenToMeUnconfirmed[contact.did] || 0))
: this.showGiveConfirmed
? (givenToMeConfirmed[contact.did] || 0)
: (givenToMeUnconfirmed[contact.did] || 0)
/* eslint-enable prettier/prettier */
}}
<br />
<fa icon="plus" />
</button> </button>
<button <button
class="text-sm bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-1.5 rounded-md border border-blue-400" class="text-sm bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-1.5 rounded-md border border-blue-400"
@click="openOfferDialog(contact.did, contact.name)" @click="openOfferDialog(contact.did, contact.name)"
data-testId="offerButton"
> >
Offer Offer
</button> </button>
@@ -262,6 +273,7 @@
<GiftedDialog ref="customGivenDialog" /> <GiftedDialog ref="customGivenDialog" />
<OfferDialog ref="customOfferDialog" /> <OfferDialog ref="customOfferDialog" />
<ContactNameDialog ref="contactNameDialog" />
<div v-if="showLargeIdenticon" class="fixed z-[100] top-0 inset-x-0 w-full"> <div v-if="showLargeIdenticon" class="fixed z-[100] top-0 inset-x-0 w-full">
<div <div
@@ -282,35 +294,51 @@
import { AxiosError } from "axios"; import { AxiosError } from "axios";
import { Buffer } from "buffer/"; import { Buffer } from "buffer/";
import { IndexableType } from "dexie"; import { IndexableType } from "dexie";
import { JWTPayload } from "did-jwt";
import * as R from "ramda"; import * as R from "ramda";
import { Component, Vue } from "vue-facing-decorator"; import { Component, Vue } from "vue-facing-decorator";
import { Router } from "vue-router"; import { RouteLocationNormalizedLoaded, Router } from "vue-router";
import { useClipboard } from "@vueuse/core"; import { useClipboard } from "@vueuse/core";
import QuickNav from "@/components/QuickNav.vue";
import EntityIcon from "@/components/EntityIcon.vue";
import GiftedDialog from "@/components/GiftedDialog.vue";
import OfferDialog from "@/components/OfferDialog.vue";
import ContactNameDialog from "@/components/ContactNameDialog.vue";
import TopMessage from "@/components/TopMessage.vue";
import { AppString, NotificationIface } from "@/constants/app"; import { AppString, NotificationIface } from "@/constants/app";
import { db } from "@/db/index"; import {
db,
retrieveSettingsForActiveAccount,
updateAccountSettings,
updateDefaultSettings,
} from "@/db/index";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
import { getContactPayloadFromJwtUrl } from "@/libs/crypto"; import { getContactPayloadFromJwtUrl } from "@/libs/crypto";
import { decodeEndorserJwt } from "@/libs/crypto/vc";
import { import {
CONTACT_CSV_HEADER, CONTACT_CSV_HEADER,
CONTACT_URL_PREFIX, CONTACT_URL_PREFIX,
GiverReceiverInputInfo,
GiveSummaryRecord, GiveSummaryRecord,
getHeaders, getHeaders,
isDid, isDid,
register, register,
setVisibilityUtil, setVisibilityUtil,
UserInfo,
VerifiableCredential,
} from "@/libs/endorserServer"; } from "@/libs/endorserServer";
import * as libsUtil from "@/libs/util"; import * as libsUtil from "@/libs/util";
import QuickNav from "@/components/QuickNav.vue"; import { generateSaveAndActivateIdentity } from "@/libs/util";
import EntityIcon from "@/components/EntityIcon.vue";
import GiftedDialog from "@/components/GiftedDialog.vue";
import OfferDialog from "@/components/OfferDialog.vue";
import TopMessage from "@/components/TopMessage.vue";
@Component({ @Component({
components: { TopMessage, GiftedDialog, EntityIcon, OfferDialog, QuickNav }, components: {
GiftedDialog,
EntityIcon,
OfferDialog,
QuickNav,
ContactNameDialog,
TopMessage,
},
}) })
export default class ContactsView extends Vue { export default class ContactsView extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void; $notify!: (notification: NotificationIface, timeout?: number) => void;
@@ -349,14 +377,14 @@ export default class ContactsView extends Vue {
public async created() { public async created() {
await db.open(); await db.open();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; const settings = await retrieveSettingsForActiveAccount();
this.activeDid = settings?.activeDid || ""; this.activeDid = settings.activeDid || "";
this.apiServer = settings?.apiServer || ""; this.apiServer = settings.apiServer || "";
this.isRegistered = !!settings?.isRegistered; this.isRegistered = !!settings.isRegistered;
this.showGiveNumbers = !!settings?.showContactGivesInline; this.showGiveNumbers = !!settings.showContactGivesInline;
this.hideRegisterPromptOnNewContact = this.hideRegisterPromptOnNewContact =
!!settings?.hideRegisterPromptOnNewContact; !!settings.hideRegisterPromptOnNewContact;
if (this.showGiveNumbers) { if (this.showGiveNumbers) {
this.loadGives(); this.loadGives();
@@ -368,6 +396,121 @@ export default class ContactsView extends Vue {
this.contacts = baseContacts.sort((a, b) => this.contacts = baseContacts.sort((a, b) =>
(a.name || "").localeCompare(b.name || ""), (a.name || "").localeCompare(b.name || ""),
); );
// handle a contact sent via URL
const importedContactJwt = (this.$route as RouteLocationNormalizedLoaded)
.query["contactJwt"] as string;
if (importedContactJwt) {
// really should fully verify contents
const { payload } = decodeEndorserJwt(importedContactJwt);
const userInfo = payload["own"] as UserInfo;
const newContact = {
did: payload["iss"],
name: userInfo.name,
nextPubKeyHashB64: userInfo.nextPublicEncKeyHash,
profileImageUrl: userInfo.profileImageUrl,
publicKeyBase64: userInfo.publicEncKey,
registered: userInfo.registered,
} as Contact;
this.addContact(newContact);
}
// handle an invite JWT sent via URL
const importedInviteJwt = (this.$route as RouteLocationNormalizedLoaded)
.query["inviteJwt"] as string;
if (importedInviteJwt === "") {
// this happens when a platform (usually iOS) doesn't include anything after the "=" in a shared link.
this.$notify(
{
group: "alert",
type: "warning",
title: "Blank Invite",
text: "The invite was not included. This can happen when your device cuts off the link, so you might try pasting the full link into a browser.",
},
7000,
);
} else if (importedInviteJwt) {
// make sure user is created
if (!this.activeDid) {
this.activeDid = await generateSaveAndActivateIdentity();
}
// send invite directly to server, with auth for this user
const headers = await getHeaders(this.activeDid);
try {
const response = await this.axios.post(
this.apiServer + "/api/v2/claim",
{ jwtEncoded: importedInviteJwt },
{ headers },
);
if (response.status != 201) {
throw { error: { response: response } };
}
await updateAccountSettings(this.activeDid, { isRegistered: true });
this.isRegistered = true;
this.$notify(
{
group: "alert",
type: "success",
title: "Registered",
text: "You are now registered.",
},
3000,
);
// now add the inviter as a contact
const payload: JWTPayload =
decodeEndorserJwt(importedInviteJwt).payload;
const registration = payload as VerifiableCredential;
(this.$refs.contactNameDialog as ContactNameDialog).open(
"Who Invited You?",
"",
(name) => {
// not doing await on purpose, so that they always see the onboarding
this.addContact({
did: registration.vc.credentialSubject.agent.identifier,
name: name,
registered: true,
});
this.showOnboardingInfo();
},
() => {
// not doing await on purpose, so that they always see the onboarding
this.addContact({
did: registration.vc.credentialSubject.agent.identifier,
name: "(person who invited you)",
registered: true,
});
this.showOnboardingInfo();
},
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
console.error("Error redeeming invite:", error);
let message = "Got an error sending the invite.";
if (
error.response &&
error.response.data &&
error.response.data.error
) {
if (error.response.data.error.message) {
message = error.response.data.error.message;
} else {
message = error.response.data.error;
}
} else if (error.message) {
message = error.message;
}
this.$notify(
{
group: "alert",
type: "danger",
title: "Error with Invite",
text: message,
},
5000,
);
}
}
} }
private danger(message: string, title: string = "Error", timeout = 5000) { private danger(message: string, title: string = "Error", timeout = 5000) {
@@ -382,6 +525,21 @@ export default class ContactsView extends Vue {
); );
} }
private showOnboardingInfo() {
this.$notify(
{
group: "modal",
type: "confirm",
title: "They're Added To Your List",
text: "Would you like to go to the main page now?",
onYes: async () => {
(this.$router as Router).push({ name: "home" });
},
},
-1,
);
}
private filteredContacts() { private filteredContacts() {
return this.showGiveNumbers return this.showGiveNumbers
? this.contactsSelected.length === 0 ? this.contactsSelected.length === 0
@@ -437,7 +595,7 @@ export default class ContactsView extends Vue {
(useRecipient ? "given" : "received") + (useRecipient ? "given" : "received") +
" data from the server.", " data from the server.",
}, },
-1, 5000,
); );
} }
}; };
@@ -710,17 +868,17 @@ export default class ContactsView extends Vue {
type: "confirm", type: "confirm",
title: "Register", title: "Register",
text: "Do you want to register them?", text: "Do you want to register them?",
onCancel: async (stopAsking: boolean) => { onCancel: async (stopAsking?: boolean) => {
if (stopAsking) { if (stopAsking) {
await db.settings.update(MASTER_SETTINGS_KEY, { await updateDefaultSettings({
hideRegisterPromptOnNewContact: stopAsking, hideRegisterPromptOnNewContact: stopAsking,
}); });
this.hideRegisterPromptOnNewContact = stopAsking; this.hideRegisterPromptOnNewContact = stopAsking;
} }
}, },
onNo: async (stopAsking: boolean) => { onNo: async (stopAsking?: boolean) => {
if (stopAsking) { if (stopAsking) {
await db.settings.update(MASTER_SETTINGS_KEY, { await updateDefaultSettings({
hideRegisterPromptOnNewContact: stopAsking, hideRegisterPromptOnNewContact: stopAsking,
}); });
this.hideRegisterPromptOnNewContact = stopAsking; this.hideRegisterPromptOnNewContact = stopAsking;
@@ -825,11 +983,18 @@ export default class ContactsView extends Vue {
} }
} catch (error) { } catch (error) {
console.error("Error when registering:", error); console.error("Error when registering:", error);
let userMessage = "There was an error. See logs for more info."; let userMessage = "There was an error.";
const serverError = error as AxiosError; const serverError = error as AxiosError;
if (serverError) { if (serverError.isAxiosError) {
if (serverError.response?.data?.error?.message) { if (
userMessage = serverError.response.data.error.message; serverError.response?.data &&
typeof serverError.response.data === "object" &&
"error" in serverError.response.data &&
typeof serverError.response.data.error === "object" &&
serverError.response.data.error !== null &&
"message" in serverError.response.data.error
) {
userMessage = serverError.response.data.error.message as string;
} else if (serverError.message) { } else if (serverError.message) {
userMessage = serverError.message; // Info for the user userMessage = serverError.message; // Info for the user
} else { } else {
@@ -885,7 +1050,10 @@ export default class ContactsView extends Vue {
} }
return true; return true;
} else { } else {
console.error("Got strange result from setting visibility:", result); console.error(
"Got strange result from setting visibility. It can happen when setting visibility on oneself.",
result,
);
const message = const message =
(result.error as string) || "Could not set visibility on the server."; (result.error as string) || "Could not set visibility on the server.";
this.$notify( this.$notify(
@@ -901,74 +1069,6 @@ export default class ContactsView extends Vue {
} }
} }
// note that this is also in DIDView.vue
private async checkVisibility(contact: Contact) {
const url =
this.apiServer +
"/api/report/canDidExplicitlySeeMe?did=" +
encodeURIComponent(contact.did);
const headers = await getHeaders(this.activeDid);
if (!headers["Authorization"]) {
this.$notify(
{
group: "alert",
type: "danger",
title: "No Identity",
text: "There is no identity to use to check visibility.",
},
3000,
);
return;
}
try {
const resp = await this.axios.get(url, { headers });
if (resp.status === 200) {
const visibility = resp.data;
contact.seesMe = visibility;
//console.log("Visi check:", visibility, contact.seesMe, contact.did);
await db.contacts.update(contact.did, { seesMe: visibility });
this.$notify(
{
group: "alert",
type: "info",
title: "Visibility Refreshed",
text:
libsUtil.nameForContact(contact, true) +
" can " +
(visibility ? "" : "not ") +
"see your activity.",
},
3000,
);
} else {
console.error("Got bad server response checking visibility:", resp);
const message = resp.data.error?.message || "Got bad server response.";
this.$notify(
{
group: "alert",
type: "danger",
title: "Error Checking Visibility",
text: message,
},
5000,
);
}
} catch (err) {
console.error("Caught error from request to check visibility:", err);
this.$notify(
{
group: "alert",
type: "danger",
title: "Error Checking Visibility",
text: "Check connectivity and try again.",
},
3000,
);
}
}
private confirmShowGiftedDialog(giverDid: string, recipientDid: string) { private confirmShowGiftedDialog(giverDid: string, recipientDid: string) {
// if they have unconfirmed amounts, ask to confirm those // if they have unconfirmed amounts, ask to confirm those
if ( if (
@@ -1010,7 +1110,8 @@ export default class ContactsView extends Vue {
} }
private showGiftedDialog(giverDid: string, recipientDid: string) { private showGiftedDialog(giverDid: string, recipientDid: string) {
let giver: GiverReceiverInputInfo, receiver: GiverReceiverInputInfo; let giver: libsUtil.GiverReceiverInputInfo | undefined;
let receiver: libsUtil.GiverReceiverInputInfo | undefined;
if (giverDid) { if (giverDid) {
giver = { giver = {
did: giverDid, did: giverDid,
@@ -1033,7 +1134,7 @@ export default class ContactsView extends Vue {
newList[recipientDid] = (newList[recipientDid] || 0) + amount; newList[recipientDid] = (newList[recipientDid] || 0) + amount;
this.givenByMeUnconfirmed = newList; this.givenByMeUnconfirmed = newList;
}; };
customTitle = "Given to " + receiver.name; customTitle = "Given to " + (receiver?.name || "Someone Unnamed");
} else { } else {
// must be (recipientDid == this.activeDid) // must be (recipientDid == this.activeDid)
callback = (amount: number) => { callback = (amount: number) => {
@@ -1041,13 +1142,14 @@ export default class ContactsView extends Vue {
newList[giverDid] = (newList[giverDid] || 0) + amount; newList[giverDid] = (newList[giverDid] || 0) + amount;
this.givenToMeUnconfirmed = newList; this.givenToMeUnconfirmed = newList;
}; };
customTitle = "Received from " + giver.name; customTitle = "Received from " + (giver?.name || "Someone Unnamed");
} }
(this.$refs.customGivenDialog as GiftedDialog).open( (this.$refs.customGivenDialog as GiftedDialog).open(
giver, giver,
receiver, receiver,
undefined as string, undefined as unknown as string,
customTitle, customTitle,
undefined as unknown as string,
callback, callback,
); );
} }
@@ -1062,8 +1164,7 @@ export default class ContactsView extends Vue {
private async toggleShowContactAmounts() { private async toggleShowContactAmounts() {
const newShowValue = !this.showGiveNumbers; const newShowValue = !this.showGiveNumbers;
try { try {
await db.open(); await updateDefaultSettings({
await db.settings.update(MASTER_SETTINGS_KEY, {
showContactGivesInline: newShowValue, showContactGivesInline: newShowValue,
}); });
} catch (err) { } catch (err) {
@@ -1074,7 +1175,7 @@ export default class ContactsView extends Vue {
title: "Error Updating Contact Setting", title: "Error Updating Contact Setting",
text: "The setting may not have saved. Try again, maybe after restarting the app.", text: "The setting may not have saved. Try again, maybe after restarting the app.",
}, },
-1, 5000,
); );
console.error( console.error(
"Telling user to try again after contact-amounts setting update because:", "Telling user to try again after contact-amounts setting update because:",
@@ -1128,8 +1229,8 @@ export default class ContactsView extends Vue {
this.contactsSelected.includes(c.did), this.contactsSelected.includes(c.did),
); );
const message = const message =
"To add contacts, paste this into the box on the 'People' screen.\n\n" + "To add contacts, paste this into the box on the 'Contacts' screen.\n\n" +
JSON.stringify(selectedContacts, null, 2); JSON.stringify(selectedContacts);
useClipboard() useClipboard()
.copy(message) .copy(message)
.then(() => { .then(() => {
@@ -1138,11 +1239,26 @@ export default class ContactsView extends Vue {
group: "alert", group: "alert",
type: "info", type: "info",
title: "Copied", title: "Copied",
text: "Those contacts were copied to the clipboard. Have them paste it in the box on their 'People' screen.", text: "Those contacts were copied to the clipboard. Have them paste it in the box on their 'Contacts' screen.",
}, },
5000, 5000,
); );
}); });
} }
private shortDid(did: string) {
if (did.startsWith("did:peer:")) {
return (
did.substring(0, "did:peer:".length + 2) +
"..." +
did.substring("did:peer:".length + 18, "did:peer:".length + 25) +
"..."
);
} else if (did.startsWith("did:ethr:")) {
return did.substring(0, "did:ethr:".length + 9) + "...";
} else {
return did.substring(0, did.indexOf(":", 4) + 7) + "...";
}
}
} }
</script> </script>

View File

@@ -19,14 +19,17 @@
</div> </div>
<!-- Identity Details --> <!-- Identity Details -->
<div class="bg-slate-100 rounded-md overflow-hidden px-4 py-3 mb-4"> <div
v-if="!!contactFromDid"
class="bg-slate-100 rounded-md overflow-hidden px-4 py-3 mb-4"
>
<div> <div>
<h2 class="text-xl font-semibold"> <h2 class="text-xl font-semibold">
{{ contact?.name || "(no name)" }} {{ contactFromDid?.name || "(no name)" }}
<button <button
@click=" @click="
contactEdit = true; contactEdit = true;
contactNewName = contact.name || ''; contactNewName = (contactFromDid?.name as string) || '';
" "
title="Edit" title="Edit"
> >
@@ -38,8 +41,8 @@
class="ml-2 mr-2 mt-4" class="ml-2 mr-2 mt-4"
> >
Details Details
<fa v-if="showDidDetails" icon="chevron-up" class="text-blue-400" /> <fa v-if="showDidDetails" icon="chevron-down" class="text-blue-400" />
<fa v-else icon="chevron-down" class="text-blue-400" /> <fa v-else icon="chevron-right" class="text-blue-400" />
</button> </button>
<!-- Keep the dump contents directly between > and < to avoid weird spacing. --> <!-- Keep the dump contents directly between > and < to avoid weird spacing. -->
<pre <pre
@@ -49,12 +52,15 @@
> >
</div> </div>
<div class="flex justify-center mt-4"> <div class="flex justify-center mt-4">
<span v-if="contact?.profileImageUrl" class="flex justify-between"> <span
v-if="contactFromDid?.profileImageUrl"
class="flex justify-between"
>
<EntityIcon <EntityIcon
:icon-size="96" :icon-size="96"
:profileImageUrl="contact?.profileImageUrl" :profileImageUrl="contactFromDid?.profileImageUrl"
class="inline-block align-text-bottom border border-slate-300 rounded" class="inline-block align-text-bottom border border-slate-300 rounded"
@click="showLargeIdenticonUrl = contact?.profileImageUrl" @click="showLargeIdenticonUrl = contactFromDid?.profileImageUrl"
/> />
</span> </span>
</div> </div>
@@ -63,62 +69,60 @@
<div v-if="activeDid" class="flex justify-between"> <div v-if="activeDid" class="flex justify-between">
<div> <div>
<button <button
v-if="contact?.seesMe && contact.did !== activeDid" v-if="
contactFromDid?.seesMe && contactFromDid.did !== activeDid
"
class="text-sm uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white mx-0.5 my-0.5 px-2 py-1.5 rounded-md" class="text-sm uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white mx-0.5 my-0.5 px-2 py-1.5 rounded-md"
@click="confirmSetVisibility(contact, false)" @click="confirmSetVisibility(contactFromDid, false)"
title="They can see you" title="They can see you"
> >
<fa icon="eye" class="fa-fw" /> <fa icon="eye" class="fa-fw" />
</button> </button>
<button <button
v-else-if="!contact?.seesMe && contact?.did !== activeDid" v-else-if="
!contactFromDid?.seesMe && contactFromDid?.did !== activeDid
"
class="text-sm uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white mx-0.5 my-0.5 px-2 py-1.5 rounded-md" class="text-sm uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white mx-0.5 my-0.5 px-2 py-1.5 rounded-md"
@click="confirmSetVisibility(contact, true)" @click="confirmSetVisibility(contactFromDid, true)"
title="They cannot see you" title="They cannot see you"
> >
<fa icon="eye-slash" class="fa-fw" /> <fa icon="eye-slash" class="fa-fw" />
</button> </button>
<!-- otherwise it's this user so hide it -->
<fa v-else icon="eye" class="text-white mx-2.5" />
<button <button
class="text-sm uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white mx-0.5 my-0.5 px-2 py-1.5 rounded-md" class="text-sm uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white mx-0.5 my-0.5 px-2 py-1.5 rounded-md"
@click="checkVisibility(contact)" @click="checkVisibility(contactFromDid)"
title="Check Visibility" title="Check Visibility"
v-if="contact?.did !== activeDid" v-if="contactFromDid?.did !== activeDid"
> >
<fa icon="rotate" class="fa-fw" /> <fa icon="rotate" class="fa-fw" />
</button> </button>
<!-- otherwise it's this user so hide it -->
<fa v-else icon="rotate" class="text-white mx-2.5" />
</div> </div>
<button <button
@click="confirmRegister(contact)" @click="confirmRegister(contactFromDid)"
class="text-sm uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white ml-6 mx-0.5 my-0.5 px-2 py-1.5 rounded-md" class="text-sm uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white ml-6 mx-0.5 my-0.5 px-2 py-1.5 rounded-md"
v-if="contact?.did !== activeDid" v-if="contactFromDid?.did !== activeDid"
title="Registration" title="Registration"
> >
<fa <fa
v-if="contact?.registered" v-if="contactFromDid?.registered"
icon="person-circle-check" icon="person-circle-check"
class="fa-fw" class="fa-fw"
/> />
<fa v-else icon="person-circle-question" class="fa-fw" /> <fa v-else icon="person-circle-question" class="fa-fw" />
</button> </button>
<!-- otherwise it's this user so hide it -->
<fa v-else icon="rotate" class="text-white ml-6 px-2.5" />
</div> </div>
<button <button
@click="confirmDeleteContact(contact)" @click="confirmDeleteContact(contactFromDid)"
class="text-sm uppercase bg-gradient-to-b from-rose-500 to-rose-800 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white ml-6 mx-0.5 my-0.5 px-2 py-1.5 rounded-md" class="text-sm uppercase bg-gradient-to-b from-rose-500 to-rose-800 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white ml-6 mx-0.5 my-0.5 px-2 py-1.5 rounded-md"
title="Delete" title="Delete"
> >
<fa icon="trash-can" class="fa-fw" /> <fa icon="trash-can" class="fa-fw" />
</button> </button>
</div> </div>
<div v-if="!contact?.profileImageUrl"> <div v-if="!contactFromDid?.profileImageUrl">
<div>Auto-Generated Icon</div> <div>Auto-Generated Icon</div>
<div class="flex justify-center"> <div class="flex justify-center">
<EntityIcon <EntityIcon
@@ -150,6 +154,16 @@
</div> </div>
</div> </div>
</div> </div>
<div v-else class="bg-slate-100 rounded-md overflow-hidden px-4 py-3 mb-4">
<!-- !contactFromDid -->
<div>
<h2 class="text-xl font-semibold">
{{ isMyDid ? "You" : "(no name)" }}
</h2>
</div>
</div>
<!-- Edit Name Dialog, maybe should be replaced by ContactNameDialog -->
<div v-if="contactEdit" class="dialog-overlay"> <div v-if="contactEdit" class="dialog-overlay">
<div class="dialog"> <div class="dialog">
<h1 class="text-xl font-bold text-center mb-4">Edit Name</h1> <h1 class="text-xl font-bold text-center mb-4">Edit Name</h1>
@@ -186,7 +200,9 @@
</div> </div>
<!-- Results List --> <!-- Results List -->
<div v-if="claims.length > 0" class="mt-4"> <div v-if="claims.length > 0" class="mt-4">
<div class="text-l font-bold text-center">Claims That Involve Them</div> <div class="text-l font-bold text-center">
Claims That Involve {{ isMyDid ? "You" : "Them" }}
</div>
</div> </div>
<InfiniteScroll @reached-bottom="loadMoreData"> <InfiniteScroll @reached-bottom="loadMoreData">
<ul> <ul>
@@ -222,7 +238,8 @@
v-if="!isLoading && claims.length === 0" v-if="!isLoading && claims.length === 0"
class="flex justify-center mt-4" class="flex justify-center mt-4"
> >
<span>They are in no claims visible to you.</span> <span v-if="isMyDid">You have no claims yet.</span>
<span v-else>They are in no claims visible to you.</span>
</div> </div>
</section> </section>
</template> </template>
@@ -237,9 +254,9 @@ import QuickNav from "@/components/QuickNav.vue";
import InfiniteScroll from "@/components/InfiniteScroll.vue"; import InfiniteScroll from "@/components/InfiniteScroll.vue";
import TopMessage from "@/components/TopMessage.vue"; import TopMessage from "@/components/TopMessage.vue";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import { BoundingBox, MASTER_SETTINGS_KEY } from "@/db/tables/settings"; import { BoundingBox } from "@/db/tables/settings";
import { import {
capitalizeAndInsertSpacesBeforeCaps, capitalizeAndInsertSpacesBeforeCaps,
didInfoForContact, didInfoForContact,
@@ -270,15 +287,15 @@ export default class DIDView extends Vue {
yaml = yaml; yaml = yaml;
activeDid = ""; activeDid = "";
allMyDids: Array<string> = [];
apiServer = ""; apiServer = "";
claims: Array<GenericCredWrapper<GenericVerifiableCredential>> = []; claims: Array<GenericCredWrapper<GenericVerifiableCredential>> = [];
contact: Contact; contactFromDid?: Contact;
contactEdit = false; contactEdit = false;
contactNewName?: string; contactNewName: string = "";
contactYaml = ""; contactYaml = "";
hitEnd = false; hitEnd = false;
isLoading = false; isLoading = false;
isMyDid = false;
searchBox: { name: string; bbox: BoundingBox } | null = null; searchBox: { name: string; bbox: BoundingBox } | null = null;
showDidDetails = false; showDidDetails = false;
showLargeIdenticonId?: string; showLargeIdenticonId?: string;
@@ -290,38 +307,28 @@ export default class DIDView extends Vue {
displayAmount = displayAmount; displayAmount = displayAmount;
async mounted() { async mounted() {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); this.activeDid = settings.activeDid || "";
this.activeDid = (settings?.activeDid as string) || ""; this.apiServer = settings.apiServer || "";
this.apiServer = (settings?.apiServer as string) || "";
const pathParam = window.location.pathname.substring("/did/".length); const pathParam = window.location.pathname.substring("/did/".length);
let theContact: Contact | undefined;
if (pathParam) { if (pathParam) {
this.viewingDid = decodeURIComponent(pathParam); this.viewingDid = decodeURIComponent(pathParam);
theContact = await db.contacts.get(this.viewingDid); this.contactFromDid = await db.contacts.get(this.viewingDid);
} if (this.contactFromDid) {
if (theContact) { this.contactYaml = yaml.dump(this.contactFromDid);
this.contact = theContact; }
} else { await this.loadClaimsAbout();
this.$notify(
{
group: "alert",
type: "danger",
title: "Error",
text: "No valid claim ID was provided.",
},
-1,
);
return;
}
this.contactYaml = yaml.dump(this.contact); await accountsDB.open();
await this.loadClaimsAbout(); const allAccounts = await accountsDB.accounts.toArray();
for (const account of allAccounts) {
await accountsDB.open(); if (account.did === this.viewingDid) {
const allAccounts = await accountsDB.accounts.toArray(); this.isMyDid = true;
this.allMyDids = allAccounts.map((acc) => acc.did); break;
}
}
}
} }
/** /**
@@ -336,15 +343,20 @@ export default class DIDView extends Vue {
// prompt with confirmation if they want to delete a contact // prompt with confirmation if they want to delete a contact
confirmDeleteContact(contact: Contact) { confirmDeleteContact(contact: Contact) {
let message =
"Are you sure you want to remove " +
libsUtil.nameForContact(contact, false) +
" from your contact list?";
if (contact.seesMe) {
message +=
" Note that they can see your activity, so if you want to hide your activity from them then you should do that first.";
}
this.$notify( this.$notify(
{ {
group: "modal", group: "modal",
type: "confirm", type: "confirm",
title: "Delete", title: "Delete",
text: text: message,
"Are you sure you want to remove " +
libsUtil.nameForContact(contact, false) +
" from your contact list?",
onYes: async () => { onYes: async () => {
await this.deleteContact(contact); await this.deleteContact(contact);
}, },
@@ -377,7 +389,7 @@ export default class DIDView extends Vue {
title: "Register", title: "Register",
text: text:
"Are you sure you want to register " + "Are you sure you want to register " +
libsUtil.nameForContact(this.contact, false) + libsUtil.nameForContact(this.contactFromDid, false) +
(contact.registered (contact.registered
? " -- especially since they are already marked as registered" ? " -- especially since they are already marked as registered"
: "") + : "") +
@@ -430,7 +442,7 @@ export default class DIDView extends Vue {
} }
} catch (error) { } catch (error) {
console.error("Error when registering:", error); console.error("Error when registering:", error);
let userMessage = "There was an error. See logs for more info."; let userMessage = "There was an error.";
const serverError = error as AxiosError; const serverError = error as AxiosError;
if (serverError) { if (serverError) {
if (serverError.response?.data?.error?.message) { if (serverError.response?.data?.error?.message) {
@@ -558,9 +570,21 @@ export default class DIDView extends Vue {
} }
private async onClickSaveName(newName: string) { private async onClickSaveName(newName: string) {
this.contact.name = newName; if (!this.contactFromDid) {
this.$notify(
{
group: "alert",
type: "danger",
title: "Not A Contact",
text: "First add this on the contact page, then you can edit here.",
},
5000,
);
return;
}
this.contactFromDid.name = newName;
return db.contacts return db.contacts
.update(this.contact.did, { name: newName }) .update(this.contactFromDid.did, { name: newName })
.then(() => (this.contactEdit = false)); .then(() => (this.contactEdit = false));
} }

View File

@@ -1,16 +1,22 @@
<template> <template>
<QuickNav selected="Discover"></QuickNav> <QuickNav selected="Discover" />
<TopMessage /> <TopMessage />
<!-- CONTENT --> <!-- CONTENT -->
<section id="Content" class="p-6 pb-24 max-w-3xl mx-auto"> <section id="Content" class="p-6 pb-24 max-w-3xl mx-auto">
<!-- Heading --> <!-- Heading -->
<h1 id="ViewHeading" class="text-4xl text-center font-light pt-4 mb-8"> <h1 id="ViewHeading" class="text-4xl text-center font-light">
Discover Projects Discover Projects
</h1> </h1>
<OnboardingDialog ref="onboardingDialog" />
<!-- Quick Search --> <!-- Quick Search -->
<div id="QuickSearch" class="mb-4 flex" v-on:keyup.enter="searchSelected()"> <div
id="QuickSearch"
class="mt-8 mb-4 flex"
v-on:keyup.enter="searchSelected()"
>
<input <input
type="text" type="text"
v-model="searchTerms" v-model="searchTerms"
@@ -72,11 +78,12 @@
</div> </div>
<div v-if="isLocalActive"> <div v-if="isLocalActive">
<div> <div class="text-center">
<button <button
class="ml-2 mt-2 px-4 py-2 rounded-md bg-blue-200 text-blue-500" class="ml-2 mt-2 px-4 py-2 rounded-md bg-blue-200 text-blue-500"
@click="$router.push({ name: 'search-area' })" @click="$router.push({ name: 'search-area' })"
> >
<fa icon="location-dot" class="fa-fw" />
Select a {{ searchBox ? "Different" : "" }} Location for Nearby Search Select a {{ searchBox ? "Different" : "" }} Location for Nearby Search
</button> </button>
</div> </div>
@@ -89,6 +96,15 @@
> >
<fa icon="spinner" class="fa-spin-pulse"></fa> <fa icon="spinner" class="fa-spin-pulse"></fa>
</div> </div>
<div v-else-if="projects.length === 0" class="text-center mt-8">
<p class="text-lg text-slate-500">
<span v-if="isLocalActive">
<span v-if="searchBox"> None found in the selected area. </span>
<!-- Otherwise there's no search area selected so we'll just leave the search box for them to click. -->
</span>
<span v-else>No projects were found with that search.</span>
</p>
</div>
<!-- Results List --> <!-- Results List -->
<InfiniteScroll @reached-bottom="loadMoreData"> <InfiniteScroll @reached-bottom="loadMoreData">
@@ -134,16 +150,19 @@ import { Router } from "vue-router";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import InfiniteScroll from "@/components/InfiniteScroll.vue"; import InfiniteScroll from "@/components/InfiniteScroll.vue";
import ProjectIcon from "@/components/ProjectIcon.vue"; import ProjectIcon from "@/components/ProjectIcon.vue";
import OnboardingDialog from "@/components/OnboardingDialog.vue";
import TopMessage from "@/components/TopMessage.vue"; import TopMessage from "@/components/TopMessage.vue";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import { BoundingBox, MASTER_SETTINGS_KEY } from "@/db/tables/settings"; import { BoundingBox } from "@/db/tables/settings";
import { didInfo, getHeaders, PlanData } from "@/libs/endorserServer"; import { didInfo, getHeaders, PlanData } from "@/libs/endorserServer";
import { OnboardPage } from "@/libs/util";
@Component({ @Component({
components: { components: {
InfiniteScroll, InfiniteScroll,
OnboardingDialog,
ProjectIcon, ProjectIcon,
QuickNav, QuickNav,
TopMessage, TopMessage,
@@ -169,11 +188,10 @@ export default class DiscoverView extends Vue {
didInfo = didInfo; didInfo = didInfo;
async mounted() { async mounted() {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); this.activeDid = (settings.activeDid as string) || "";
this.activeDid = (settings?.activeDid as string) || ""; this.apiServer = (settings.apiServer as string) || "";
this.apiServer = (settings?.apiServer as string) || ""; this.searchBox = settings.searchBoxes?.[0] || null;
this.searchBox = settings?.searchBoxes?.[0] || null;
this.allContacts = await db.contacts.toArray(); this.allContacts = await db.contacts.toArray();
@@ -181,6 +199,14 @@ export default class DiscoverView extends Vue {
const allAccounts = await accountsDB.accounts.toArray(); const allAccounts = await accountsDB.accounts.toArray();
this.allMyDids = allAccounts.map((acc) => acc.did); this.allMyDids = allAccounts.map((acc) => acc.did);
this.searchTerms = (this.$route as Router).query["searchText"] || "";
if (!settings.finishedOnboarding) {
(this.$refs.onboardingDialog as OnboardingDialog).open(
OnboardPage.Discover,
);
}
if (this.searchBox) { if (this.searchBox) {
await this.searchLocal(); await this.searchLocal();
} else { } else {
@@ -393,7 +419,6 @@ export default class DiscoverView extends Vue {
* @param id of the project * @param id of the project
**/ **/
onClickLoadProject(id: string) { onClickLoadProject(id: string) {
localStorage.setItem("projectId", id);
const route = { const route = {
path: "/project/" + encodeURIComponent(id), path: "/project/" + encodeURIComponent(id),
}; };

View File

@@ -21,12 +21,22 @@
<h1 class="text-4xl text-center font-light px-4 mb-4">What Was Given</h1> <h1 class="text-4xl text-center font-light px-4 mb-4">What Was Given</h1>
<h1 class="text-xl font-bold text-center mb-4"> <h1 class="text-xl font-bold text-center mb-4">
<span>From {{ giverName }}</span> <span>
From
{{
providedByProject
? providerProjectName
: providedByGiver
? giverName
: "someone not named"
}}
</span>
<br />
<span> <span>
to to
{{ {{
givenToProject givenToProject
? projectName ? fulfillsProjectName
: givenToRecipient : givenToRecipient
? recipientName ? recipientName
: "someone unidentified" : "someone unidentified"
@@ -64,7 +74,7 @@
</div> </div>
</div> </div>
<div class="flex justify-center mt-4" data-testid="imagery"> <div class="flex justify-center mt-4" data-testId="imagery">
<span v-if="imageUrl" class="flex justify-between"> <span v-if="imageUrl" class="flex justify-between">
<a :href="imageUrl" target="_blank"> <a :href="imageUrl" target="_blank">
<img :src="imageUrl" class="h-24 rounded-xl" /> <img :src="imageUrl" class="h-24 rounded-xl" />
@@ -87,7 +97,29 @@
<div class="h-7 mt-4 flex"> <div class="h-7 mt-4 flex">
<input <input
v-if="projectId && !givenToRecipient" v-if="providerProjectId && !providedByGiver"
type="checkbox"
class="h-6 w-6 mr-2"
v-model="providedByProject"
/>
<fa
v-else
icon="square"
class="bg-slate-500 text-slate-500 h-5 w-5 px-0.5 py-0.5 mr-2 rounded"
@click="notifyUserOfProvidingProject()"
/>
<label class="text-sm mt-1">
{{
providerProjectId
? "This was provided by " + providerProjectName
: "This was not provided by a project"
}}
</label>
</div>
<div class="h-7 mt-4 flex">
<input
v-if="fulfillsProjectId && !givenToRecipient"
type="checkbox" type="checkbox"
class="h-6 w-6 mr-2" class="h-6 w-6 mr-2"
v-model="givenToProject" v-model="givenToProject"
@@ -96,13 +128,13 @@
v-else v-else
icon="square" icon="square"
class="bg-slate-500 text-slate-500 h-5 w-5 px-0.5 py-0.5 mr-2 rounded" class="bg-slate-500 text-slate-500 h-5 w-5 px-0.5 py-0.5 mr-2 rounded"
@click="notifyUserOfProject()" @click="notifyUserFulfillsProject()"
/> />
<label class="text-sm mt-1"> <label class="text-sm mt-1">
{{ {{
projectId fulfillsProjectId
? "This was given to " + projectName ? "This was given to " + fulfillsProjectName
: "No project was chosen" : "No recipient project was chosen"
}} }}
</label> </label>
</div> </div>
@@ -134,7 +166,7 @@
<label class="text-sm mt-1">This was a trade (not a gift)</label> <label class="text-sm mt-1">This was a trade (not a gift)</label>
</div> </div>
<div class="mt-4 flex"> <div v-if="showGeneralAdvanced" class="mt-4 flex">
<router-link <router-link
:to="{ :to="{
name: 'claim-add-raw', name: 'claim-add-raw',
@@ -181,8 +213,7 @@ import ImageMethodDialog from "@/components/ImageMethodDialog.vue";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import TopMessage from "@/components/TopMessage.vue"; import TopMessage from "@/components/TopMessage.vue";
import { DEFAULT_IMAGE_API_SERVER, NotificationIface } from "@/constants/app"; import { DEFAULT_IMAGE_API_SERVER, NotificationIface } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
import { import {
createAndSubmitGive, createAndSubmitGive,
didInfo, didInfo,
@@ -212,8 +243,10 @@ export default class GiftedDetails extends Vue {
amountInput = "0"; amountInput = "0";
description = ""; description = "";
destinationPathAfter = ""; destinationPathAfter = "";
givenToProject = false; fulfillsProjectId = "";
givenToRecipient = false; fulfillsProjectName = "a project";
givenToProject = false; // basically static, based on input; if we allow changing then let's fix things (see below)
givenToRecipient = false; // basically static, based on input; if we allow changing then let's fix things (see below)
giverDid: string | undefined; giverDid: string | undefined;
giverName = ""; giverName = "";
hideBackButton = false; hideBackButton = false;
@@ -222,10 +255,13 @@ export default class GiftedDetails extends Vue {
message = ""; message = "";
offerId = ""; offerId = "";
prevCredToEdit?: GenericCredWrapper<GiveVerifiableCredential>; prevCredToEdit?: GenericCredWrapper<GiveVerifiableCredential>;
projectId = ""; providerProjectId = "";
projectName = "a project"; providerProjectName = "a project";
providedByProject = false; // basically static, based on input; if we allow changing then let's fix things (see below)
providedByGiver = false; // basically static, based on input; if we allow changing then let's fix things (see below)
recipientDid = ""; recipientDid = "";
recipientName = ""; recipientName = "";
showGeneralAdvanced = false;
unitCode = "HUR"; unitCode = "HUR";
libsUtil = libsUtil; libsUtil = libsUtil;
@@ -282,11 +318,31 @@ export default class GiftedDetails extends Vue {
offer?.identifier || offer?.identifier ||
this.offerId) as string; this.offerId) as string;
// find any project ID // find any fulfills project ID
const project = fulfillsArray.find((rec) => rec["@type"] === "PlanAction"); const fulfillsProject = fulfillsArray.find(
this.projectId = ((this.$route as Router).query["projectId"] || (rec) => rec["@type"] === "PlanAction",
project?.identifier || );
this.projectId) as string; // eslint-disable-next-line prettier/prettier
this.fulfillsProjectId =
((this.$route as Router).query["fulfillsProjectId"] ||
fulfillsProject?.identifier ||
this.fulfillsProjectId) as string;
// find any provider project ID
const provider = this.prevCredToEdit?.claim?.provider;
const providerArray = Array.isArray(provider)
? provider
: provider
? [provider]
: [];
const providerProject = providerArray.find(
(rec) => rec["@type"] === "PlanAction",
);
this.providerProjectId = ((this.$route as Router).query[
"providerProjectId"
] ||
providerProject?.identifier ||
this.providerProjectId) as string;
this.recipientDid = ((this.$route as Router).query["recipientDid"] || this.recipientDid = ((this.$route as Router).query["recipientDid"] ||
this.prevCredToEdit?.claim?.recipient?.identifier) as string; this.prevCredToEdit?.claim?.recipient?.identifier) as string;
@@ -318,68 +374,70 @@ export default class GiftedDetails extends Vue {
this.imageUrl = (this.$route as Router).query["shareUrl"] as string; this.imageUrl = (this.$route as Router).query["shareUrl"] as string;
} }
try { const settings = await retrieveSettingsForActiveAccount();
await db.open(); this.apiServer = settings.apiServer || "";
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; this.activeDid = settings.activeDid || "";
this.apiServer = settings?.apiServer || "";
this.activeDid = settings?.activeDid || "";
let allContacts: Contact[] = []; let allContacts: Contact[] = [];
let allMyDids: string[] = []; let allMyDids: string[] = [];
if ( if (
(this.giverDid && !this.giverName) || (this.giverDid && !this.giverName) ||
(this.recipientDid && !this.recipientName) (this.recipientDid && !this.recipientName)
) { ) {
allContacts = await db.contacts.toArray(); allContacts = await db.contacts.toArray();
await accountsDB.open(); await accountsDB.open();
const allAccounts = await accountsDB.accounts.toArray(); const allAccounts = await accountsDB.accounts.toArray();
allMyDids = allAccounts.map((acc) => acc.did); allMyDids = allAccounts.map((acc) => acc.did);
if (this.giverDid && !this.giverName) { if (this.giverDid && !this.giverName) {
this.giverName = didInfo( this.giverName = didInfo(
this.giverDid, this.giverDid,
this.activeDid, this.activeDid,
allMyDids, allMyDids,
allContacts, allContacts,
); );
} }
if (this.recipientDid && !this.recipientName) { if (this.recipientDid && !this.recipientName) {
this.recipientName = didInfo( this.recipientName = didInfo(
this.recipientDid, this.recipientDid,
this.activeDid, this.activeDid,
allMyDids, allMyDids,
allContacts, allContacts,
); );
}
} }
// these should be functions but something's wrong with the syntax in the <> conditional
this.givenToProject = !!this.projectId;
this.givenToRecipient = !this.givenToProject && !!this.recipientDid;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
console.error("Error retrieving settings from database:", err);
this.$notify(
{
group: "alert",
type: "danger",
title: "Error",
text: err.message || "There was an error retrieving your settings.",
},
-1,
);
} }
// these should be functions but something's wrong with the syntax in the <> conditional
this.givenToProject = !!this.fulfillsProjectId;
this.givenToRecipient = !this.givenToProject && !!this.recipientDid;
if (this.projectId) { // these should be functions but something's wrong with the syntax in the <> conditional
// console.log("Getting project name from cache", this.projectId); this.providedByProject = !!this.providerProjectId;
const project = await getPlanFromCache( this.providedByGiver = !this.providedByProject && !!this.giverDid;
this.projectId,
this.showGeneralAdvanced = !!settings.showGeneralAdvanced;
if (this.fulfillsProjectId) {
// console.log("Getting project name from cache", this.fulfillsProjectId);
const fulfillsProject = await getPlanFromCache(
this.fulfillsProjectId,
this.axios, this.axios,
this.apiServer, this.apiServer,
this.activeDid, this.activeDid,
); );
this.projectName = project?.name this.fulfillsProjectName = fulfillsProject?.name
? "the project: " + project.name ? `the project "${fulfillsProject.name}"`
: "a project";
}
if (this.providerProjectId) {
// console.log("Getting project name from cache", this.providerProjectId);
const providerProject = await getPlanFromCache(
this.providerProjectId,
this.axios,
this.apiServer,
this.activeDid,
);
this.providerProjectName = providerProject?.name
? `the project "${providerProject.name}"`
: "a project"; : "a project";
} }
} }
@@ -470,7 +528,7 @@ export default class GiftedDetails extends Vue {
console.error("Error deleting image:", error); console.error("Error deleting image:", error);
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
if ((error as any).response.status === 404) { if ((error as any).response.status === 404) {
console.log("The image was already deleted:", error); console.log("Weird: the image was already deleted.", error);
localStorage.removeItem("imageUrl"); localStorage.removeItem("imageUrl");
this.imageUrl = ""; this.imageUrl = "";
@@ -544,8 +602,35 @@ export default class GiftedDetails extends Vue {
await this.recordGive(); await this.recordGive();
} }
notifyUserOfProject() { notifyUserOfProvidingProject() {
if (!this.projectId) { // we're here because they clicked and either there is no provider project or there is a giver chosen
if (!this.providerProjectId) {
this.$notify(
{
group: "alert",
type: "warning",
title: "Error",
text: "To select a project as a provider, you must open this page through a project.",
},
3000,
);
} else {
// no providing project was chosen
this.$notify(
{
group: "alert",
type: "warning",
title: "Error",
text: "You cannot select both a giving project and person.",
},
3000,
);
}
}
notifyUserFulfillsProject() {
// we're here because they clicked and either there is no fulfills project or there is a recipient chosen
if (!this.fulfillsProjectId) {
this.$notify( this.$notify(
{ {
group: "alert", group: "alert",
@@ -556,7 +641,7 @@ export default class GiftedDetails extends Vue {
3000, 3000,
); );
} else { } else {
// must be because givenToRecipient is true // no fulfills project was chosen
this.$notify( this.$notify(
{ {
group: "alert", group: "alert",
@@ -606,7 +691,9 @@ export default class GiftedDetails extends Vue {
const recipientDid = this.givenToRecipient const recipientDid = this.givenToRecipient
? this.recipientDid ? this.recipientDid
: undefined; : undefined;
const projectId = this.givenToProject ? this.projectId : undefined; const fulfillsProjectId = this.givenToProject
? this.fulfillsProjectId
: undefined;
let result; let result;
if (this.prevCredToEdit) { if (this.prevCredToEdit) {
// don't create from a blank one in case some properties were set from a different interface // don't create from a blank one in case some properties were set from a different interface
@@ -620,10 +707,11 @@ export default class GiftedDetails extends Vue {
this.description, this.description,
parseFloat(this.amountInput), parseFloat(this.amountInput),
this.unitCode, this.unitCode,
projectId, fulfillsProjectId,
this.offerId, this.offerId,
this.isTrade, this.isTrade,
this.imageUrl, this.imageUrl,
this.providerProjectId,
); );
} else { } else {
result = await createAndSubmitGive( result = await createAndSubmitGive(
@@ -635,10 +723,11 @@ export default class GiftedDetails extends Vue {
this.description, this.description,
parseFloat(this.amountInput), parseFloat(this.amountInput),
this.unitCode, this.unitCode,
projectId, fulfillsProjectId,
this.offerId, this.offerId,
this.isTrade, this.isTrade,
this.imageUrl, this.imageUrl,
this.providerProjectId,
); );
} }
@@ -695,7 +784,9 @@ export default class GiftedDetails extends Vue {
constructGiveParam() { constructGiveParam() {
const recipientDid = this.givenToRecipient ? this.recipientDid : undefined; const recipientDid = this.givenToRecipient ? this.recipientDid : undefined;
const projectId = this.givenToProject ? this.projectId : undefined; const fulfillsProjectId = this.givenToProject
? this.fulfillsProjectId
: undefined;
const giveClaim = hydrateGive( const giveClaim = hydrateGive(
this.prevCredToEdit?.claim as GiveVerifiableCredential, this.prevCredToEdit?.claim as GiveVerifiableCredential,
this.giverDid, this.giverDid,
@@ -703,10 +794,11 @@ export default class GiftedDetails extends Vue {
this.description, this.description,
parseFloat(this.amountInput), parseFloat(this.amountInput),
this.unitCode, this.unitCode,
projectId, fulfillsProjectId,
this.offerId, this.offerId,
this.isTrade, this.isTrade,
this.imageUrl, this.imageUrl,
this.providerProjectId,
this.prevCredToEdit?.id as string, this.prevCredToEdit?.id as string,
); );
const claimStr = JSON.stringify(giveClaim); const claimStr = JSON.stringify(giveClaim);

View File

@@ -0,0 +1,68 @@
<template>
<QuickNav />
<!-- CONTENT -->
<section id="Content" class="p-6 pb-24 max-w-3xl mx-auto">
<!-- Breadcrumb -->
<div class="mb-8">
<!-- Back -->
<div class="text-lg text-center font-light relative px-7">
<h1
class="text-lg text-center px-2 py-1 absolute -left-2 -top-1"
@click="$router.back()"
>
<fa icon="chevron-left" class="fa-fw"></fa>
</h1>
</div>
<!-- Heading -->
<h1 id="ViewHeading" class="text-4xl text-center font-light pt-4 mb-8">
Notification Types
</h1>
</div>
<!-- eslint-disable prettier/prettier -->
<div>
<p>There are two types of notifications:</p>
<h2 class="text-xl font-semibold mt-4">Reminder Notifications</h2>
<div>
<p>
The Reminder Notification will be sent to you daily with a specific message,
at whatever time you choose. Use it to remind
yourself to act, for example: pause and consider who has given you
something, so you can record thanks in here.
</p>
<p>
This is a reliable message, but it doesn't contain any details about
activity that might be especially interesting to you.
</p>
</div>
<h2 class="text-xl font-semibold mt-4">New Activity Notifications</h2>
<div>
<p>
The New Activity Notification will be sent to you when there is new, relevant activity for you.
It will only trigger if something involves you or a project of interest; it will not
bug you for other, general activity.
</p>
<p>
This type is not as reliable as a Reminder Notification because mobile devices often suppress
such notifications to save battery. (We are working on other ways to notify you more
reliably. If you want to quickly check for relevant activity daily, use the Reminder
Notification and open the app and look for a large green button that points out new
activity that is personal to you.)
</p>
</div>
</div>
<!-- eslint-enable -->
</section>
</template>
<script lang="ts">
import { Component, Vue } from "vue-facing-decorator";
import QuickNav from "@/components/QuickNav.vue";
@Component({ components: { QuickNav } })
export default class HelpNotificationTypesView extends Vue {}
</script>

View File

@@ -39,6 +39,15 @@
</p> </p>
</div> </div>
<h2 class="text-xl font-semibold mt-4">Android Users</h2>
<div>
<p>
Note that you may not receive notifications when the app is in the
background. When you're done working, close the app, and then you'll
get the reminder notifications.
</p>
</div>
<h2 class="text-xl font-semibold mt-4"> <h2 class="text-xl font-semibold mt-4">
If this app doesn't support notifications... If this app doesn't support notifications...
<!-- Note that that exact verbiage shows in a message elsewhere. --> <!-- Note that that exact verbiage shows in a message elsewhere. -->
@@ -305,8 +314,8 @@ export default class HelpNotificationsView extends Vue {
async mounted() { async mounted() {
try { try {
const registration = await navigator.serviceWorker.ready; const registration = await navigator.serviceWorker?.ready;
const fullSub = await registration.pushManager.getSubscription(); const fullSub = await registration?.pushManager.getSubscription();
this.subscriptionJSON = fullSub?.toJSON(); this.subscriptionJSON = fullSub?.toJSON();
} catch (error) { } catch (error) {
console.error("Mount error:", error); console.error("Mount error:", error);
@@ -366,7 +375,7 @@ export default class HelpNotificationsView extends Vue {
showTestNotification() { showTestNotification() {
const TEST_NOTIFICATION_TITLE = "It Worked"; const TEST_NOTIFICATION_TITLE = "It Worked";
navigator.serviceWorker.ready navigator.serviceWorker?.ready
.then((registration) => { .then((registration) => {
return registration.showNotification(TEST_NOTIFICATION_TITLE, { return registration.showNotification(TEST_NOTIFICATION_TITLE, {
body: "This is your test notification.", body: "This is your test notification.",

View File

@@ -12,45 +12,91 @@
</h1> </h1>
</div> </div>
<!-- eslint-disable prettier/prettier --> <p>
To invite someone the easiest way, send them a link that you generate from
this page:
<router-link
:to="{ name: 'invite-one' }"
class="bg-gradient-to-b from-green-400 to-green-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md"
>
<fa icon="envelope-open-text" class="fa-fw text-xl"
/></router-link>
</p>
<p>Then watch that page to see when they accept their invite.</p>
<p>
(That page is also reachable from the Contacts <fa icon="users" /> page
though the invitation <fa icon="envelope-open-text" /> icon.)
</p>
<h1 class="mt-4 font-bold text-xl">Next Steps</h1>
Although not totally necessary, backups are important to understand.
<div class="ml-4"> <div class="ml-4">
<h1 class="font-bold text-xl">Install</h1> <h1 class="font-bold text-xl">Without a backup, you can lose data.</h1>
<div> <div>
<p> <p>
1) Have them visit TimeSafari.app in a browser, preferably Chrome or Safari. Exporting backups (from the Account <fa icon="circle-user" /> screen)
is important for the case where they lose their device. This is
especially true for the Identifier Seed: that is theirs and and theirs
alone, and currently nobody else can recover it if they lose it. The
good thing is that anyone can create a new account and simply inform
their network of their new ID.
</p>
</div>
</div>
<h1 class="mt-4 font-bold text-xl">Advanced</h1>
The following are optional steps for even more functionality.
<!-- eslint-disable prettier/prettier -->
<div class="ml-4">
<h1 class="font-bold text-xl">Add Contact & Register</h1>
<p>
You share even more information such as your picture and name when
you share with your QR code at these links: <fa icon="qrcode" />
</p>
<p>
Scanning
those with your cameras will automatically register people and add them
to each other's contact lists.
</p>
<p>
The following are more detailed manual steps:
</p>
<div>
<p>
1) Have them follow their yellow prompts.
</p> </p>
<p> <p>
2) Have them "Install" the site to their desktop. 2) Scan their QR, or have them tap on it to copy their info and send it to you.
Then you can add them to your Contacts <fa icon="users" />
</p>
<p>
3) You can register them at their info page <fa icon="circle-info" />
and click on the register button <fa icon="person-circle-question" />
</p>
<p>
4) Add yourself to their Contacts <fa icon="users" />
</p> </p>
</div> </div>
<h1 class="font-bold text-xl">Add Contact & Register</h1> <h1 class="font-bold text-xl">Install</h1>
<div> <div>
<p> <p>
3) Have them follow their yellow prompts. Have them visit TimeSafari.app in a browser, preferably Chrome or Safari,
</p> and then look for the "Install" selection which adds this app to their desktop.
<p> This enables other things, like the ability to "share" a photo from their
4) Add them to your contacts <fa icon="users" /> device directly to Time Safari, and it makes notifications more reliable.
</p>
<p>
5) Register them <fa icon="person-circle-question" />
</p>
<p>
6) Add yourself to their contacts <fa icon="users" />
</p> </p>
</div> </div>
<h1 class="font-bold text-xl">Enable Notifications</h1> <h1 class="font-bold text-xl">Enable Notifications</h1>
<div> <div>
<p> <p>
7) Enable notifications from <fa icon="circle-user" /> Enable notifications from the Account page <fa icon="circle-user" />.
</p> Those notifications might show up on the device depending on your settings.
</div> For the most reliable habits, people should own alarm or some other ritual to look every day.
<h1 class="font-bold text-xl">Discuss Backups</h1>
<div>
<p>
8) Exporting backups <fa icon="circle-user" /> are important if they lose their phone --- especially for the Identifier Seed!
</p> </p>
</div> </div>

View File

@@ -21,53 +21,192 @@
</h1> </h1>
</div> </div>
<!-- eslint-disable prettier/prettier --> <!-- eslint-disable prettier/prettier max-len -->
<div> <div>
<p> <p>
This app focuses on gifts & gratitude, using them to build cool things with your network. This app focuses on gifts & gratitude, using them to build cool things together with your network.
</p>
<p class="ml-4">
If you'd like to see the page-by-page help,
<span
@click="unsetFinishedOnboarding()"
class="text-blue-500 cursor-pointer"
>click here</span>.
</p> </p>
<h2 class="text-xl font-semibold">What is the idea here?</h2> <h2 class="text-xl font-semibold">What is the idea here?</h2>
<p> <p>
We are building networks of people who want to grow a giving society. We are building networks of people who want to grow good society from the ground up, using modern
First of all, let's build gratitude: see what people have given, and recognize technology that connects people peer-to-peer.
First of all, let's showcase gratitude: see what people have given, and recognize
gifts you've seen. This is done in a way that leaves a permanent record -- one that gifts you've seen. This is done in a way that leaves a permanent record -- one that
came from you, and one that the recipient can prove it was for them. This is came from you, and one that the recipient can prove it was for them. This can be
personally gratifying, but it extends to broader work: volunteers get personally gratifying, but it extends to broader work: volunteers get
confirmation of activity, and selectively show off their contributions confirmation of activity, and they can selectively show off their contributions
and network. and network.
</p> </p>
<p> <p class="mt-2">
With this, you highlight giving and also offer help -- With this, you highlight giving and you also offer help --
which could be conditional on others' willingness to help, too. which could be conditional on others' contributions, too.
You can record your own ideas and invite others to collaborate. You can record your own ideas and invite others to collaborate.
It's a way to organize & build with the resource that everyone has in equal amounts: time.
</p> </p>
<p> <p class="mt-2">
This app uses the power of cryptography to build a reputation, recording Note that your personal data is safe: your ID is only shared with those you allow. Neither
activity that you can share at your discretion. You put some activity your name nor your contacts' names are shared with anyone -- even our servers --
public, but these services don't share your ID with others without explicit consent. though you can explicitly share it with other individuals if you choose.
This is in contrast to Meta and Google, who hold
your data and allow you use it while they manage sharing...
those services are useful but they have the control, whereas this app gives you the control.
</p> </p>
<h2 class="text-xl font-semibold">I want to know more because...</h2>
<ul class="list-disc list-outside ml-4">
<li class="p-2">
<div @click="showAlpha = !showAlpha" class="text-blue-500">... I'm a member of Alpha chat.</div>
<div v-if="showAlpha">
<p>
This is a project for public benefit. You are invited to add your gratitude
and propose projects on a distributable ledger.
</p>
<p>
The underlying data is on a merkle tree with each verifiable claim, signature and all.
The chain includes individual IDs for discovery & visibility, so not all data is distributed -- yet.
The goal is to eventually distribute the data on people's devices with their chosen network,
where anyone could host their own chain of provenance if they choose.
The formats follow standard schemas (eg. schema.org) to encourage interoperability.
We're currently at the beginning phase where we're trusting the server to keep IDs private.
It's all open-source, and we expect to have a professional audit someday.
</p>
<p>
A person's network of contacts is similar: the server currently knows some of the links between people
to allow discovery and visibility. However, even that will be manageable on personal devices someday.
</p>
<p>
There are no tokens to maintain the chain: the purpose is to create software that communities
and activists can easily join and use. We're betting that this is a case where network
participants have the motivation to run the software. The protocol is meant to be lightweight enough that
non-technical people can run it on inexpensive devices they already own. There may be cases for
MPC or ZKP in the future when they are more widespread and standard,
but our preference is to engineer as simply as possible with "white-magic" cryptography
over those "black-magic" functions.
</p>
<p>
Let's make real distributed computing and shared data happen, starting with our own small networks.
</p>
<p>
... and exemplify the fun along the way.
</p>
</div>
</li>
<li class="p-2">
<div @click="showGroup = !showGroup" class="text-blue-500">... I want to find a group I'll enjoy working with.</div>
<div v-if="showGroup">
<p>
This app encourages people to offer small bits of time to one another. It's a way to
run experiments with other people... tests of working together, which can start small
and easy but build into cooperation with people who are like-minded and who work well together.
</p>
<p>
Search the projects and place an offer on an interesting one
-- or create your own project and see who offers to help.
After your first experiment, you can give and get confirmation about the work, which you might choose
to show to future contacts.
</p>
</div>
</li>
<li class="p-2">
<div @click="showCommunity = !showCommunity" class="text-blue-500">... I want to participate in community projects.</div>
<div v-if="showCommunity">
<p>
These are mostly at the beginning stages, so any of them will appreciate your offers that show interest.
In fact, your offers can include your preferences, which give the project owners indications of how to proceed.
</p>
<p>
Search through the projects for issues of interest, locally as well as globally.
If you don't see any projects that interest you, create your own and see what kind of offers you get.
</p>
</div>
</li>
<li class="p-2">
<div @click="showVerifiable = !showVerifiable" class="text-blue-500">... I want to build with verifiable, private data.</div>
<div v-if="showVerifiable">
<p>
Make your claims and get others to confirm them. Then you can use the API to pull your copy of all that
data, both claims from you and claims from others about you. These are hard-and-fast credentials that can
be shown to others, along with their verifiable time and signature.
</p>
<p>
Furthermore, you can use your network to verify claims by other people, even if they haven't given you
visibility. First, on the claim screen you can see if the server detects anyone who is a direct link
between you, so you can reach out to those in-between people for more info. If there isn't anyone
who is directly in between then you can reach out with a message to your network.
</p>
<p>
This app generated an identifier, based on public & private keys located on your device.
That ID is only shared with our server and with people you explicitly allow.
The other information -- like gratitude and contributions and projects --
are published to a server that protects your ID. (Someday, your devices
will share directly P2P and not need a server... you can choose your levels
of discovery and privacy.) What this means is that you are in charge of your
network, and we provide tools and reporting to help you connect with your network for
references and reputation.
</p>
</div>
</li>
<li class="p-2">
<div @click="showGovernance = !showGovernance" class="text-blue-500">... I want to build governance organically.</div>
<div v-if="showGovernance">
<p>
This requires motivated, dedicated citizens. The good thing is that dedication the primary ingredient;
add coordination and we can find ways to replace monopolistic systems.
</p>
<p>
Add projects for your main areas of interest, and offer commitments to projects to kick-start some initiatives.
</p>
<p>
One other feature worth emphasizing: you build a history of credentials, ones that are verifiably
yours. But one other good thing is that you get support from those who confirm your activity.
You can share this support in a way that others can validate the data for themselves from people
in their own network. This kind of reputable project and history of performance is good evidence
for your ability to take responsibility for important initiatives.
</p>
</div>
</li>
<li class="p-2">
<div @click="showBasics = !showBasics" class="text-blue-500">... I want to supply life's basics freely.</div>
<div v-if="showBasics">
<p>
This platform is not optimal for balancing needs and resources at this point,
but we continuously seek out and list
those kinds of projects. Watch our blog, and watch the project list for words like
<router-link class="text-blue-500" to="/discover?searchText=sharing">"sharing"</router-link>
or
<router-link class="text-blue-500" to="/discover?searchText=basic">"basic"</router-link>
or
<router-link class="text-blue-500" to="/discover?searchText=free">"free"</router-link>.
</p>
</div>
</li>
</ul>
<h2 class="text-xl font-semibold">How do I get started?</h2> <h2 class="text-xl font-semibold">How do I get started?</h2>
<p> <p>
You need someone to register you, like the person who told you Someone -- like the person who told you about this app -- needs to register you
about this app, on the Contacts <fa icon="users" class="fa-fw" /> page. on the Contacts <fa icon="users" class="fa-fw" /> page.
If you heard about this from our outreach, feel free to contact us (below) for a chat. If you heard about this from our outreach, feel free to contact us (below) for a chat.
After someone registers you, you can After someone registers you, you can register others.
select any contact on the home page (or "anonymous") and record your
appreciation for... whatever. The main goal is to record what people
have given you, to grow giving economies. You can also record your own
ideas for projects. Each claim is recorded on a
custom ledger. The day after being registered, you'll be able to able to
register others, too.
</p> </p>
<p> <p>
Then you can record your appreciation for... whatever: select any contact on the home page
(or "Unnamed") and send it. The main goal is to record what people
have given you, to grow giving economies. You can also record your own
ideas for projects. Each claim is recorded on a
custom ledger.
</p>
<p>
The day after being registered, you'll be able to able to register others, too.
Note that there are limits to how many others you can register. Note that there are limits to how many others you can register.
Take your time to bring people on... make it an opportunity to get to Take your time to bring people on... make it an opportunity to get to
know their projects, and to show your own. know their projects, and to show off your own.
</p> </p>
<h2 class="text-xl font-semibold">How do I add someone else?</h2> <h2 class="text-xl font-semibold">How do I add someone else?</h2>
@@ -95,7 +234,7 @@
<h2 class="text-xl font-semibold">How do I backup all my data?</h2> <h2 class="text-xl font-semibold">How do I backup all my data?</h2>
<p> <p>
There are four sets of data to backup: the identifier secrets; There are four sets of data to backup: the identifier secrets;
the private text data that isn't quite as secret such as settings and contacts; the private text data that isn't as sensitive such as settings and contacts;
the private image for yourself; and the data that you have sent to the public. the private image for yourself; and the data that you have sent to the public.
</p> </p>
@@ -185,15 +324,14 @@
<h2 class="text-xl font-semibold">How do I create another identity?</h2> <h2 class="text-xl font-semibold">How do I create another identity?</h2>
<p> <p>
Before doing this, note that it is an advanced feature that affects Before doing this, beware that it is an advanced feature that affects
functionality (eg. the words "Alt ID" next to results, backup features) functionality (eg. the words "Alt ID" next to results, backup features). You can
so beware. You can
<router-link to="start" class="text-blue-500"> <router-link to="start" class="text-blue-500">
create another identity here. create another identity here.
</router-link> </router-link>
</p> </p>
<h2 class="text-xl font-semibold">How do I erase my data?</h2> <h2 class="text-xl font-semibold">How do I erase my data from my device?</h2>
<p> <p>
Before doing this, you may want to back up your data with the instructions above. Before doing this, you may want to back up your data with the instructions above.
</p> </p>
@@ -249,7 +387,7 @@
<fa icon="circle-user" /> page. <fa icon="circle-user" /> page.
</p> </p>
<p> <p>
There is a even more functionality in a mobile app (and more There is even more functionality in a mobile app (and more
documentation) at documentation) at
<a href="https://endorser.ch" target="_blank" class="text-blue-500"> <a href="https://endorser.ch" target="_blank" class="text-blue-500">
EndorserSearch.com EndorserSearch.com
@@ -385,6 +523,8 @@
<fa v-show="!showDidCopy" icon="copy" class="text-slate-400 fa-fw" /> <fa v-show="!showDidCopy" icon="copy" class="text-slate-400 fa-fw" />
</button> </button>
<span v-show="showDidCopy" class="ml-2 text-sm text-green-500">Copied</span> <span v-show="showDidCopy" class="ml-2 text-sm text-green-500">Copied</span>
You can donate online via
<a href="https://www.patreon.com/TimeSafari" target="_blank" class="text-blue-500">Patreon here</a>.
For other donations, contact us. For other donations, contact us.
</p> </p>
@@ -401,7 +541,7 @@
<p>{{ package.version }} ({{ commitHash }})</p> <p>{{ package.version }} ({{ commitHash }})</p>
<h2 class="text-xl font-semibold"> <h2 class="text-xl font-semibold">
For any other questions, like getting a new account or removing all your data from the public ledger: I have other questions, like getting a new account or removing all my data from the public ledger.
</h2> </h2>
<p> <p>
Contact us at Contact us at
@@ -416,11 +556,16 @@
<script lang="ts"> <script lang="ts">
import { Component, Vue } from "vue-facing-decorator"; import { Component, Vue } from "vue-facing-decorator";
import { Router } from "vue-router";
import { useClipboard } from "@vueuse/core"; import { useClipboard } from "@vueuse/core";
import * as Package from "../../package.json"; import * as Package from "../../package.json";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import {
retrieveSettingsForActiveAccount,
updateAccountSettings,
} from "@/db/index";
@Component({ components: { QuickNav } }) @Component({ components: { QuickNav } })
export default class Help extends Vue { export default class Help extends Vue {
@@ -428,7 +573,13 @@ export default class Help extends Vue {
package = Package; package = Package;
commitHash = import.meta.env.VITE_GIT_HASH; commitHash = import.meta.env.VITE_GIT_HASH;
showAlpha = false;
showBasics = false;
showCommunity = false;
showGovernance = false;
showGroup = false;
showDidCopy = false; showDidCopy = false;
showVerifiable = false;
// call fn, copy text to the clipboard, then redo fn after 2 seconds // call fn, copy text to the clipboard, then redo fn after 2 seconds
doCopyTwoSecRedo(text: string, fn: () => void) { doCopyTwoSecRedo(text: string, fn: () => void) {
@@ -437,5 +588,15 @@ export default class Help extends Vue {
.copy(text) .copy(text)
.then(() => setTimeout(fn, 2000)); .then(() => setTimeout(fn, 2000));
} }
async unsetFinishedOnboarding() {
const settings = await retrieveSettingsForActiveAccount();
if (settings.activeDid) {
await updateAccountSettings(settings.activeDid || "", {
finishedOnboarding: false,
});
}
(this.$router as Router).push({ name: "home" });
}
} }
</script> </script>

View File

@@ -4,14 +4,16 @@
<!-- CONTENT --> <!-- CONTENT -->
<section id="Content" class="p-2 pb-24 max-w-3xl mx-auto"> <section id="Content" class="p-2 pb-24 max-w-3xl mx-auto">
<h1 id="ViewHeading" class="text-4xl text-center font-light px-4 mb-8"> <h1 id="ViewHeading" class="text-4xl text-center font-light mb-8">
{{ AppString.APP_NAME }} {{ AppString.APP_NAME }}
</h1> </h1>
<!-- prompt to install notifications --> <OnboardingDialog ref="onboardingDialog" />
<div class="mb-8">
<!-- prompt to install notifications with notificationsSupported, which we're making an advanced feature -->
<div class="mb-8 mt-8">
<div <div
v-if="!notificationsSupported()" v-if="false"
class="bg-amber-200 rounded-md overflow-hidden text-center px-4 py-3 mb-4" class="bg-amber-200 rounded-md overflow-hidden text-center px-4 py-3 mb-4"
> >
<p style="display: inline; align-items: center"> <p style="display: inline; align-items: center">
@@ -84,15 +86,18 @@
id="noticeSomeoneMustRegisterYou" id="noticeSomeoneMustRegisterYou"
class="bg-amber-200 rounded-md overflow-hidden text-center px-4 py-3 mb-4" class="bg-amber-200 rounded-md overflow-hidden text-center px-4 py-3 mb-4"
> >
<!-- activeDid && !isRegistered --> <!-- !isCreatingIdentifier && !isRegistered -->
To share, someone must register you. To share, someone must register you.
<router-link <div class="block text-center">
:to="{ name: 'contact-qr' }" <button
class="block text-center text-md font-bold bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white mt-2 px-2 py-3 rounded-md" @click="showNameThenIdDialog()"
> class="text-md font-bold bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white mt-2 px-2 py-3 rounded-md"
Show Them {{ PASSKEYS_ENABLED ? "Default" : "Your" }} Identifier >
Info Show them {{ PASSKEYS_ENABLED ? "default" : "your" }} identifier
</router-link> info
</button>
</div>
<UserNameDialog ref="userNameDialog" />
<div v-if="PASSKEYS_ENABLED" class="flex justify-end w-full"> <div v-if="PASSKEYS_ENABLED" class="flex justify-end w-full">
<router-link <router-link
:to="{ name: 'start' }" :to="{ name: 'start' }"
@@ -104,15 +109,21 @@
</div> </div>
<div v-else id="sectionRecordSomethingGiven"> <div v-else id="sectionRecordSomethingGiven">
<!-- activeDid && isRegistered --> <!-- !isCreatingIdentifier && isRegistered -->
<!-- show the actions for recognizing a give --> <!-- show the actions for recognizing a give -->
<div class="mb-4"> <div class="flex">
<h2 class="text-xl font-bold">Record Something Given By:</h2> <h2 class="text-xl font-bold">What have you seen someone do?</h2>
<button
@click="openGiftedPrompts()"
class="ml-2 block text-xs text-center bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1 rounded-md"
>
<fa icon="lightbulb" class="fa-fw" />
</button>
</div> </div>
<ul <ul
class="grid grid-cols-4 sm:grid-cols-5 md:grid-cols-6 gap-x-3 gap-y-5 text-center mb-5" class="grid grid-cols-4 sm:grid-cols-5 md:grid-cols-6 gap-x-3 gap-y-5 text-center mt-4"
> >
<li @click="openDialog()"> <li @click="openDialog()">
<img <img
@@ -125,8 +136,11 @@
Unnamed/Unknown Unnamed/Unknown
</h3> </h3>
</li> </li>
<li v-if="allContacts.length === 0" class="text-sm">
(Add friends to see more people worthy of recognition.)
</li>
<li <li
v-for="contact in allContacts.slice(0, 7)" v-for="contact in allContacts.slice(0, 6)"
:key="contact.did" :key="contact.did"
@click="openDialog(contact)" @click="openDialog(contact)"
> >
@@ -141,23 +155,16 @@
{{ contact.name || contact.did }} {{ contact.name || contact.did }}
</h3> </h3>
</li> </li>
<li>
<router-link
v-if="allContacts.length >= 6"
:to="{ name: 'contact-gift' }"
class="flex align-bottom text-xs text-blue-500 mt-12"
>
... or someone else...
</router-link>
</li>
</ul> </ul>
<div class="flex justify-between">
<router-link
v-if="allContacts.length >= 7"
:to="{ name: 'contact-gift' }"
class="block text-center text-md font-bold bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md"
>
Choose From All Contacts
</router-link>
<button
@click="openGiftedPrompts()"
class="block text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-4 py-2 rounded-md"
>
Ideas...
</button>
</div>
</div> </div>
</div> </div>
</div> </div>
@@ -168,26 +175,68 @@
<FeedFilters ref="feedFilters" /> <FeedFilters ref="feedFilters" />
<!-- Results List --> <!-- Results List -->
<div class="bg-slate-100 rounded-md overflow-hidden px-4 py-3 mb-4"> <div class="bg-slate-100 rounded-md px-4 py-3 mt-4 mb-4">
<div class="flex items-center mb-4"> <div class="flex items-center mb-4">
<h2 class="text-xl font-bold">Latest Activity</h2> <h2 class="text-xl font-bold">
<button @click="openFeedFilters()" class="block text-center ml-auto"> Latest Activity
<span class="text-sm text-white"> <button @click="openFeedFilters()">
<span <span class="text-xs text-white">
v-if="resultsAreFiltered()" <fa
class="bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] px-3 py-1.5 rounded-md" v-if="resultsAreFiltered()"
> icon="filter"
Filtered class="bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] px-1 py-1.5 rounded-md"
/>
<fa
v-else
icon="filter"
class="bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] px-1 py-1.5 rounded-md"
/>
</span> </span>
<span </button>
v-else </h2>
class="bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] px-3 py-1.5 rounded-md"
>
Unfiltered
</span>
</span>
</button>
</div> </div>
<div
@click="goToActivityToUserPage()"
class="border-t p-2 border-slate-300"
>
<div class="flex justify-center">
<div
v-if="numNewOffersToUser"
class="bg-gradient-to-b from-green-400 to-green-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] m-1 px-4 py-4 rounded-md text-white"
>
<span
class="block text-center text-6xl"
data-testId="newDirectOffersActivityNumber"
>
{{ numNewOffersToUser }}{{ newOffersToUserHitLimit ? "+" : "" }}
</span>
<p class="text-center">
new offer{{ numNewOffersToUser === 1 ? "" : "s" }} to you
</p>
</div>
<div
v-if="numNewOffersToUserProjects"
class="bg-gradient-to-b from-green-400 to-green-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] m-1 px-4 py-4 rounded-md text-white"
>
<span
class="block text-center text-6xl"
data-testId="newOffersToUserProjectsActivityNumber"
>
{{ numNewOffersToUserProjects
}}{{ newOffersToUserProjectsHitLimit ? "+" : "" }}
</span>
<p class="text-center">
new offer{{ numNewOffersToUserProjects === 1 ? "" : "s" }} to your
projects
</p>
</div>
</div>
<div class="flex justify-end mt-2">
<button class="text-blue-500">View All New Activity For You</button>
</div>
</div>
<InfiniteScroll @reached-bottom="loadMoreGives"> <InfiniteScroll @reached-bottom="loadMoreGives">
<ul id="listLatestActivity" class="border-t border-slate-300"> <ul id="listLatestActivity" class="border-t border-slate-300">
<li <li
@@ -196,7 +245,7 @@
:key="record.jwtId" :key="record.jwtId"
> >
<div <div
class="border-b border-dashed border-slate-400 text-orange-400 pb-2 mb-2 font-bold text-sm" class="border-b border-slate-300 text-orange-400 pb-2 mb-2 font-bold text-sm"
v-if="record.jwtId == feedLastViewedClaimId" v-if="record.jwtId == feedLastViewedClaimId"
> >
You've already seen all the following You've already seen all the following
@@ -261,7 +310,7 @@
<a @click="onClickLoadClaim(record.jwtId)"> <a @click="onClickLoadClaim(record.jwtId)">
<fa <fa
icon="file-lines" icon="file-lines"
class="pl-2 text-blue-500 cursor-pointer" class="pl-2 text-slate-500 cursor-pointer"
/> />
</a> </a>
</span> </span>
@@ -275,6 +324,15 @@
> >
<fa icon="hammer" class="text-blue-500" /> <fa icon="hammer" class="text-blue-500" />
</router-link> </router-link>
<router-link
v-if="record.providerPlanHandleId"
:to="
'/project/' +
encodeURIComponent(record.providerPlanHandleId)
"
>
<fa icon="hammer" class="text-blue-500" />
</router-link>
</span> </span>
</div> </div>
<div v-if="record.image" class="flex justify-center"> <div v-if="record.image" class="flex justify-center">
@@ -310,20 +368,26 @@ import GiftedDialog from "@/components/GiftedDialog.vue";
import GiftedPrompts from "@/components/GiftedPrompts.vue"; import GiftedPrompts from "@/components/GiftedPrompts.vue";
import FeedFilters from "@/components/FeedFilters.vue"; import FeedFilters from "@/components/FeedFilters.vue";
import InfiniteScroll from "@/components/InfiniteScroll.vue"; import InfiniteScroll from "@/components/InfiniteScroll.vue";
import OnboardingDialog from "@/components/OnboardingDialog.vue";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import TopMessage from "@/components/TopMessage.vue"; import TopMessage from "@/components/TopMessage.vue";
import UserNameDialog from "@/components/UserNameDialog.vue";
import { import {
AppString, AppString,
NotificationIface, NotificationIface,
PASSKEYS_ENABLED, PASSKEYS_ENABLED,
} from "@/constants/app"; } from "@/constants/app";
import { db, accountsDB } from "@/db/index"; import {
accountsDB,
db,
retrieveSettingsForActiveAccount,
updateAccountSettings,
} from "@/db/index";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import { import {
BoundingBox, BoundingBox,
isAnyFeedFilterOn, checkIsAnyFeedFilterOn,
MASTER_SETTINGS_KEY, MASTER_SETTINGS_KEY,
Settings,
} from "@/db/tables/settings"; } from "@/db/tables/settings";
import { import {
contactForDid, contactForDid,
@@ -331,12 +395,15 @@ import {
didInfoForContact, didInfoForContact,
fetchEndorserRateLimits, fetchEndorserRateLimits,
getHeaders, getHeaders,
getNewOffersToUser,
getNewOffersToUserProjects,
getPlanFromCache, getPlanFromCache,
GiverReceiverInputInfo,
GiveSummaryRecord, GiveSummaryRecord,
} from "@/libs/endorserServer"; } from "@/libs/endorserServer";
import { import {
generateSaveAndActivateIdentity, generateSaveAndActivateIdentity,
GiverReceiverInputInfo,
OnboardPage,
registerSaveAndActivatePasskey, registerSaveAndActivatePasskey,
} from "@/libs/util"; } from "@/libs/util";
@@ -347,6 +414,7 @@ interface GiveRecordWithContactInfo extends GiveSummaryRecord {
profileImageUrl?: string; profileImageUrl?: string;
}; };
image?: string; image?: string;
providerPlanName?: string;
recipientProjectName?: string; recipientProjectName?: string;
receiver: { receiver: {
displayName: string; displayName: string;
@@ -362,13 +430,15 @@ interface GiveRecordWithContactInfo extends GiveSummaryRecord {
}, },
}, },
components: { components: {
EntityIcon,
FeedFilters,
GiftedDialog, GiftedDialog,
GiftedPrompts, GiftedPrompts,
FeedFilters,
QuickNav,
EntityIcon,
InfiniteScroll, InfiniteScroll,
OnboardingDialog,
QuickNav,
TopMessage, TopMessage,
UserNameDialog,
}, },
}) })
export default class HomeView extends Vue { export default class HomeView extends Vue {
@@ -391,6 +461,12 @@ export default class HomeView extends Vue {
isFeedFilteredByNearby = false; isFeedFilteredByNearby = false;
isFeedLoading = true; isFeedLoading = true;
isRegistered = false; isRegistered = false;
lastAckedOfferToUserJwtId?: string; // the last JWT ID for offer-to-user that they've acknowledged seeing
lastAckedOfferToUserProjectsJwtId?: string; // the last JWT ID for offers-to-user's-projects that they've acknowledged seeing
newOffersToUserHitLimit: boolean = false;
newOffersToUserProjectsHitLimit: boolean = false;
numNewOffersToUser: number = 0; // number of new offers-to-user
numNewOffersToUserProjects: number = 0; // number of new offers-to-user's-projects
searchBoxes: Array<{ searchBoxes: Array<{
name: string; name: string;
bbox: BoundingBox; bbox: BoundingBox;
@@ -411,20 +487,28 @@ export default class HomeView extends Vue {
this.allMyDids = [newDid]; this.allMyDids = [newDid];
} }
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; this.apiServer = settings.apiServer || "";
this.apiServer = settings?.apiServer || ""; this.activeDid = settings.activeDid || "";
this.activeDid = settings?.activeDid || "";
this.allContacts = await db.contacts.toArray(); this.allContacts = await db.contacts.toArray();
this.feedLastViewedClaimId = settings?.lastViewedClaimId; this.feedLastViewedClaimId = settings.lastViewedClaimId;
this.givenName = settings?.firstName || ""; this.givenName = settings.firstName || "";
this.isFeedFilteredByVisible = !!settings?.filterFeedByVisible; this.isFeedFilteredByVisible = !!settings.filterFeedByVisible;
this.isFeedFilteredByNearby = !!settings?.filterFeedByNearby; this.isFeedFilteredByNearby = !!settings.filterFeedByNearby;
this.isRegistered = !!settings?.isRegistered; this.isRegistered = !!settings.isRegistered;
this.searchBoxes = settings?.searchBoxes || []; this.lastAckedOfferToUserJwtId = settings.lastAckedOfferToUserJwtId;
this.showShortcutBvc = !!settings?.showShortcutBvc; this.lastAckedOfferToUserProjectsJwtId =
settings.lastAckedOfferToUserProjectsJwtId;
this.searchBoxes = settings.searchBoxes || [];
this.showShortcutBvc = !!settings.showShortcutBvc;
this.isAnyFeedFilterOn = isAnyFeedFilterOn(settings); this.isAnyFeedFilterOn = checkIsAnyFeedFilterOn(settings);
if (!settings.finishedOnboarding) {
(this.$refs.onboardingDialog as OnboardingDialog).open(
OnboardPage.Home,
);
}
// someone may have have registered after sharing contact info, so recheck // someone may have have registered after sharing contact info, so recheck
if (!this.isRegistered && this.activeDid) { if (!this.isRegistered && this.activeDid) {
@@ -435,9 +519,7 @@ export default class HomeView extends Vue {
this.activeDid, this.activeDid,
); );
if (resp.status === 200) { if (resp.status === 200) {
// we just needed to know that they're registered await updateAccountSettings(this.activeDid, {
await db.open();
await db.settings.update(MASTER_SETTINGS_KEY, {
isRegistered: true, isRegistered: true,
}); });
this.isRegistered = true; this.isRegistered = true;
@@ -448,7 +530,29 @@ export default class HomeView extends Vue {
} }
// this returns a Promise but we don't need to wait for it // this returns a Promise but we don't need to wait for it
await this.updateAllFeed(); this.updateAllFeed();
if (this.activeDid) {
const offersToUserData = await getNewOffersToUser(
this.axios,
this.apiServer,
this.activeDid,
this.lastAckedOfferToUserJwtId,
);
this.numNewOffersToUser = offersToUserData.data.length;
this.newOffersToUserHitLimit = offersToUserData.hitLimit;
}
if (this.activeDid) {
const offersToUserProjects = await getNewOffersToUserProjects(
this.axios,
this.apiServer,
this.activeDid,
this.lastAckedOfferToUserProjectsJwtId,
);
this.numNewOffersToUserProjects = offersToUserProjects.data.length;
this.newOffersToUserProjectsHitLimit = offersToUserProjects.hitLimit;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) { } catch (err: any) {
@@ -486,15 +590,14 @@ export default class HomeView extends Vue {
// only called when a setting was changed // only called when a setting was changed
async reloadFeedOnChange() { async reloadFeedOnChange() {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; this.isFeedFilteredByVisible = !!settings.filterFeedByVisible;
this.isFeedFilteredByVisible = !!settings?.filterFeedByVisible; this.isFeedFilteredByNearby = !!settings.filterFeedByNearby;
this.isFeedFilteredByNearby = !!settings?.filterFeedByNearby; this.isAnyFeedFilterOn = checkIsAnyFeedFilterOn(settings);
this.isAnyFeedFilterOn = isAnyFeedFilterOn(settings);
this.feedData = []; this.feedData = [];
this.feedPreviousOldestId = undefined; this.feedPreviousOldestId = undefined;
this.updateAllFeed(); await this.updateAllFeed();
} }
/** /**
@@ -506,7 +609,7 @@ export default class HomeView extends Vue {
// and the InfiniteScroll component triggers a load before finished. // and the InfiniteScroll component triggers a load before finished.
// One alternative is to totally separate the project link loading. // One alternative is to totally separate the project link loading.
if (payload && !this.isFeedLoading) { if (payload && !this.isFeedLoading) {
this.updateAllFeed(); await this.updateAllFeed();
} }
} }
@@ -545,7 +648,7 @@ export default class HomeView extends Vue {
// This has indeed proven problematic. See loadMoreGives // This has indeed proven problematic. See loadMoreGives
// We should display it immediately and then get the plan later. // We should display it immediately and then get the plan later.
const plan = await getPlanFromCache( const fulfillsPlan = await getPlanFromCache(
record.fulfillsPlanHandleId, record.fulfillsPlanHandleId,
this.axios, this.axios,
this.apiServer, this.apiServer,
@@ -561,8 +664,13 @@ export default class HomeView extends Vue {
if (!anyMatch && this.isFeedFilteredByNearby) { if (!anyMatch && this.isFeedFilteredByNearby) {
// check if the associated project has a location inside user's search box // check if the associated project has a location inside user's search box
if (record.fulfillsPlanHandleId) { if (record.fulfillsPlanHandleId) {
if (plan?.locLat && plan?.locLon) { if (fulfillsPlan?.locLat && fulfillsPlan?.locLon) {
if (this.latLongInAnySearchBox(plan.locLat, plan.locLon)) { if (
this.latLongInAnySearchBox(
fulfillsPlan.locLat,
fulfillsPlan.locLon,
)
) {
anyMatch = true; anyMatch = true;
} }
} }
@@ -572,6 +680,17 @@ export default class HomeView extends Vue {
continue; continue;
} }
// checking for arrays due to legacy data
const provider = Array.isArray(claim.provider)
? claim.provider[0]
: claim.provider;
const providedByPlan = await getPlanFromCache(
provider?.identifier as string,
this.axios,
this.apiServer,
this.activeDid,
);
const newRecord: GiveRecordWithContactInfo = { const newRecord: GiveRecordWithContactInfo = {
...record, ...record,
giver: didInfoForContact( giver: didInfoForContact(
@@ -581,7 +700,9 @@ export default class HomeView extends Vue {
this.allMyDids, this.allMyDids,
), ),
image: claim.image, image: claim.image,
recipientProjectName: plan?.name as string, providerPlanHandleId: provider?.identifier as string,
providerPlanName: providedByPlan?.name as string,
recipientProjectName: fulfillsPlan?.name as string,
receiver: didInfoForContact( receiver: didInfoForContact(
recipientDid, recipientDid,
this.activeDid, this.activeDid,
@@ -619,7 +740,7 @@ export default class HomeView extends Vue {
}); });
if (this.feedData.length === 0 && !endOfResults) { if (this.feedData.length === 0 && !endOfResults) {
// repeat until there's at least some data // repeat until there's at least some data
this.updateAllFeed(); await this.updateAllFeed();
} }
this.isFeedLoading = false; this.isFeedLoading = false;
} }
@@ -675,50 +796,70 @@ export default class HomeView extends Vue {
} }
/** /**
* Only show giver and/or receiver info first if they're named. * Only show giver and/or receiver info first if they're named in your contacts.
* - If only giver is named, show "... gave" * - If only giver is named, show "... gave"
* - If only receiver is named, show "... received" * - If only receiver is named, show "... received"
*/ */
const giverInfo = giveRecord.giver; const giverInfo = giveRecord.giver;
const recipientInfo = giveRecord.receiver; const recipientInfo = giveRecord.receiver;
// any specific names should be shown first
if (giverInfo.known && recipientInfo.known) { if (giverInfo.known && recipientInfo.known) {
// both giver and recipient are named // both giver and recipient are named
return `${giverInfo.displayName} gave to ${recipientInfo.displayName}: ${gaveAmount}`; return `${giverInfo.displayName} gave to ${recipientInfo.displayName}: ${gaveAmount}`;
} else if (giverInfo.known) { } else if (giverInfo.known) {
// giver is named but recipient is not // giver is known but recipient is not
// show the project name if to one // show the project name if to one
if (giveRecord.recipientProjectName) { if (giveRecord.recipientProjectName) {
// retrieve the project name return `${giverInfo.displayName} gave: ${gaveAmount} (to the project "${giveRecord.recipientProjectName}")`;
return `${giverInfo.displayName} gave: ${gaveAmount} (to the project ${giveRecord.recipientProjectName})`; } else {
// it's not to a project
return `${giverInfo.displayName} gave: ${gaveAmount} (to ${recipientInfo.displayName})`;
} }
// it's not to a project
return `${giverInfo.displayName} gave: ${gaveAmount} (to ${recipientInfo.displayName})`;
} else if (recipientInfo.known) { } else if (recipientInfo.known) {
// recipient is named but giver is not // recipient is known but giver is not
return `${recipientInfo.displayName} received: ${gaveAmount} (from ${giverInfo.displayName})`;
// show the project name if from one
if (giveRecord.providerPlanName) {
return `${recipientInfo.displayName} received: ${gaveAmount} (from the project "${giveRecord.providerPlanName}")`;
} else {
// it's not from a project
return `${recipientInfo.displayName} received: ${gaveAmount} (from ${giverInfo.displayName})`;
}
} else { } else {
// neither giver nor recipient are named // neither giver nor recipient are named
// show the project name if to one // create the part in parens
if (giveRecord.recipientProjectName) { let peopleInfo = "";
// retrieve the project name if (giveRecord.providerPlanName || giveRecord.recipientProjectName) {
return `${gaveAmount} (to the project ${giveRecord.recipientProjectName})`; if (giveRecord.providerPlanName) {
peopleInfo = `from the project "${giveRecord.providerPlanName}"`;
} else {
peopleInfo = `from ${giverInfo.displayName}`;
}
if (giveRecord.recipientProjectName) {
peopleInfo += ` to the project "${giveRecord.recipientProjectName}"`;
} else {
peopleInfo += ` to ${recipientInfo.displayName}`;
}
} else {
if (giverInfo.displayName === recipientInfo.displayName) {
peopleInfo = `between two who are ${giverInfo.displayName}`;
} else {
peopleInfo = `from ${giverInfo.displayName} to ${recipientInfo.displayName}`;
}
} }
// it's not to a project
let peopleInfo;
if (giverInfo.displayName === recipientInfo.displayName) {
peopleInfo = `between two who are ${giverInfo.displayName}`;
} else {
peopleInfo = `from ${giverInfo.displayName} to ${recipientInfo.displayName}`;
}
return gaveAmount + " (" + peopleInfo + ")"; return gaveAmount + " (" + peopleInfo + ")";
} }
} }
goToActivityToUserPage() {
(this.$router as Router).push({ name: "new-activity" });
}
onClickLoadClaim(jwtId: string) { onClickLoadClaim(jwtId: string) {
const route = { const route = {
path: "/claim/" + encodeURIComponent(jwtId), path: "/claim/" + encodeURIComponent(jwtId),
@@ -734,27 +875,30 @@ export default class HomeView extends Vue {
return unitCode === "HUR" ? (single ? "hour" : "hours") : unitCode; return unitCode === "HUR" ? (single ? "hour" : "hours") : unitCode;
} }
openDialog(giver?: GiverReceiverInputInfo) { openDialog(giver?: GiverReceiverInputInfo, description?: string) {
(this.$refs.customDialog as GiftedDialog).open( (this.$refs.customDialog as GiftedDialog).open(
giver, giver,
{ {
did: this.activeDid, did: this.activeDid,
name: "you", name: "you",
}, } as GiverReceiverInputInfo,
undefined, undefined,
"Given by " + (giver?.name || "someone not named"), "Given by " + (giver?.name || "someone not named"),
description,
); );
} }
openGiftedPrompts() { openGiftedPrompts() {
(this.$refs.giftedPrompts as GiftedPrompts).open(); (this.$refs.giftedPrompts as GiftedPrompts).open((giver, description) =>
this.openDialog(giver as GiverReceiverInputInfo, description),
);
} }
openFeedFilters() { openFeedFilters() {
(this.$refs.feedFilters as FeedFilters).open(this.reloadFeedOnChange); (this.$refs.feedFilters as FeedFilters).open(this.reloadFeedOnChange);
} }
toastUser(message) { toastUser(message: string) {
this.$notify( this.$notify(
{ {
group: "alert", group: "alert",
@@ -769,5 +913,36 @@ export default class HomeView extends Vue {
computeKnownPersonIconStyleClassNames(known: boolean) { computeKnownPersonIconStyleClassNames(known: boolean) {
return known ? "text-slate-500" : "text-slate-100"; return known ? "text-slate-500" : "text-slate-100";
} }
showNameThenIdDialog() {
if (!this.givenName) {
(this.$refs.userNameDialog as UserNameDialog).open(() => {
this.promptForShareMethod();
});
} else {
this.promptForShareMethod();
}
}
promptForShareMethod() {
this.$notify(
{
group: "modal",
type: "confirm",
title: "Are you nearby with cameras?",
text: "If so, we'll use those with QR codes to share.",
onCancel: async () => {},
onNo: async () => {
(this.$router as Router).push({ name: "share-my-contact-info" });
},
onYes: async () => {
(this.$router as Router).push({ name: "contact-qr" });
},
noText: "we will share another way",
yesText: "we are nearby with cameras",
},
-1,
);
}
} }
</script> </script>

View File

@@ -102,8 +102,8 @@ import { Component, Vue } from "vue-facing-decorator";
import { Router } from "vue-router"; import { Router } from "vue-router";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { db, accountsDB } from "@/db/index"; import { db, accountsDB, retrieveSettingsForActiveAccount } from "@/db/index";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings"; import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
@Component({ components: { QuickNav } }) @Component({ components: { QuickNav } })
@@ -118,11 +118,10 @@ export default class IdentitySwitcherView extends Vue {
async created() { async created() {
try { try {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; this.activeDid = settings.activeDid || "";
this.activeDid = settings?.activeDid || ""; this.apiServer = settings.apiServer || "";
this.apiServer = settings?.apiServer || ""; this.apiServerInput = settings.apiServer || "";
this.apiServerInput = settings?.apiServer || "";
await accountsDB.open(); await accountsDB.open();
const accounts = await accountsDB.accounts.toArray(); const accounts = await accountsDB.accounts.toArray();

View File

@@ -53,6 +53,13 @@
<input type="checkbox" class="mr-2" v-model="shouldErase" /> <input type="checkbox" class="mr-2" v-model="shouldErase" />
<label>Erase the previous identifier.</label> <label>Erase the previous identifier.</label>
</div> </div>
<div v-if="isNotProdServer()" class="mt-4 text-blue-500">
<!-- if they click this, fill in the mnemonic seed-input with the test mnemonic -->
<button @click="mnemonic = TEST_USER_0_MNEMONIC">
Use mnemonic for Test User #0
</button>
</div>
</div> </div>
<div class="mt-8"> <div class="mt-8">
@@ -79,8 +86,8 @@
import { Component, Vue } from "vue-facing-decorator"; import { Component, Vue } from "vue-facing-decorator";
import { Router } from "vue-router"; import { Router } from "vue-router";
import { NotificationIface } from "@/constants/app"; import { AppString, NotificationIface } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { import {
DEFAULT_ROOT_DERIVATION_PATH, DEFAULT_ROOT_DERIVATION_PATH,
@@ -92,28 +99,40 @@ import {
components: {}, components: {},
}) })
export default class ImportAccountView extends Vue { export default class ImportAccountView extends Vue {
TEST_USER_0_MNEMONIC =
"rigid shrug mobile smart veteran half all pond toilet brave review universe ship congress found yard skate elite apology jar uniform subway slender luggage";
UPORT_DERIVATION_PATH = "m/7696500'/0'/0'/0'"; // for legacy imports, likely never used UPORT_DERIVATION_PATH = "m/7696500'/0'/0'/0'"; // for legacy imports, likely never used
AppString = AppString;
$notify!: (notification: NotificationIface, timeout?: number) => void; $notify!: (notification: NotificationIface, timeout?: number) => void;
mnemonic = ""; apiServer = "";
address = ""; address = "";
derivationPath = DEFAULT_ROOT_DERIVATION_PATH;
mnemonic = "";
numAccounts = 0; numAccounts = 0;
privateHex = ""; privateHex = "";
publicHex = ""; publicHex = "";
derivationPath = DEFAULT_ROOT_DERIVATION_PATH;
showAdvanced = false; showAdvanced = false;
shouldErase = false; shouldErase = false;
async created() { async created() {
await accountsDB.open(); await accountsDB.open();
this.numAccounts = await accountsDB.accounts.count(); this.numAccounts = await accountsDB.accounts.count();
// get the server, to help with import on the test server
const settings = await retrieveSettingsForActiveAccount();
this.apiServer = settings.apiServer || "";
} }
public onCancelClick() { public onCancelClick() {
(this.$router as Router).back(); (this.$router as Router).back();
} }
public isNotProdServer() {
return this.apiServer !== AppString.PROD_ENDORSER_API_SERVER;
}
public async fromMnemonic() { public async fromMnemonic() {
const mne: string = this.mnemonic.trim().toLowerCase(); const mne: string = this.mnemonic.trim().toLowerCase();
try { try {

392
src/views/InviteOneView.vue Normal file
View File

@@ -0,0 +1,392 @@
<template>
<QuickNav selected="Invite" />
<TopMessage />
<section id="Content" class="p-6 pb-24 max-w-3xl mx-auto">
<!-- Back -->
<div class="text-lg text-center font-light relative px-7">
<h1
class="text-lg text-center px-2 py-1 absolute -left-2 -top-1"
@click="$router.back()"
>
<fa icon="chevron-left" class="fa-fw"></fa>
</h1>
</div>
<!-- Heading -->
<h1 class="text-4xl text-center font-light">Invitations</h1>
<ul class="ml-8 mt-4 list-outside list-disc w-5/6">
<li>
Note when sending
<span
v-if="!showAppleWarning"
class="text-blue-500 cursor-pointer"
@click="showAppleWarning = !showAppleWarning"
>
to Apple users...
</span>
<span v-else>
to Apple users: their links often fail because their device cuts off
part of the link. You might need to send it to them some other way,
like in an email.
</span>
</li>
</ul>
<!-- New Project -->
<button
v-if="isRegistered"
class="fixed right-6 top-12 text-center text-4xl leading-none bg-green-600 text-white w-14 py-2.5 rounded-full"
@click="createInvite()"
>
<fa icon="plus" class="fa-fw"></fa>
</button>
<InviteDialog ref="inviteDialog" />
<!-- Invites Table -->
<div v-if="invites.length" class="mt-6">
<table class="min-w-full bg-white">
<thead>
<tr>
<th class="py-2">
ID
<br />
(click for link)
</th>
<th class="py-2">Notes</th>
<th class="py-2">Expires At</th>
<th class="py-2">Redeemed</th>
</tr>
</thead>
<tbody>
<tr
v-for="invite in invites"
:key="invite.inviteIdentifier"
class="border-t py-2"
>
<td>
<span
v-if="
!invite.redeemedAt &&
invite.expiresAt > new Date().toISOString()
"
@click="
copyInviteAndNotify(invite.inviteIdentifier, invite.jwt)
"
class="text-center text-blue-500 cursor-pointer"
:title="inviteLink(invite.jwt)"
>
{{ getTruncatedInviteId(invite.inviteIdentifier) }}
</span>
<span
v-else
@click="
showInvite(
invite.inviteIdentifier,
!!invite.redeemedAt,
invite.expiresAt < new Date().toISOString(),
)
"
class="text-center text-slate-500 cursor-pointer"
:title="inviteLink(invite.jwt)"
>
{{ getTruncatedInviteId(invite.inviteIdentifier) }}
</span>
</td>
<td class="text-left" :data-testId="inviteLink(invite.jwt)">
{{ invite.notes }}
</td>
<td class="text-center">
{{ invite.expiresAt.substring(0, 10) }}
</td>
<td class="text-center">
{{ invite.redeemedAt?.substring(0, 10) }}
<br />
{{ getTruncatedRedeemedBy(invite.redeemedBy) }}
<br />
<fa
v-if="invite.redeemedBy && !contactsRedeemed[invite.redeemedBy]"
icon="plus"
class="bg-green-600 text-white px-1 py-1 rounded-full cursor-pointer"
@click="addNewContact(invite.redeemedBy)"
/>
</td>
<td>
<fa
icon="trash-can"
class="text-red-600 text-xl ml-2 mr-2 cursor-pointer"
@click="deleteInvite(invite.inviteIdentifier, invite.notes)"
/>
</td>
</tr>
</tbody>
</table>
<ContactNameDialog ref="contactNameDialog" />
</div>
<p v-else class="mt-6 text-center">No invites found.</p>
</section>
</template>
<script lang="ts">
import axios from "axios";
import { Component, Vue } from "vue-facing-decorator";
import { useClipboard } from "@vueuse/core";
import ContactNameDialog from "@/components/ContactNameDialog.vue";
import QuickNav from "@/components/QuickNav.vue";
import TopMessage from "@/components/TopMessage.vue";
import InviteDialog from "@/components/InviteDialog.vue";
import { APP_SERVER, NotificationIface } from "@/constants/app";
import { db, retrieveSettingsForActiveAccount } from "@/db";
import { createInviteJwt, getHeaders } from "@/libs/endorserServer";
interface Invite {
inviteIdentifier: string;
expiresAt: string;
jwt: string;
notes: string;
redeemedAt: string | null;
redeemedBy: string | null;
}
@Component({
components: { ContactNameDialog, QuickNav, TopMessage, InviteDialog },
})
export default class InviteOneView extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void;
invites: Invite[] = [];
activeDid: string = "";
apiServer: string = "";
contactsRedeemed = {};
isRegistered: boolean = false;
showAppleWarning = false;
async mounted() {
try {
await db.open();
const settings = await retrieveSettingsForActiveAccount();
this.activeDid = settings.activeDid || "";
this.apiServer = settings.apiServer || "";
this.isRegistered = !!settings.isRegistered;
const headers = await getHeaders(this.activeDid);
const response = await axios.get(
this.apiServer + "/api/userUtil/invite",
{ headers },
);
this.invites = response.data.data;
const baseContacts = await db.contacts.toArray();
for (const invite of this.invites) {
const contact = baseContacts.find(
(contact) => contact.did === invite.redeemedBy,
);
if (contact) {
this.contactsRedeemed[invite.redeemedBy] = contact;
}
}
} catch (error) {
console.error("Error fetching invites:", error);
this.$notify(
{
group: "alert",
type: "danger",
title: "Load Error",
text: "Got an error loading your invites.",
},
5000,
);
}
}
getTruncatedInviteId(inviteId: string): string {
if (inviteId.length <= 9) return inviteId;
return `${inviteId.slice(0, 6)}...`;
}
getTruncatedRedeemedBy(redeemedBy: string | null): string {
if (!redeemedBy) return "";
if (this.contactsRedeemed[redeemedBy]) {
return this.contactsRedeemed[redeemedBy].name;
}
if (redeemedBy.length <= 19) return redeemedBy;
return `${redeemedBy.slice(0, 13)}...${redeemedBy.slice(-3)}`;
}
inviteLink(jwt: string): string {
return APP_SERVER + "/contacts?inviteJwt=" + jwt;
}
copyInviteAndNotify(inviteId: string, jwt: string) {
useClipboard().copy(this.inviteLink(jwt));
this.$notify(
{
group: "alert",
type: "success",
title: "Copied",
text: "Your clipboard now contains the link for invite " + inviteId,
},
5000,
);
}
showInvite(inviteId: string, redeemed: boolean, expired: boolean) {
let message = `Your clipboard now contains the invite ID ${inviteId}`;
if (redeemed) {
message += " (This invite has been used.)";
} else if (expired) {
message += " (This invite has expired.)";
}
useClipboard().copy(inviteId);
this.$notify(
{
group: "alert",
type: "success",
title: "Copied",
text: message,
},
5000,
);
}
lookForErrorAndNotify(error, title: string, defaultMessage: string) {
console.error(title, "-", error);
let message = defaultMessage;
if (error.response && error.response.data && error.response.data.error) {
if (error.response.data.error.message) {
message = error.response.data.error.message;
} else {
message = error.response.data.error;
}
}
this.$notify(
{
group: "alert",
type: "danger",
title: title,
text: message,
},
5000,
);
}
async createInvite() {
const inviteIdentifier =
Math.random().toString(36).substring(2) +
Math.random().toString(36).substring(2) +
Math.random().toString(36).substring(2);
(this.$refs.inviteDialog as InviteDialog).open(
inviteIdentifier,
async (notes, expiresAt) => {
try {
const headers = await getHeaders(this.activeDid);
if (!expiresAt) {
throw {
response: {
data: { error: "You must select an expiration date." },
},
};
}
const expiresIn = (new Date(expiresAt).getTime() - Date.now()) / 1000;
const inviteJwt = await createInviteJwt(
this.activeDid,
undefined,
inviteIdentifier,
expiresIn,
);
await axios.post(
this.apiServer + "/api/userUtil/invite",
{ inviteJwt: inviteJwt, notes: notes },
{ headers },
);
this.invites.push({
inviteIdentifier: inviteIdentifier,
expiresAt: expiresAt,
jwt: inviteJwt,
notes: notes,
redeemedAt: null,
redeemedBy: null,
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
this.lookForErrorAndNotify(
error,
"Error Creating Invite",
"Got an error creating your invite.",
);
}
},
);
}
addNewContact(did) {
(this.$refs.contactNameDialog as ContactNameDialog).open(
"Who Sent You The Invite?",
"Their name will be added to your contact list.",
(name) => {
// the person obviously registered themselves and this user already granted visibility, so we just add them
const contact = {
did: did,
name: name,
registered: true,
};
db.contacts.add(contact);
this.contactsRedeemed[did] = contact;
this.$notify(
{
group: "alert",
type: "success",
title: "Contact Added",
text: `${name} has been added to your contacts.`,
},
3000,
);
},
);
}
deleteInvite(inviteId: string, notes: string) {
this.$notify(
{
group: "modal",
type: "confirm",
title: "Delete Invite?",
text: `Are you sure you want to erase the invite for "${notes}"? (There is no undo.)`,
onYes: async () => {
const headers = await getHeaders(this.activeDid);
try {
const result = await axios.delete(
this.apiServer + "/api/userUtil/invite/" + inviteId,
{ headers },
);
if (result.status !== 204) {
throw result.data;
}
this.invites = this.invites.filter(
(invite) => invite.inviteIdentifier !== inviteId,
);
this.$notify(
{
group: "alert",
type: "success",
title: "Deleted",
text: "Invite deleted.",
},
3000,
);
} catch (e) {
this.lookForErrorAndNotify(
e,
"Error Deleting Invite",
"Got an error deleting your invite.",
);
}
},
},
-1,
);
}
}
</script>

View File

@@ -0,0 +1,335 @@
<template>
<QuickNav selected="Home"></QuickNav>
<!-- CONTENT -->
<section id="Content" class="p-6 pb-24 max-w-3xl mx-auto">
<!-- Breadcrumb -->
<div id="ViewBreadcrumb" class="mb-8">
<h1 class="text-lg text-center font-light relative px-7">
<!-- Back -->
<fa
icon="chevron-left"
@click="$router.back()"
class="fa-fw text-lg text-center px-2 py-1 absolute -left-2 -top-1"
/>
New Activity For You
</h1>
</div>
<!-- Display a single row with the name of "New Offers To You" with a count. -->
<div class="flex justify-between" data-testId="showOffersToUser">
<div>
<span class="text-lg font-medium"
>{{ newOffersToUser.length
}}{{ newOffersToUserHitLimit ? "+" : "" }}</span
>
<span class="text-lg font-medium ml-4"
>New Offer{{ newOffersToUser.length === 1 ? "" : "s" }} To You</span
>
<fa
v-if="newOffersToUser.length > 0"
:icon="showOffersDetails ? 'chevron-down' : 'chevron-right'"
class="cursor-pointer ml-4 mr-4 text-lg"
@click="expandOffersToUserAndMarkRead()"
/>
</div>
<router-link to="/recent-offers-to-user" class="text-blue-500">
See&nbsp;all
</router-link>
</div>
<div v-if="showOffersDetails" class="ml-4 mt-4">
<ul class="list-disc ml-4">
<li
v-for="offer in newOffersToUser"
:key="offer.jwtId"
class="mt-4 relative group"
>
<span>{{
didInfo(offer.offeredByDid, activeDid, allMyDids, allContacts)
}}</span>
offered
<span v-if="offer.objectDescription">{{
offer.objectDescription
}}</span
>{{ offer.objectDescription && offer.amount ? ", and " : "" }}
<span v-if="offer.amount">{{
displayAmount(offer.unit, offer.amount)
}}</span>
<router-link
:to="{ path: '/claim/' + encodeURIComponent(offer.jwtId) }"
class="text-blue-500"
>
<fa icon="file-lines" class="pl-2 text-blue-500 cursor-pointer" />
</router-link>
<!-- New line that appears on hover -->
<div
@click="markOffersAsReadStartingWith(offer.jwtId)"
class="absolute left-0 w-full text-left text-gray-500 text-sm hidden group-hover:flex cursor-pointer items-center"
>
<span class="inline-block w-8 h-px bg-gray-500 mr-2" />
Click to keep all above as new offers
</div>
</li>
</ul>
</div>
<!-- Display a single row with the name of "New Offers To Your Projects" with a count. -->
<div
class="mt-4 flex justify-between"
data-testId="showOffersToUserProjects"
>
<div>
<span class="text-lg font-medium"
>{{ newOffersToUserProjects.length
}}{{ newOffersToUserProjectsHitLimit ? "+" : "" }}</span
>
<span class="text-lg font-medium ml-4"
>New Offer{{ newOffersToUserProjects.length === 1 ? "" : "s" }} To
Your Projects</span
>
<fa
v-if="newOffersToUserProjects.length > 0"
:icon="
showOffersToUserProjectsDetails ? 'chevron-down' : 'chevron-right'
"
class="cursor-pointer ml-4 mr-4 text-lg"
@click="expandOffersToUserProjectsAndMarkRead()"
/>
</div>
<router-link to="/recent-offers-to-user-projects" class="text-blue-500">
See&nbsp;all
</router-link>
</div>
<div v-if="showOffersToUserProjectsDetails" class="ml-4 mt-4">
<ul class="list-disc ml-4">
<li
v-for="offer in newOffersToUserProjects"
:key="offer.jwtId"
class="mt-4 relative group"
>
<span>{{
didInfo(offer.offeredByDid, activeDid, allMyDids, allContacts)
}}</span>
offered
<span v-if="offer.objectDescription">{{
offer.objectDescription
}}</span
>{{ offer.objectDescription && offer.amount ? ", and " : "" }}
<span v-if="offer.amount">{{
displayAmount(offer.unit, offer.amount)
}}</span>
to
<span>{{ offer.planName }}</span>
<router-link
:to="{ path: '/claim/' + encodeURIComponent(offer.jwtId) }"
class="text-blue-500"
>
<fa icon="file-lines" class="pl-2 text-blue-500 cursor-pointer" />
</router-link>
<!-- New line that appears on hover -->
<div
@click="markOffersToUserProjectsAsReadStartingWith(offer.jwtId)"
class="absolute left-0 w-full text-left text-gray-500 text-sm hidden group-hover:flex cursor-pointer items-center"
>
<span class="inline-block w-8 h-px bg-gray-500 mr-2" />
Click to keep all above as new offers
</div>
</li>
</ul>
</div>
</section>
</template>
<script lang="ts">
import { Component, Vue } from "vue-facing-decorator";
import GiftedDialog from "@/components/GiftedDialog.vue";
import QuickNav from "@/components/QuickNav.vue";
import EntityIcon from "@/components/EntityIcon.vue";
import { NotificationIface } from "@/constants/app";
import {
accountsDB,
db,
retrieveSettingsForActiveAccount,
updateAccountSettings,
} from "@/db/index";
import { Contact } from "@/db/tables/contacts";
import {
didInfo,
displayAmount,
getNewOffersToUser,
getNewOffersToUserProjects,
OfferSummaryRecord,
OfferToPlanSummaryRecord,
} from "@/libs/endorserServer";
@Component({
components: { GiftedDialog, QuickNav, EntityIcon },
})
export default class NewActivityView extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void;
activeDid = "";
allContacts: Array<Contact> = [];
allMyDids: string[] = [];
apiServer = "";
lastAckedOfferToUserJwtId = "";
lastAckedOfferToUserProjectsJwtId = "";
newOffersToUser: Array<OfferSummaryRecord> = [];
newOffersToUserHitLimit = false;
newOffersToUserProjects: Array<OfferToPlanSummaryRecord> = [];
newOffersToUserProjectsHitLimit = false;
showOffersDetails = false;
showOffersToUserProjectsDetails = false;
didInfo = didInfo;
displayAmount = displayAmount;
async created() {
try {
const settings = await retrieveSettingsForActiveAccount();
this.apiServer = settings.apiServer || "";
this.activeDid = settings.activeDid || "";
this.lastAckedOfferToUserJwtId = settings.lastAckedOfferToUserJwtId || "";
this.lastAckedOfferToUserProjectsJwtId =
settings.lastAckedOfferToUserProjectsJwtId || "";
this.allContacts = await db.contacts.toArray();
await accountsDB.open();
const allAccounts = await accountsDB.accounts.toArray();
if (allAccounts.length > 0) {
this.allMyDids = allAccounts.map((acc) => acc.did);
}
const offersToUserData = await getNewOffersToUser(
this.axios,
this.apiServer,
this.activeDid,
this.lastAckedOfferToUserJwtId,
);
this.newOffersToUser = offersToUserData.data;
this.newOffersToUserHitLimit = offersToUserData.hitLimit;
const offersToUserProjectsData = await getNewOffersToUserProjects(
this.axios,
this.apiServer,
this.activeDid,
this.lastAckedOfferToUserProjectsJwtId,
);
this.newOffersToUserProjects = offersToUserProjectsData.data;
this.newOffersToUserProjectsHitLimit = offersToUserProjectsData.hitLimit;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
console.error("Error retrieving settings & contacts:", err);
this.$notify(
{
group: "alert",
type: "danger",
title: "Error",
text: err.message || "There was an error retrieving your activity.",
},
5000,
);
}
}
async expandOffersToUserAndMarkRead() {
this.showOffersDetails = !this.showOffersDetails;
if (this.showOffersDetails) {
await updateAccountSettings(this.activeDid, {
lastAckedOfferToUserJwtId: this.newOffersToUser[0].jwtId,
});
// note that we don't update this.lastAckedOfferToUserJwtId in case they
// later choose the last one to keep the offers as new
this.$notify(
{
group: "alert",
type: "info",
title: "Marked as Read",
text: "The offers are marked as viewed. Click in the list to keep them as new.",
},
5000,
);
}
}
async markOffersAsReadStartingWith(jwtId: string) {
const index = this.newOffersToUser.findIndex(
(offer) => offer.jwtId === jwtId,
);
if (index !== -1 && index < this.newOffersToUser.length - 1) {
// Set to the next offer's jwtId
await updateAccountSettings(this.activeDid, {
lastAckedOfferToUserJwtId: this.newOffersToUser[index + 1].jwtId,
});
} else {
// it's the last entry (or not found), so just keep it the same
await updateAccountSettings(this.activeDid, {
lastAckedOfferToUserJwtId: this.lastAckedOfferToUserJwtId,
});
}
this.$notify(
{
group: "alert",
type: "info",
title: "Marked as Unread",
text: "All offers above that one are marked as unread.",
},
3000,
);
}
async expandOffersToUserProjectsAndMarkRead() {
this.showOffersToUserProjectsDetails =
!this.showOffersToUserProjectsDetails;
if (this.showOffersToUserProjectsDetails) {
await updateAccountSettings(this.activeDid, {
lastAckedOfferToUserProjectsJwtId:
this.newOffersToUserProjects[0].jwtId,
});
// note that we don't update this.lastAckedOfferToUserProjectsJwtId in case
// they later choose the last one to keep the offers as new
this.$notify(
{
group: "alert",
type: "info",
title: "Marked as Read",
text: "The offers are marked as viewed. Click in the list to keep them as new.",
},
5000,
);
}
}
async markOffersToUserProjectsAsReadStartingWith(jwtId: string) {
const index = this.newOffersToUserProjects.findIndex(
(offer) => offer.jwtId === jwtId,
);
if (index !== -1 && index < this.newOffersToUserProjects.length - 1) {
// Set to the next offer's jwtId
await updateAccountSettings(this.activeDid, {
lastAckedOfferToUserProjectsJwtId:
this.newOffersToUserProjects[index + 1].jwtId,
});
} else {
// it's the last entry (or not found), so just keep it the same
await updateAccountSettings(this.activeDid, {
lastAckedOfferToUserProjectsJwtId:
this.lastAckedOfferToUserProjectsJwtId,
});
}
this.$notify(
{
group: "alert",
type: "info",
title: "Marked as Unread",
text: "All offers above that one are marked as unread.",
},
3000,
);
}
}
</script>

View File

@@ -47,8 +47,8 @@
import { Component, Vue } from "vue-facing-decorator"; import { Component, Vue } from "vue-facing-decorator";
import { Router } from "vue-router"; import { Router } from "vue-router";
import { db } from "@/db/index"; import { db, retrieveSettingsForActiveAccount } from "@/db/index";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings"; import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
@Component({ @Component({
components: {}, components: {},
@@ -58,11 +58,10 @@ export default class NewEditAccountView extends Vue {
// 'created' hook runs when the Vue instance is first created // 'created' hook runs when the Vue instance is first created
async created() { async created() {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings;
this.givenName = this.givenName =
(settings?.firstName || "") + (settings.firstName || "") +
(settings?.lastName ? ` ${settings.lastName}` : ""); // deprecated, pre v 0.1.3 (settings.lastName ? ` ${settings.lastName}` : ""); // deprecated, pre v 0.1.3
} }
async onClickSaveChanges() { async onClickSaveChanges() {

View File

@@ -105,13 +105,11 @@
<span class="col-span-1 w-full flex justify-center">{{ zoneName }}</span> <span class="col-span-1 w-full flex justify-center">{{ zoneName }}</span>
</div> </div>
<div class="flex items-center mb-4"> <div
<input class="flex items-center mb-4"
type="checkbox" @click="includeLocation = !includeLocation"
class="mr-2" >
v-model="includeLocation" <input type="checkbox" class="mr-2" v-model="includeLocation" />
@click="includeLocation = !includeLocation"
/>
<label for="includeLocation">Include Location</label> <label for="includeLocation">Include Location</label>
</div> </div>
<div v-if="includeLocation" class="mb-4 aspect-video"> <div v-if="includeLocation" class="mb-4 aspect-video">
@@ -145,6 +143,22 @@
</l-map> </l-map>
</div> </div>
<div
v-if="showGeneralAdvanced && includeLocation"
class="items-center mb-4"
>
<div class="flex" @click="sendToTrustroots = !sendToTrustroots">
<input type="checkbox" class="mr-2" v-model="sendToTrustroots" />
<label>Send to Trustroots</label>
</div>
<!--
<div class="flex" @click="sendToTripHopping = !sendToTripHopping">
<input type="checkbox" class="mr-2" v-model="sendToTripHopping" />
<label>Send to TripHopping</label>
</div>
-->
</div>
<div class="mt-8"> <div class="mt-8">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-2"> <div class="grid grid-cols-1 sm:grid-cols-2 gap-2">
<button <button
@@ -178,28 +192,35 @@
import "leaflet/dist/leaflet.css"; import "leaflet/dist/leaflet.css";
import { AxiosError, AxiosRequestHeaders } from "axios"; import { AxiosError, AxiosRequestHeaders } from "axios";
import { DateTime } from "luxon"; import { DateTime } from "luxon";
import { hexToBytes } from "@noble/hashes/utils";
import type { EventTemplate, VerifiedEvent } from "nostr-tools/lib/types/core";
import { accountFromSeedWords } from "nostr-tools/nip06";
import { finalizeEvent, serializeEvent } from "nostr-tools/pure";
import { Component, Vue } from "vue-facing-decorator"; import { Component, Vue } from "vue-facing-decorator";
import { LMap, LMarker, LTileLayer } from "@vue-leaflet/vue-leaflet"; import { LMap, LMarker, LTileLayer } from "@vue-leaflet/vue-leaflet";
import { Router } from "vue-router"; import { RouteLocationNormalizedLoaded, Router } from "vue-router";
import ImageMethodDialog from "@/components/ImageMethodDialog.vue"; import ImageMethodDialog from "@/components/ImageMethodDialog.vue";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import { DEFAULT_IMAGE_API_SERVER, NotificationIface } from "@/constants/app"; import {
import { accountsDB, db } from "@/db/index"; DEFAULT_IMAGE_API_SERVER,
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; DEFAULT_PARTNER_API_SERVER,
NotificationIface,
} from "@/constants/app";
import { accountsDB, retrieveSettingsForActiveAccount } from "@/db/index";
import { import {
createEndorserJwtVcFromClaim, createEndorserJwtVcFromClaim,
getHeaders, getHeaders,
PlanVerifiableCredential, PlanVerifiableCredential,
} from "@/libs/endorserServer"; } from "@/libs/endorserServer";
import { useAppStore } from "@/store/app"; import { getAccount } from "@/libs/util";
@Component({ @Component({
components: { ImageMethodDialog, LMap, LMarker, LTileLayer, QuickNav }, components: { ImageMethodDialog, LMap, LMarker, LTileLayer, QuickNav },
}) })
export default class NewEditProjectView extends Vue { export default class NewEditProjectView extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void; $notify!: (notification: NotificationIface, timeout?: number) => void;
errNote(message) { errNote(message: string) {
this.$notify( this.$notify(
{ group: "alert", type: "danger", title: "Error", text: message }, { group: "alert", type: "danger", title: "Error", text: message },
5000, 5000,
@@ -224,8 +245,11 @@ export default class NewEditProjectView extends Vue {
latitude = 0; latitude = 0;
longitude = 0; longitude = 0;
numAccounts = 0; numAccounts = 0;
projectId = localStorage.getItem("projectId") || ""; projectId = "";
projectIssuerDid = ""; projectIssuerDid = "";
sendToTrustroots = false;
sendToTripHopping = false;
showGeneralAdvanced = false;
startDateInput?: string; startDateInput?: string;
startTimeInput?: string; startTimeInput?: string;
zoneName = DateTime.local().zoneName; zoneName = DateTime.local().zoneName;
@@ -235,10 +259,13 @@ export default class NewEditProjectView extends Vue {
await accountsDB.open(); await accountsDB.open();
this.numAccounts = await accountsDB.accounts.count(); this.numAccounts = await accountsDB.accounts.count();
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); this.activeDid = settings.activeDid || "";
this.activeDid = (settings?.activeDid as string) || ""; this.apiServer = settings.apiServer || "";
this.apiServer = (settings?.apiServer as string) || ""; this.showGeneralAdvanced = !!settings.showGeneralAdvanced;
this.projectId =
(this.$route as RouteLocationNormalizedLoaded).query["projectId"] || "";
if (this.projectId) { if (this.projectId) {
if (this.numAccounts === 0) { if (this.numAccounts === 0) {
@@ -357,7 +384,7 @@ export default class NewEditProjectView extends Vue {
} }
} }
private async saveProject(issuerDid: string) { private async saveProject() {
// Make a claim // Make a claim
const vcClaim: PlanVerifiableCredential = this.fullClaim; const vcClaim: PlanVerifiableCredential = this.fullClaim;
if (this.projectId) { if (this.projectId) {
@@ -408,24 +435,44 @@ export default class NewEditProjectView extends Vue {
} else { } else {
delete vcClaim.startTime; delete vcClaim.startTime;
} }
const vcJwt = await createEndorserJwtVcFromClaim(issuerDid, vcClaim); const vcJwt = await createEndorserJwtVcFromClaim(this.activeDid, vcClaim);
// Make the xhr request payload // Make the xhr request payload
const payload = JSON.stringify({ jwtEncoded: vcJwt }); const payload = JSON.stringify({ jwtEncoded: vcJwt });
const url = this.apiServer + "/api/v2/claim"; const url = this.apiServer + "/api/v2/claim";
const headers = await getHeaders(issuerDid); const headers = await getHeaders(this.activeDid);
try { try {
const resp = await this.axios.post(url, payload, { headers }); const resp = await this.axios.post(url, payload, { headers });
if (resp.data?.success?.handleId) { if (resp.data?.success?.handleId) {
this.errorMessage = ""; this.errorMessage = "";
useAppStore() const projectPath = encodeURIComponent(resp.data.success.handleId);
.setProjectId(resp.data.success.handleId)
.then(() => { let signedPayload: VerifiedEvent | undefined; // sign something to prove ownership of pubkey
(this.$router as Router).push({ name: "project" }); if (this.sendToTrustroots) {
}); signedPayload = await this.signPayload();
this.sendToNostrPartner(
"NOSTR-EVENT-TRUSTROOTS",
"Trustroots",
resp.data.success.claimId,
signedPayload,
);
}
if (this.sendToTripHopping) {
if (!signedPayload) {
signedPayload = await this.signPayload();
}
this.sendToNostrPartner(
"NOSTR-EVENT-TRIPHOPPING",
"TripHopping",
resp.data.success.claimId,
signedPayload,
);
}
(this.$router as Router).push({ path: "/project/" + projectPath });
} else { } else {
console.error( console.error(
"Got unexpected 'data' inside response from server", "Got unexpected 'data' inside response from server",
@@ -489,6 +536,120 @@ export default class NewEditProjectView extends Vue {
} }
} }
private async signPayload(): Promise<VerifiedEvent> {
const account = await getAccount(this.activeDid);
// get the last number of the derivationPath
const finalDerNum = account?.derivationPath?.split?.("/")?.reverse()[0];
// remove any trailing '
const finalDerNumNoApostrophe = finalDerNum?.replace(/'/g, "");
const accountNum = Number(finalDerNumNoApostrophe || 0);
const pubPri = accountFromSeedWords(
account?.mnemonic as string,
"",
accountNum,
);
const privateBytes = hexToBytes(pubPri?.privateKey);
// No real content is necessary, we just want something signed,
// so we might as well use nostr libs for nostr functions.
// Besides: someday we may create real content that we can relay.
const event: EventTemplate = {
kind: 30402,
tags: [[]],
content: "",
created_at: 0,
};
// Why does IntelliJ not see matching types?
const signedEvent = finalizeEvent(event, privateBytes);
return signedEvent;
}
private async sendToNostrPartner(
linkCode: string,
serviceName: string,
jwtId: string,
signedPayload: VerifiedEvent,
) {
// first, get the public key for nostr
const account = await getAccount(this.activeDid);
// get the last number of the derivationPath
const finalDerNum = account?.derivationPath?.split?.("/")?.reverse()[0];
// remove any trailing '
const finalDerNumNoApostrophe = finalDerNum?.replace(/'/g, "");
const accountNum = Number(finalDerNumNoApostrophe || 0);
const pubPri = accountFromSeedWords(
account?.mnemonic as string,
"",
accountNum,
);
const nostrPubKey = pubPri?.publicKey;
let partnerServer = DEFAULT_PARTNER_API_SERVER;
const settings = await retrieveSettingsForActiveAccount();
if (settings.partnerApiServer) {
partnerServer = settings.partnerApiServer;
}
const trustrootsUrl = partnerServer + "/api/partner/link";
const timeSafariUrl = window.location.origin + "/claim/" + jwtId;
const content = this.fullClaim.name + " - see " + timeSafariUrl;
// Why does IntelliJ not see matching types?
const payload = serializeEvent(signedPayload);
const trustrootsParams = {
jwtId: jwtId,
linkCode: linkCode,
inputJson: JSON.stringify(content),
pubKeyHex: nostrPubKey,
pubKeyImage: payload,
pubKeySigHex: signedPayload.sig,
};
const fullTrustrootsUrl = trustrootsUrl;
const headers = await getHeaders(this.activeDid);
try {
const linkResp = await this.axios.post(
fullTrustrootsUrl,
trustrootsParams,
{ headers },
);
if (linkResp.status === 201) {
this.$notify(
{
group: "alert",
type: "success",
title: `Sent to ${serviceName}`,
text: `The project info was sent to ${serviceName}.`,
},
5000,
);
} else {
// axios never gets here because it throws an error, but just in case
this.$notify(
{
group: "alert",
type: "danger",
title: `Failed Sending to ${serviceName}`,
text: JSON.stringify(linkResp.data),
},
5000,
);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
console.error(`Error sending to ${serviceName}`, error);
let errorMessage = `There was an error sending to ${serviceName}.`;
if (error.response?.data?.error?.message) {
errorMessage = error.response.data.error.message;
}
this.$notify(
{
group: "alert",
type: "danger",
title: `Error Sending to ${serviceName}`,
text: errorMessage,
},
5000,
);
}
}
public async onSaveProjectClick() { public async onSaveProjectClick() {
this.isHiddenSave = true; this.isHiddenSave = true;
this.isHiddenSpinner = false; this.isHiddenSpinner = false;
@@ -496,7 +657,7 @@ export default class NewEditProjectView extends Vue {
if (this.numAccounts === 0) { if (this.numAccounts === 0) {
console.error("Error: there is no account."); console.error("Error: there is no account.");
} else { } else {
this.saveProject(this.activeDid); this.saveProject();
} }
} }

View File

@@ -22,8 +22,8 @@
</div> </div>
<div class="flex justify-center py-12"> <div class="flex justify-center py-12">
<span /> <div />
<span v-if="loading"> <div v-if="loading">
<span class="text-xl">Creating...&nbsp;</span> <span class="text-xl">Creating...&nbsp;</span>
<fa <fa
icon="spinner" icon="spinner"
@@ -31,8 +31,8 @@
color="green" color="green"
size="128" size="128"
></fa> ></fa>
</span> </div>
<span v-else> <div v-else>
<span class="text-xl">Created!</span> <span class="text-xl">Created!</span>
<fa <fa
icon="burst" icon="burst"
@@ -45,8 +45,8 @@
--fa-beat-scale: 6; --fa-beat-scale: 6;
" "
></fa> ></fa>
</span> </div>
<span /> <div />
</div> </div>
</section> </section>
</template> </template>

View File

@@ -35,7 +35,7 @@
<textarea <textarea
class="block w-full rounded border border-slate-400 mb-2 px-3 py-2" class="block w-full rounded border border-slate-400 mb-2 px-3 py-2"
placeholder="What is offered" placeholder="What is offered"
v-model="itemDescription" v-model="descriptionOfItem"
data-testId="itemDescription" data-testId="itemDescription"
/> />
<div class="flex flex-row justify-center"> <div class="flex flex-row justify-center">
@@ -74,7 +74,7 @@
<textarea <textarea
class="w-full border border-slate-400 px-3 py-2 rounded-r" class="w-full border border-slate-400 px-3 py-2 rounded-r"
placeholder="Prerequisites, other people to include, etc." placeholder="Prerequisites, other people to include, etc."
v-model="conditionDescription" v-model="descriptionOfCondition"
/> />
</div> </div>
@@ -135,7 +135,7 @@
</label> </label>
</div> </div>
<div class="mt-4 flex"> <div v-if="showGeneralAdvanced" class="mt-4 flex">
<router-link <router-link
:to="{ :to="{
name: 'claim-add-raw', name: 'claim-add-raw',
@@ -181,8 +181,7 @@ import { Router } from "vue-router";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import TopMessage from "@/components/TopMessage.vue"; import TopMessage from "@/components/TopMessage.vue";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
import { import {
createAndSubmitOffer, createAndSubmitOffer,
didInfo, didInfo,
@@ -208,20 +207,21 @@ export default class OfferDetailsView extends Vue {
apiServer = ""; apiServer = "";
amountInput = "0"; amountInput = "0";
conditionDescription = ""; descriptionOfCondition = "";
itemDescription = ""; descriptionOfItem = "";
destinationPathAfter = ""; destinationPathAfter = "";
hideBackButton = false;
message = "";
offeredToProject = false; offeredToProject = false;
offeredToRecipient = false; offeredToRecipient = false;
offererDid: string | undefined; offererDid: string | undefined;
hideBackButton = false;
message = "";
offerId = ""; offerId = "";
prevCredToEdit?: GenericCredWrapper<OfferVerifiableCredential>; prevCredToEdit?: GenericCredWrapper<OfferVerifiableCredential>;
projectId = ""; projectId = "";
projectName = "a project"; projectName = "a project";
recipientDid = ""; recipientDid = "";
recipientName = ""; recipientName = "";
showGeneralAdvanced = false;
unitCode = "HUR"; unitCode = "HUR";
validThroughDateInput = ""; validThroughDateInput = "";
@@ -256,12 +256,12 @@ export default class OfferDetailsView extends Vue {
this.prevCredToEdit?.claim?.includesObject?.unitCode || this.prevCredToEdit?.claim?.includesObject?.unitCode ||
this.unitCode) as string; this.unitCode) as string;
this.conditionDescription = this.descriptionOfCondition =
this.prevCredToEdit?.claim?.description || this.conditionDescription; this.prevCredToEdit?.claim?.description || this.descriptionOfCondition;
this.itemDescription = this.descriptionOfItem =
(this.$route as Router).query["description"] || (this.$route as Router).query["description"] ||
this.prevCredToEdit?.claim?.itemOffered?.description || this.prevCredToEdit?.claim?.itemOffered?.description ||
this.itemDescription; this.descriptionOfItem;
this.destinationPathAfter = (this.$route as Router).query[ this.destinationPathAfter = (this.$route as Router).query[
"destinationPathAfter" "destinationPathAfter"
]; ];
@@ -296,10 +296,10 @@ export default class OfferDetailsView extends Vue {
this.prevCredToEdit?.claim?.validThrough || this.validThroughDateInput; this.prevCredToEdit?.claim?.validThrough || this.validThroughDateInput;
try { try {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; this.apiServer = settings.apiServer ?? "";
this.apiServer = settings?.apiServer || ""; this.activeDid = settings.activeDid ?? "";
this.activeDid = settings?.activeDid || ""; this.showGeneralAdvanced = settings.showGeneralAdvanced ?? false;
let allContacts: Contact[] = []; let allContacts: Contact[] = [];
let allMyDids: string[] = []; let allMyDids: string[] = [];
@@ -402,7 +402,7 @@ export default class OfferDetailsView extends Vue {
); );
return; return;
} }
if (!this.itemDescription && !parseFloat(this.amountInput)) { if (!this.descriptionOfItem && !parseFloat(this.amountInput)) {
this.$notify( this.$notify(
{ {
group: "alert", group: "alert",
@@ -502,10 +502,10 @@ export default class OfferDetailsView extends Vue {
this.apiServer, this.apiServer,
this.prevCredToEdit, this.prevCredToEdit,
this.activeDid, this.activeDid,
this.itemDescription, this.descriptionOfItem,
parseFloat(this.amountInput), parseFloat(this.amountInput),
this.unitCode, this.unitCode,
this.conditionDescription, this.descriptionOfCondition,
this.validThroughDateInput, this.validThroughDateInput,
recipientDid, recipientDid,
projectId, projectId,
@@ -515,10 +515,10 @@ export default class OfferDetailsView extends Vue {
this.axios, this.axios,
this.apiServer, this.apiServer,
this.activeDid, this.activeDid,
this.itemDescription, this.descriptionOfItem,
parseFloat(this.amountInput), parseFloat(this.amountInput),
this.unitCode, this.unitCode,
this.conditionDescription, this.descriptionOfCondition,
this.validThroughDateInput, this.validThroughDateInput,
recipientDid, recipientDid,
projectId, projectId,
@@ -582,10 +582,10 @@ export default class OfferDetailsView extends Vue {
this.prevCredToEdit?.claim as OfferVerifiableCredential, this.prevCredToEdit?.claim as OfferVerifiableCredential,
this.activeDid, this.activeDid,
recipientDid, recipientDid,
this.itemDescription, this.descriptionOfItem,
parseFloat(this.amountInput), parseFloat(this.amountInput),
this.unitCode, this.unitCode,
this.conditionDescription, this.descriptionOfCondition,
projectId, projectId,
this.validThroughDateInput, this.validThroughDateInput,
this.prevCredToEdit?.id as string, this.prevCredToEdit?.id as string,

View File

@@ -220,7 +220,10 @@
</li> </li>
</ul> </ul>
<!-- Ideally, this button should only be visible when the active account has more than 7 or 11 contacts in their list (we want to limit the grid count above to 8 or 12 accounts to keep it compact) --> <!--
Ideally, this button should only be visible when the active account has more than 7 or 11 contacts in their list
(we want to limit the grid count above to 8 or 12 accounts to keep it compact)
-->
<a <a
v-if="allContacts.length >= 7" v-if="allContacts.length >= 7"
@click="onClickAllContactsGifting()" @click="onClickAllContactsGifting()"
@@ -382,7 +385,7 @@
<span> <span>
{{ {{
serverUtil.didInfo( serverUtil.didInfo(
give.agentDid, give.recipientDid,
activeDid, activeDid,
allMyDids, allMyDids,
allContacts, allContacts,
@@ -431,16 +434,14 @@ import QuickNav from "@/components/QuickNav.vue";
import EntityIcon from "@/components/EntityIcon.vue"; import EntityIcon from "@/components/EntityIcon.vue";
import ProjectIcon from "@/components/ProjectIcon.vue"; import ProjectIcon from "@/components/ProjectIcon.vue";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { Account } from "@/db/tables/accounts"; import { Account } from "@/db/tables/accounts";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
import * as libsUtil from "@/libs/util"; import * as libsUtil from "@/libs/util";
import { import {
BLANK_GENERIC_SERVER_RECORD, BLANK_GENERIC_SERVER_RECORD,
GenericCredWrapper, GenericCredWrapper,
getHeaders, getHeaders,
GiverReceiverInputInfo,
GiveSummaryRecord, GiveSummaryRecord,
GiveVerifiableCredential, GiveVerifiableCredential,
OfferSummaryRecord, OfferSummaryRecord,
@@ -484,7 +485,7 @@ export default class ProjectViewView extends Vue {
name = ""; name = "";
offersToThis: Array<OfferSummaryRecord> = []; offersToThis: Array<OfferSummaryRecord> = [];
offersHitLimit = false; offersHitLimit = false;
projectId = localStorage.getItem("projectId") || ""; // handle ID projectId = ""; // handle ID
showDidCopy = false; showDidCopy = false;
startTime = ""; startTime = "";
truncatedDesc = ""; truncatedDesc = "";
@@ -495,12 +496,11 @@ export default class ProjectViewView extends Vue {
serverUtil = serverUtil; serverUtil = serverUtil;
async created() { async created() {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; this.activeDid = settings.activeDid || "";
this.activeDid = settings?.activeDid || ""; this.apiServer = settings.apiServer || "";
this.apiServer = settings?.apiServer || "";
this.allContacts = await db.contacts.toArray(); this.allContacts = await db.contacts.toArray();
this.isRegistered = !!settings?.isRegistered; this.isRegistered = !!settings.isRegistered;
await accountsDB.open(); await accountsDB.open();
const accounts = accountsDB.accounts; const accounts = accountsDB.accounts;
@@ -515,9 +515,9 @@ export default class ProjectViewView extends Vue {
} }
onEditClick() { onEditClick() {
localStorage.setItem("projectId", this.projectId as string);
const route = { const route = {
name: "new-edit-project", name: "new-edit-project",
query: { projectId: this.projectId },
}; };
(this.$router as Router).push(route); (this.$router as Router).push(route);
} }
@@ -566,35 +566,22 @@ export default class ProjectViewView extends Vue {
group: "alert", group: "alert",
type: "danger", type: "danger",
title: "Error", title: "Error",
text: "There was a problem getting that project. See logs for more info.", text: "There was a problem getting that project.",
}, },
5000, 5000,
); );
} }
} catch (error: unknown) { } catch (error: unknown) {
console.error("Error retrieving project:", error); console.error("Error retrieving project:", error);
const serverError = error as AxiosError; this.$notify(
if (serverError.response?.status === 404) { {
this.$notify( group: "alert",
{ type: "danger",
group: "alert", title: "Error",
type: "danger", text: "Something went wrong retrieving that project.",
title: "Error", },
text: "That project does not exist.", 5000,
}, );
5000,
);
} else {
this.$notify(
{
group: "alert",
type: "danger",
title: "Error",
text: "Something went wrong retrieving that project. See logs for more info.",
},
5000,
);
}
} }
this.loadGives(); this.loadGives();
@@ -839,7 +826,6 @@ export default class ProjectViewView extends Vue {
* @param id of the project * @param id of the project
**/ **/
async onClickLoadProject(projectId: string) { async onClickLoadProject(projectId: string) {
localStorage.setItem("projectId", projectId);
const route = { const route = {
path: "/project/" + encodeURIComponent(projectId), path: "/project/" + encodeURIComponent(projectId),
}; };
@@ -861,7 +847,7 @@ export default class ProjectViewView extends Vue {
); );
} }
openGiftDialog(contact?: GiverReceiverInputInfo) { openGiftDialog(contact?: libsUtil.GiverReceiverInputInfo) {
(this.$refs.customGiveDialog as GiftedDialog).open( (this.$refs.customGiveDialog as GiftedDialog).open(
contact, contact,
undefined, undefined,
@@ -875,9 +861,11 @@ export default class ProjectViewView extends Vue {
} }
onClickAllContactsGifting() { onClickAllContactsGifting() {
localStorage.setItem("projectId", this.projectId);
const route = { const route = {
name: "contact-gift", name: "contact-gift",
query: {
projectId: this.projectId,
},
}; };
(this.$router as Router).push(route); (this.$router as Router).push(route);
} }
@@ -905,7 +893,7 @@ export default class ProjectViewView extends Vue {
claim: offer.fullClaim, claim: offer.fullClaim,
issuer: offer.offeredByDid, issuer: offer.offeredByDid,
}; };
const giver: GiverReceiverInputInfo = { const giver: libsUtil.GiverReceiverInputInfo = {
did: libsUtil.offerGiverDid(offerRecord), did: libsUtil.offerGiverDid(offerRecord),
}; };
(this.$refs.customGiveDialog as GiftedDialog).open( (this.$refs.customGiveDialog as GiftedDialog).open(
@@ -1010,7 +998,7 @@ export default class ProjectViewView extends Vue {
console.error("Got error submitting the confirmation:", result); console.error("Got error submitting the confirmation:", result);
const message = const message =
(result.error?.error as string) || (result.error?.error as string) ||
"There was a problem submitting the confirmation. See logs for more info."; "There was a problem submitting the confirmation.";
this.$notify( this.$notify(
{ {
group: "alert", group: "alert",

View File

@@ -1,15 +1,15 @@
<template> <template>
<QuickNav selected="Projects"></QuickNav> <QuickNav selected="Projects" />
<TopMessage /> <TopMessage />
<section id="Content" class="p-6 pb-24 max-w-3xl mx-auto"> <section id="Content" class="p-6 pb-24 max-w-3xl mx-auto">
<!-- Heading --> <!-- Heading -->
<h1 id="ViewHeading" class="text-4xl text-center font-light pt-4 mb-8"> <h1 id="ViewHeading" class="text-4xl text-center font-light">Your Ideas</h1>
Your Ideas
</h1> <OnboardingDialog ref="onboardingDialog" />
<!-- Result Tabs --> <!-- Result Tabs -->
<div class="text-center text-slate-500 border-b border-slate-300"> <div class="text-center text-slate-500 border-b border-slate-300 mt-8">
<ul class="flex flex-wrap justify-center gap-4 -mb-px"> <ul class="flex flex-wrap justify-center gap-4 -mb-px">
<li> <li>
<a <a
@@ -63,7 +63,7 @@
<!-- New Project --> <!-- New Project -->
<button <button
v-if="isRegistered && showProjects" v-if="isRegistered && showProjects"
class="fixed right-6 top-24 text-center text-4xl leading-none bg-blue-600 text-white w-14 py-2.5 rounded-full" class="fixed right-6 top-24 text-center text-4xl leading-none bg-green-600 text-white w-14 py-2.5 rounded-full"
@click="onClickNewProject()" @click="onClickNewProject()"
> >
<fa icon="plus" class="fa-fw"></fa> <fa icon="plus" class="fa-fw"></fa>
@@ -152,7 +152,10 @@
<span <span
v-if="offer.amountGivenConfirmed >= offer.amountGiven" v-if="offer.amountGivenConfirmed >= offer.amountGiven"
> >
<!-- no need for green icon; unnecessary if there's already a green, confusing if there's a yellow --> <!--
There's no need for a green icon:
it's unnecessary if there's already a green, and confusing if there's a yellow.
-->
all all
</span> </span>
<span v-else> <span v-else>
@@ -206,10 +209,19 @@
Hit the big Hit the big
<fa <fa
icon="plus" icon="plus"
class="bg-blue-600 text-white px-1 py-1 rounded-full" class="bg-green-600 text-white px-1.5 py-1 rounded-full"
/> />
button. You'll never know until you try. button. You'll never know until you try.
</div> </div>
<div v-else>
<button
@click="showNameThenIdDialog()"
class="text-md font-bold bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white mt-2 px-2 py-3 rounded-md"
>
Get someone to onboard you.
</button>
<UserNameDialog ref="userNameDialog" />
</div>
</div> </div>
<ul id="listProjects" class="border-t border-slate-300"> <ul id="listProjects" class="border-t border-slate-300">
<li <li
@@ -249,13 +261,16 @@ import { Component, Vue } from "vue-facing-decorator";
import { Router } from "vue-router"; import { Router } from "vue-router";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import * as libsUtil from "@/libs/util"; import * as libsUtil from "@/libs/util";
import EntityIcon from "@/components/EntityIcon.vue";
import InfiniteScroll from "@/components/InfiniteScroll.vue"; import InfiniteScroll from "@/components/InfiniteScroll.vue";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import OnboardingDialog from "@/components/OnboardingDialog.vue";
import ProjectIcon from "@/components/ProjectIcon.vue"; import ProjectIcon from "@/components/ProjectIcon.vue";
import TopMessage from "@/components/TopMessage.vue"; import TopMessage from "@/components/TopMessage.vue";
import UserNameDialog from "@/components/UserNameDialog.vue";
import { Contact } from "@/db/tables/contacts";
import { import {
didInfo, didInfo,
getHeaders, getHeaders,
@@ -263,11 +278,18 @@ import {
OfferSummaryRecord, OfferSummaryRecord,
PlanData, PlanData,
} from "@/libs/endorserServer"; } from "@/libs/endorserServer";
import EntityIcon from "@/components/EntityIcon.vue"; import { OnboardPage } from "@/libs/util";
import { Contact } from "@/db/tables/contacts";
@Component({ @Component({
components: { EntityIcon, InfiniteScroll, QuickNav, ProjectIcon, TopMessage }, components: {
EntityIcon,
InfiniteScroll,
QuickNav,
OnboardingDialog,
ProjectIcon,
TopMessage,
UserNameDialog,
},
}) })
export default class ProjectsView extends Vue { export default class ProjectsView extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void; $notify!: (notification: NotificationIface, timeout?: number) => void;
@@ -282,24 +304,25 @@ export default class ProjectsView extends Vue {
allContacts: Array<Contact> = []; allContacts: Array<Contact> = [];
allMyDids: Array<string> = []; allMyDids: Array<string> = [];
apiServer = ""; apiServer = "";
projects: PlanData[] = []; givenName = "";
isLoading = false; isLoading = false;
isRegistered = false; isRegistered = false;
offers: OfferSummaryRecord[] = []; offers: OfferSummaryRecord[] = [];
projectNameFromHandleId: Record<string, string> = {}; // mapping from handleId to description projectNameFromHandleId: Record<string, string> = {}; // mapping from handleId to description
showOffers = true; projects: PlanData[] = [];
showProjects = false; showOffers = false;
showProjects = true;
libsUtil = libsUtil; libsUtil = libsUtil;
didInfo = didInfo; didInfo = didInfo;
async mounted() { async mounted() {
try { try {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); this.activeDid = settings.activeDid || "";
this.activeDid = (settings?.activeDid as string) || ""; this.apiServer = settings.apiServer || "";
this.apiServer = (settings?.apiServer as string) || ""; this.isRegistered = !!settings.isRegistered;
this.isRegistered = !!settings?.isRegistered; this.givenName = settings.firstName || "";
this.allContacts = await db.contacts.toArray(); this.allContacts = await db.contacts.toArray();
@@ -307,11 +330,17 @@ export default class ProjectsView extends Vue {
const allAccounts = await accountsDB.accounts.toArray(); const allAccounts = await accountsDB.accounts.toArray();
this.allMyDids = allAccounts.map((acc) => acc.did); this.allMyDids = allAccounts.map((acc) => acc.did);
if (!settings.finishedOnboarding) {
(this.$refs.onboardingDialog as OnboardingDialog).open(
OnboardPage.Create,
);
}
if (allAccounts.length === 0) { if (allAccounts.length === 0) {
console.error("No accounts found."); console.error("No accounts found.");
this.errNote("You need an identifier to load your projects."); this.errNote("You need an identifier to load your projects.");
} else { } else {
await this.loadOffers(); await this.loadProjects();
} }
} catch (err) { } catch (err) {
console.error("Error initializing:", err); console.error("Error initializing:", err);
@@ -385,7 +414,6 @@ export default class ProjectsView extends Vue {
* @param id of the project * @param id of the project
**/ **/
onClickLoadProject(id: string) { onClickLoadProject(id: string) {
localStorage.setItem("projectId", id);
const route = { const route = {
path: "/project/" + encodeURIComponent(id), path: "/project/" + encodeURIComponent(id),
}; };
@@ -396,7 +424,6 @@ export default class ProjectsView extends Vue {
* Handling clicking on the new project button * Handling clicking on the new project button
**/ **/
onClickNewProject(): void { onClickNewProject(): void {
localStorage.removeItem("projectId");
const route = { const route = {
name: "new-edit-project", name: "new-edit-project",
}; };
@@ -432,18 +459,8 @@ export default class ProjectsView extends Vue {
this.activeDid, this.activeDid,
); );
const projectName = project?.name as string; const projectName = project?.name as string;
console.log(
"now have name for",
offer.fulfillsPlanHandleId,
projectName,
);
this.projectNameFromHandleId[offer.fulfillsPlanHandleId] = this.projectNameFromHandleId[offer.fulfillsPlanHandleId] =
projectName; projectName;
console.log(
"now have a real name for",
offer.fulfillsPlanHandleId,
this.projectNameFromHandleId[offer.fulfillsPlanHandleId],
);
} }
this.offers = this.offers.concat([offer]); this.offers = this.offers.concat([offer]);
} }
@@ -501,6 +518,37 @@ export default class ProjectsView extends Vue {
await this.offerDataLoader(url); await this.offerDataLoader(url);
} }
showNameThenIdDialog() {
if (!this.givenName) {
(this.$refs.userNameDialog as UserNameDialog).open(() => {
this.promptForShareMethod();
});
} else {
this.promptForShareMethod();
}
}
promptForShareMethod() {
this.$notify(
{
group: "modal",
type: "confirm",
title: "Are you nearby with cameras?",
text: "If so, we'll use those with QR codes to share.",
onCancel: async () => {},
onNo: async () => {
(this.$router as Router).push({ name: "share-my-contact-info" });
},
onYes: async () => {
(this.$router as Router).push({ name: "contact-qr" });
},
noText: "we will share another way",
yesText: "we are nearby with cameras",
},
-1,
);
}
public computedOfferTabClassNames() { public computedOfferTabClassNames() {
return { return {
"inline-block": true, "inline-block": true,

View File

@@ -67,12 +67,13 @@
<script lang="ts"> <script lang="ts">
import axios from "axios"; import axios from "axios";
import { DateTime } from "luxon"; import { DateTime } from "luxon";
import { Router } from "vue-router";
import { Component, Vue } from "vue-facing-decorator"; import { Component, Vue } from "vue-facing-decorator";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import TopMessage from "@/components/TopMessage.vue"; import TopMessage from "@/components/TopMessage.vue";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { db } from "@/db/index"; import { retrieveSettingsForActiveAccount } from "@/db/index";
import { import {
BVC_MEETUPS_PROJECT_CLAIM_ID, BVC_MEETUPS_PROJECT_CLAIM_ID,
bvcMeetingJoinClaim, bvcMeetingJoinClaim,
@@ -80,7 +81,6 @@ import {
createAndSubmitGive, createAndSubmitGive,
} from "@/libs/endorserServer"; } from "@/libs/endorserServer";
import * as libsUtil from "@/libs/util"; import * as libsUtil from "@/libs/util";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
@Component({ @Component({
components: { components: {
@@ -117,10 +117,9 @@ export default class QuickActionBvcBeginView extends Vue {
} }
async record() { async record() {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; const activeDid = settings.activeDid || "";
const activeDid = settings?.activeDid || ""; const apiServer = settings.apiServer || "";
const apiServer = settings?.apiServer || "";
try { try {
const hoursNum = libsUtil.numberOrZero(this.hoursStr); const hoursNum = libsUtil.numberOrZero(this.hoursStr);
@@ -202,6 +201,7 @@ export default class QuickActionBvcBeginView extends Vue {
}, },
3000, 3000,
); );
(this.$router as Router).push({ path: "/quick-action-bvc" });
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any

View File

@@ -97,7 +97,7 @@
<h2 class="text-2xl m-2">Anything else?</h2> <h2 class="text-2xl m-2">Anything else?</h2>
<div class="m-2 flex"> <div class="m-2 flex">
<input type="checkbox" v-model="someoneGave" class="h-6 w-6" /> <input type="checkbox" v-model="someoneGave" class="h-6 w-6" />
<span class="pb-2 pl-2 pr-2">Someone else gave</span> <span class="pb-2 pl-2 pr-2">The group provided</span>
<span v-if="someoneGave"> <span v-if="someoneGave">
<input <input
type="text" type="text"
@@ -106,7 +106,8 @@
class="border border-slate-400 h-6 px-2" class="border border-slate-400 h-6 px-2"
/> />
<br /> <br />
(Everyone likes personalized messages! 😁) (Everyone likes personalized messages! 😁 ... and for a pic:
<input type="checkbox" v-model="supplyGiftDetails" />)
</span> </span>
<!-- This is to match input height to avoid shifting when hiding & showing. --> <!-- This is to match input height to avoid shifting when hiding & showing. -->
<span v-else class="h-6">...</span> <span v-else class="h-6">...</span>
@@ -144,9 +145,8 @@ import { Router } from "vue-router";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import TopMessage from "@/components/TopMessage.vue"; import TopMessage from "@/components/TopMessage.vue";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { Contact } from "@/db/tables/contacts"; import { Contact } from "@/db/tables/contacts";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
import { import {
BVC_MEETUPS_PROJECT_CLAIM_ID, BVC_MEETUPS_PROJECT_CLAIM_ID,
claimSpecialDescription, claimSpecialDescription,
@@ -180,17 +180,16 @@ export default class QuickActionBvcBeginView extends Vue {
description = "breakfast"; description = "breakfast";
loadingConfirms = true; loadingConfirms = true;
someoneGave = false; someoneGave = false;
supplyGiftDetails = false;
async created() { async created() {
await db.open();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings;
this.apiServer = settings?.apiServer || "";
this.activeDid = settings?.activeDid || "";
this.allContacts = await db.contacts.toArray();
}
async mounted() {
this.loadingConfirms = true; this.loadingConfirms = true;
const settings = await retrieveSettingsForActiveAccount();
this.apiServer = settings.apiServer || "";
this.activeDid = settings.activeDid || "";
this.allContacts = await db.contacts.toArray();
let currentOrPreviousSat = DateTime.now().setZone("America/Denver"); let currentOrPreviousSat = DateTime.now().setZone("America/Denver");
if (currentOrPreviousSat.weekday < 6) { if (currentOrPreviousSat.weekday < 6) {
// it's not Saturday or Sunday, // it's not Saturday or Sunday,
@@ -265,7 +264,9 @@ export default class QuickActionBvcBeginView extends Vue {
async record() { async record() {
try { try {
this.$notify({ group: "alert", type: "toast", title: "Sent..." }, 1000); if (this.claimsToConfirmSelected.length > 0) {
this.$notify({ group: "alert", type: "toast", title: "Sent..." }, 1000);
}
// in parallel, make a confirmation for each selected claim and send them all to the server // in parallel, make a confirmation for each selected claim and send them all to the server
const confirmResults = await Promise.allSettled( const confirmResults = await Promise.allSettled(
@@ -307,7 +308,7 @@ export default class QuickActionBvcBeginView extends Vue {
// now send the give for the description // now send the give for the description
let giveSucceeded = false; let giveSucceeded = false;
if (this.someoneGave) { if (this.someoneGave && !this.supplyGiftDetails) {
const giveResult = await createAndSubmitGive( const giveResult = await createAndSubmitGive(
axios, axios,
this.apiServer, this.apiServer,
@@ -317,6 +318,10 @@ export default class QuickActionBvcBeginView extends Vue {
this.description, this.description,
undefined, undefined,
undefined, undefined,
undefined,
undefined,
false,
undefined,
BVC_MEETUPS_PROJECT_CLAIM_ID, BVC_MEETUPS_PROJECT_CLAIM_ID,
); );
giveSucceeded = giveResult.type === "success"; giveSucceeded = giveResult.type === "success";
@@ -335,29 +340,60 @@ export default class QuickActionBvcBeginView extends Vue {
); );
} }
} }
if (this.someoneGave && this.supplyGiftDetails) {
if (confirmsSucceeded.length > 0 || giveSucceeded) { // we'll give a success message for the confirmations and go to the gifted details page
const confirms = if (confirmsSucceeded.length > 0) {
confirmsSucceeded.length === 1 ? "confirmation" : "confirmations"; const actions =
const actions = confirmsSucceeded.length === 1
confirmsSucceeded.length > 0 && giveSucceeded ? `Your confirmation has been recorded.`
? `Your ${confirms} and that give have been recorded.` : `Your confirmations have been recorded.`;
: giveSucceeded this.$notify(
? "That give has been recorded." {
: "Your " + group: "alert",
confirms + type: "success",
" " + title: "Success",
(confirmsSucceeded.length === 1 ? "has" : "have") + text: actions,
" been recorded."; },
this.$notify( 3000,
{ );
group: "alert", }
type: "success", (this.$router as Router).push({
title: "Success", name: "gifted-details",
text: actions, query: {
description: this.description,
destinationPathAfter: "/",
providerProjectId: BVC_MEETUPS_PROJECT_CLAIM_ID,
recipientDid: this.activeDid,
}, },
3000, });
); } else {
// just go ahead and print a message for all the activity
if (confirmsSucceeded.length > 0 || giveSucceeded) {
const confirms =
confirmsSucceeded.length === 1 ? "confirmation" : "confirmations";
const actions =
confirmsSucceeded.length > 0 && giveSucceeded
? `Your ${confirms} and that give have been recorded.`
: giveSucceeded
? "That give has been recorded."
: "Your " +
confirms +
" " +
(confirmsSucceeded.length === 1 ? "has" : "have") +
" been recorded.";
this.$notify(
{
group: "alert",
type: "success",
title: "Success",
text: actions,
},
3000,
);
(this.$router as Router).push({ path: "/" });
} else {
// errors should have already shown
}
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any

View File

@@ -0,0 +1,169 @@
<template>
<QuickNav selected="Home"></QuickNav>
<!-- CONTENT -->
<section id="Content" class="p-6 pb-24 max-w-3xl mx-auto">
<!-- Breadcrumb -->
<div id="ViewBreadcrumb" class="mb-8">
<h1 class="text-lg text-center font-light relative px-7">
<!-- Back -->
<fa
icon="chevron-left"
@click="$router.back()"
class="fa-fw text-lg text-center px-2 py-1 absolute -left-2 -top-1"
/>
Offers to Your Projects
</h1>
</div>
<div v-if="newOffersToUserProjects.length === 0">
<p>Nobody has given any offers to your projects.</p>
<p class="mt-2">
Maybe there are already some projects you can help on the
<router-link to="/discover" class="text-blue-500">
Discover page <fa icon="search" />
</router-link>
</p>
<p class="mt-2">
You can announce more of your own on
<router-link to="/contacts" class="text-blue-500">
Your Ideas page <fa icon="hand" />
</router-link>
</p>
</div>
<InfiniteScroll @reached-bottom="loadMoreOffersToUserProjects">
<ul
data-testId="listRecentOffersToUserProjects"
class="border-t border-slate-300"
>
<li
v-for="offer in newOffersToUserProjects"
:key="offer.jwtId"
class="mt-4 relative group"
>
<div
class="border-b border-slate-300 text-orange-400 pb-2 mb-2 font-bold text-sm"
v-if="offer.jwtId == lastAckedOfferToUserProjectsJwtId"
>
You've already seen all the following
</div>
<span>{{
didInfo(offer.offeredByDid, activeDid, allMyDids, allContacts)
}}</span>
offered
<span v-if="offer.objectDescription">{{
offer.objectDescription
}}</span
>{{ offer.objectDescription && offer.amount ? ", and " : "" }}
<span v-if="offer.amount">{{
displayAmount(offer.unit, offer.amount)
}}</span>
to
<span>{{ offer.planName }}</span>
<router-link
:to="{ path: '/claim/' + encodeURIComponent(offer.jwtId) }"
class="text-blue-500"
>
<fa icon="file-lines" class="pl-2 text-blue-500 cursor-pointer" />
</router-link>
</li>
</ul>
</InfiniteScroll>
</section>
</template>
<script lang="ts">
import { Component, Vue } from "vue-facing-decorator";
import EntityIcon from "@/components/EntityIcon.vue";
import GiftedDialog from "@/components/GiftedDialog.vue";
import InfiniteScroll from "@/components/InfiniteScroll.vue";
import QuickNav from "@/components/QuickNav.vue";
import { NotificationIface } from "@/constants/app";
import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { Contact } from "@/db/tables/contacts";
import {
didInfo,
displayAmount,
getNewOffersToUserProjects,
OfferToPlanSummaryRecord,
} from "@/libs/endorserServer";
@Component({
components: { EntityIcon, GiftedDialog, InfiniteScroll, QuickNav },
})
export default class RecentOffersToUserView extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void;
activeDid = "";
allContacts: Array<Contact> = [];
allMyDids: string[] = [];
apiServer = "";
lastAckedOfferToUserProjectsJwtId = "";
newOffersToUserProjects: Array<OfferToPlanSummaryRecord> = [];
newOffersToUserProjectsAtEnd = false;
showOffersDetails = false;
showOffersToUserProjectsDetails = false;
didInfo = didInfo;
displayAmount = displayAmount;
async created() {
try {
const settings = await retrieveSettingsForActiveAccount();
this.apiServer = settings.apiServer || "";
this.activeDid = settings.activeDid || "";
this.lastAckedOfferToUserProjectsJwtId =
settings.lastAckedOfferToUserProjectsJwtId || "";
this.allContacts = await db.contacts.toArray();
await accountsDB.open();
const allAccounts = await accountsDB.accounts.toArray();
if (allAccounts.length > 0) {
this.allMyDids = allAccounts.map((acc) => acc.did);
}
const offersToUserProjectsData = await getNewOffersToUserProjects(
this.axios,
this.apiServer,
this.activeDid,
undefined,
undefined,
);
this.newOffersToUserProjects = offersToUserProjectsData.data;
this.newOffersToUserProjectsAtEnd = !offersToUserProjectsData.hitLimit;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
console.error("Error retrieving settings & contacts:", err);
this.$notify(
{
group: "alert",
type: "danger",
title: "Error",
text: err.message || "There was an error retrieving your activity.",
},
5000,
);
}
}
async loadMoreOffersToUserProjects() {
if (this.newOffersToUserProjectsAtEnd) {
return;
}
const offersToUserProjectsData = await getNewOffersToUserProjects(
this.axios,
this.apiServer,
this.activeDid,
undefined,
this.newOffersToUserProjects[this.newOffersToUserProjects.length - 1]
.jwtId,
);
this.newOffersToUserProjects.push(...offersToUserProjectsData.data);
this.newOffersToUserProjectsAtEnd = !offersToUserProjectsData.hitLimit;
}
}
</script>

View File

@@ -0,0 +1,160 @@
<template>
<QuickNav selected="Home"></QuickNav>
<!-- CONTENT -->
<section id="Content" class="p-6 pb-24 max-w-3xl mx-auto">
<!-- Breadcrumb -->
<div id="ViewBreadcrumb" class="mb-8">
<h1 class="text-lg text-center font-light relative px-7">
<!-- Back -->
<fa
icon="chevron-left"
@click="$router.back()"
class="fa-fw text-lg text-center px-2 py-1 absolute -left-2 -top-1"
/>
Offers to You
</h1>
</div>
<div v-if="newOffersToUser.length === 0">
<p>Nobody has given you an offer.</p>
<p class="mt-2">
You can start the cycle on the
<router-link to="/contacts" class="text-blue-500">
Contacts page <fa icon="users" />
</router-link>
with an "Offer" directly to someone. Hopefully you'll find a common
interest!
</p>
</div>
<InfiniteScroll @reached-bottom="loadMoreOffersToUser">
<ul
data-testId="listRecentOffersToUser"
class="border-t border-slate-300"
>
<li
v-for="offer in newOffersToUser"
:key="offer.jwtId"
class="mt-4 relative group"
>
<div
class="border-b border-slate-300 text-orange-400 pb-2 mb-2 font-bold text-sm"
v-if="offer.jwtId == lastAckedOfferToUserJwtId"
>
You've already seen all the following
</div>
<span>{{
didInfo(offer.offeredByDid, activeDid, allMyDids, allContacts)
}}</span>
offered
<span v-if="offer.objectDescription">{{
offer.objectDescription
}}</span
>{{ offer.objectDescription && offer.amount ? ", and " : "" }}
<span v-if="offer.amount">{{
displayAmount(offer.unit, offer.amount)
}}</span>
<router-link
:to="{ path: '/claim/' + encodeURIComponent(offer.jwtId) }"
class="text-blue-500"
>
<fa icon="file-lines" class="pl-2 text-blue-500 cursor-pointer" />
</router-link>
</li>
</ul>
</InfiniteScroll>
</section>
</template>
<script lang="ts">
import { Component, Vue } from "vue-facing-decorator";
import GiftedDialog from "@/components/GiftedDialog.vue";
import EntityIcon from "@/components/EntityIcon.vue";
import InfiniteScroll from "@/components/InfiniteScroll.vue";
import QuickNav from "@/components/QuickNav.vue";
import { NotificationIface } from "@/constants/app";
import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { Contact } from "@/db/tables/contacts";
import {
didInfo,
displayAmount,
getNewOffersToUser,
OfferSummaryRecord,
} from "@/libs/endorserServer";
@Component({
components: { EntityIcon, GiftedDialog, InfiniteScroll, QuickNav },
})
export default class RecentOffersToUserView extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void;
activeDid = "";
allContacts: Array<Contact> = [];
allMyDids: string[] = [];
apiServer = "";
lastAckedOfferToUserJwtId = "";
newOffersToUser: Array<OfferSummaryRecord> = [];
newOffersToUserAtEnd = false;
showOffersDetails = false;
showOffersToUserProjectsDetails = false;
didInfo = didInfo;
displayAmount = displayAmount;
async created() {
try {
const settings = await retrieveSettingsForActiveAccount();
this.apiServer = settings.apiServer || "";
this.activeDid = settings.activeDid || "";
this.lastAckedOfferToUserJwtId = settings.lastAckedOfferToUserJwtId || "";
this.allContacts = await db.contacts.toArray();
await accountsDB.open();
const allAccounts = await accountsDB.accounts.toArray();
if (allAccounts.length > 0) {
this.allMyDids = allAccounts.map((acc) => acc.did);
}
const offersToUserData = await getNewOffersToUser(
this.axios,
this.apiServer,
this.activeDid,
undefined,
undefined,
);
this.newOffersToUser = offersToUserData.data;
this.newOffersToUserAtEnd = !offersToUserData.hitLimit;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
console.error("Error retrieving settings & contacts:", err);
this.$notify(
{
group: "alert",
type: "danger",
title: "Error",
text: err.message || "There was an error retrieving your activity.",
},
5000,
);
}
}
async loadMoreOffersToUser() {
if (this.newOffersToUserAtEnd) {
return;
}
const offersToUserData = await getNewOffersToUser(
this.axios,
this.apiServer,
this.activeDid,
undefined,
this.newOffersToUser[this.newOffersToUser.length - 1].jwtId,
);
this.newOffersToUser.push(...offersToUserData.data);
this.newOffersToUserAtEnd = !offersToUserData.hitLimit;
}
}
</script>

View File

@@ -26,7 +26,7 @@
your device to run searches but it is not stored on our servers. your device to run searches but it is not stored on our servers.
</div> </div>
<div> <div class="text-center">
<button v-if="!searchBox && !isNewMarkerSet" class="m-4 px-4 py-2"> <button v-if="!searchBox && !isNewMarkerSet" class="m-4 px-4 py-2">
Click to Choose a Location for Nearby Search Click to Choose a Location for Nearby Search
</button> </button>
@@ -35,6 +35,7 @@
class="m-4 px-4 py-2 rounded-md bg-blue-200 text-blue-500" class="m-4 px-4 py-2 rounded-md bg-blue-200 text-blue-500"
@click="storeSearchBox" @click="storeSearchBox"
> >
<fa icon="save" class="fa-fw" />
Store This Location for Nearby Search Store This Location for Nearby Search
</button> </button>
<button <button
@@ -42,6 +43,7 @@
class="m-4 px-4 py-2 rounded-md bg-blue-200 text-blue-500" class="m-4 px-4 py-2 rounded-md bg-blue-200 text-blue-500"
@click="forgetSearchBox" @click="forgetSearchBox"
> >
<fa icon="trash-can" class="fa-fw" />
Delete Stored Location Delete Stored Location
</button> </button>
<button <button
@@ -49,13 +51,15 @@
class="m-4 px-4 py-2 rounded-md bg-blue-200 text-blue-500" class="m-4 px-4 py-2 rounded-md bg-blue-200 text-blue-500"
@click="resetLatLong" @click="resetLatLong"
> >
Reset Marker <fa icon="rotate" class="fa-fw" />
Reset To Original
</button> </button>
<button <button
v-if="isNewMarkerSet" v-if="isNewMarkerSet"
class="m-4 px-4 py-2 rounded-md bg-blue-200 text-blue-500" class="m-4 px-4 py-2 rounded-md bg-blue-200 text-blue-500"
@click="isNewMarkerSet = false" @click="isNewMarkerSet = false"
> >
<fa icon="eraser" class="fa-fw" />
Erase Marker Erase Marker
</button> </button>
<div v-if="isNewMarkerSet"> <div v-if="isNewMarkerSet">
@@ -109,7 +113,7 @@ import { Router } from "vue-router";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { db } from "@/db/index"; import { db, retrieveSettingsForActiveAccount } from "@/db/index";
import { BoundingBox, MASTER_SETTINGS_KEY } from "@/db/tables/settings"; import { BoundingBox, MASTER_SETTINGS_KEY } from "@/db/tables/settings";
const DEFAULT_LAT_LONG_DIFF = 0.01; const DEFAULT_LAT_LONG_DIFF = 0.01;
@@ -142,9 +146,8 @@ export default class DiscoverView extends Vue {
searchBox: { name: string; bbox: BoundingBox } | null = null; searchBox: { name: string; bbox: BoundingBox } | null = null;
async mounted() { async mounted() {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); this.searchBox = settings.searchBoxes?.[0] || null;
this.searchBox = settings?.searchBoxes?.[0] || null;
this.resetLatLong(); this.resetLatLong();
} }

View File

@@ -105,9 +105,8 @@ import { useClipboard } from "@vueuse/core";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import { NotificationIface } from "@/constants/app"; import { NotificationIface } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import { accountsDB, retrieveSettingsForActiveAccount } from "@/db/index";
import { Account } from "@/db/tables/accounts"; import { Account } from "@/db/tables/accounts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
@Component({ components: { QuickNav } }) @Component({ components: { QuickNav } })
export default class SeedBackupView extends Vue { export default class SeedBackupView extends Vue {
@@ -122,9 +121,8 @@ export default class SeedBackupView extends Vue {
// 'created' hook runs when the Vue instance is first created // 'created' hook runs when the Vue instance is first created
async created() { async created() {
try { try {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); const activeDid = settings.activeDid || "";
const activeDid = settings?.activeDid || "";
await accountsDB.open(); await accountsDB.open();
const accounts = await accountsDB.accounts.toArray(); const accounts = await accountsDB.accounts.toArray();

View File

@@ -0,0 +1,122 @@
<template>
<QuickNav />
<TopMessage />
<!-- CONTENT -->
<section id="Content" class="p-2 pb-24 max-w-3xl mx-auto">
<!-- Breadcrumb -->
<div>
<!-- Back -->
<div class="text-lg text-center font-light relative px-7">
<h1
class="text-lg text-center px-2 py-1 absolute -left-2 -top-1"
@click="$router.back()"
>
<fa icon="chevron-left" class="fa-fw" />
</h1>
</div>
<!-- Heading -->
<h1 id="ViewHeading" class="text-4xl text-center font-light">
Share Your Contact Info
</h1>
</div>
<div class="flex justify-center mt-8">
<button
class="block w-fit text-center text-lg font-bold bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md"
@click="onClickShare()"
>
Copy to Clipboard
</button>
</div>
<div class="ml-12">
<div class="mt-8">Click to copy your info, then send it to them.</div>
<div>
They will paste it in the input box on the Contacts
<fa icon="users" /> screen.
</div>
</div>
</section>
</template>
<script lang="ts">
import * as R from "ramda";
import { Component, Vue } from "vue-facing-decorator";
import { Router } from "vue-router";
import { useClipboard } from "@vueuse/core";
import QuickNav from "@/components/QuickNav.vue";
import TopMessage from "@/components/TopMessage.vue";
import { NotificationIface } from "@/constants/app";
import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { generateEndorserJwtForAccount } from "@/libs/endorserServer";
@Component({
components: { QuickNav, TopMessage },
})
export default class ShareMyContactInfoView extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void;
async onClickShare() {
const settings = await retrieveSettingsForActiveAccount();
const activeDid = settings.activeDid || "";
const givenName = settings.firstName || "";
const isRegistered = !!settings.isRegistered;
const profileImageUrl = settings.profileImageUrl || "";
await accountsDB.open();
const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === activeDid, accounts);
const numContacts = await db.contacts.count();
if (account) {
const message = await generateEndorserJwtForAccount(
account,
isRegistered,
givenName,
profileImageUrl,
true,
);
useClipboard()
.copy(message)
.then(() => {
this.$notify(
{
group: "alert",
type: "info",
title: "Copied",
text: "Your contact info was copied to the clipboard. Have them paste it in the box on their 'Contacts' screen.",
},
5000,
);
if (numContacts > 0) {
setTimeout(() => {
this.$notify(
{
group: "alert",
type: "success",
title: "Share Other Contacts",
text: "You may want to share some of your contacts with them. Select them below to copy and send.",
},
10000,
);
}, 3000);
}
});
(this.$router as Router).push({ name: "contacts" });
} else {
this.$notify(
{
group: "alert",
type: "error",
title: "Error",
text: "No account was found for the active DID.",
},
5000,
);
}
}
}
</script>

View File

@@ -75,7 +75,7 @@ import {
IMAGE_TYPE_PROFILE, IMAGE_TYPE_PROFILE,
NotificationIface, NotificationIface,
} from "@/constants/app"; } from "@/constants/app";
import { db } from "@/db/index"; import { db, retrieveSettingsForActiveAccount } from "@/db/index";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken } from "@/libs/crypto"; import { accessToken } from "@/libs/crypto";
import { base64ToBlob, SHARED_PHOTO_BASE64_KEY } from "@/libs/util"; import { base64ToBlob, SHARED_PHOTO_BASE64_KEY } from "@/libs/util";
@@ -94,9 +94,8 @@ export default class SharedPhotoView extends Vue {
// 'created' hook runs when the Vue instance is first created // 'created' hook runs when the Vue instance is first created
async mounted() { async mounted() {
try { try {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); this.activeDid = settings.activeDid;
this.activeDid = settings?.activeDid as string;
const temp = await db.temp.get(SHARED_PHOTO_BASE64_KEY); const temp = await db.temp.get(SHARED_PHOTO_BASE64_KEY);
const imageB64 = temp?.blobB64 as string; const imageB64 = temp?.blobB64 as string;

View File

@@ -58,6 +58,7 @@
<a <a
@click="onClickNewSeed()" @click="onClickNewSeed()"
class="block w-full text-center text-lg uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md mb-2 cursor-pointer" class="block w-full text-center text-lg uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md mb-2 cursor-pointer"
data-testId="newSeed"
> >
Generate one with a new seed Generate one with a new seed
</a> </a>
@@ -91,8 +92,7 @@ import { Component, Vue } from "vue-facing-decorator";
import { Router } from "vue-router"; import { Router } from "vue-router";
import { AppString, PASSKEYS_ENABLED } from "@/constants/app"; import { AppString, PASSKEYS_ENABLED } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import { accountsDB, retrieveSettingsForActiveAccount } from "@/db/index";
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings";
import { registerSaveAndActivatePasskey } from "@/libs/util"; import { registerSaveAndActivatePasskey } from "@/libs/util";
@Component({ @Component({
@@ -105,9 +105,8 @@ export default class StartView extends Vue {
numAccounts = 0; numAccounts = 0;
async mounted() { async mounted() {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; this.givenName = settings.firstName || "";
this.givenName = settings?.firstName || "";
await accountsDB.open(); await accountsDB.open();
this.numAccounts = await accountsDB.accounts.count(); this.numAccounts = await accountsDB.accounts.count();

View File

@@ -25,12 +25,13 @@
Here is a view of the activity you can see. Here is a view of the activity you can see.
<ul class="list-disc outside ml-4"> <ul class="list-disc outside ml-4">
<li>Each identity and claim has a unique position.</li> <li>Each identity and claim has a unique position.</li>
<!-- eslint-disable prettier/prettier --><!-- If we format prettier then there is extra space at the start of the line. --> <li>
<li>Each will show at their time of appearance relative to all others.</li> Each will show at their time of appearance relative to all others.
<li>Note that the ones on the left and right edges are randomized </li>
because their data isn't all visible to you. <li>
Note that the ones on the left and right edges are randomized because
their data isn't all visible to you.
</li> </li>
<!-- eslint-enable -->
</ul> </ul>
</div> </div>
@@ -46,7 +47,9 @@
{{ worldProperties.animationDurationSeconds }} seconds {{ worldProperties.animationDurationSeconds }} seconds
</div> </div>
</div> </div>
<button class="float-right text-blue-600" @click="captureGraphics()">Screenshot</button> <button class="float-right text-blue-600" @click="captureGraphics()">
Screenshot
</button>
<div id="scene-container" class="h-screen"></div> <div id="scene-container" class="h-screen"></div>
</section> </section>
</template> </template>

View File

@@ -157,7 +157,7 @@
<div class="mt-8"> <div class="mt-8">
<h2 class="text-xl font-bold mb-4">Image Sharing</h2> <h2 class="text-xl font-bold mb-4">Image Sharing</h2>
Populates the "shared-photo" view as if they used "share_target". Populates the "shared-photo" view as if they used "share_target".
<input type="file" data-testid="fileInput" @change="uploadFile" /> <input type="file" data-testId="fileInput" @change="uploadFile" />
<router-link <router-link
v-if="showFileNextStep()" v-if="showFileNextStep()"
:to="{ :to="{
@@ -165,7 +165,7 @@
query: { fileName }, query: { fileName },
}" }"
class="block w-full text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md mb-2 mt-2" class="block w-full text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md mb-2 mt-2"
data-testid="fileUploadButton" data-testId="fileUploadButton"
> >
Go to Shared Page Go to Shared Page
</router-link> </router-link>
@@ -247,8 +247,7 @@ import { Router } from "vue-router";
import QuickNav from "@/components/QuickNav.vue"; import QuickNav from "@/components/QuickNav.vue";
import { AppString, NotificationIface } from "@/constants/app"; import { AppString, NotificationIface } from "@/constants/app";
import { accountsDB, db } from "@/db/index"; import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import * as vcLib from "@/libs/crypto/vc"; import * as vcLib from "@/libs/crypto/vc";
import { import {
PeerSetup, PeerSetup,
@@ -291,10 +290,9 @@ export default class Help extends Vue {
userName?: string; userName?: string;
async mounted() { async mounted() {
await db.open(); const settings = await retrieveSettingsForActiveAccount();
const settings = await db.settings.get(MASTER_SETTINGS_KEY); this.activeDid = settings.activeDid || "";
this.activeDid = (settings?.activeDid as string) || ""; this.userName = settings.firstName;
this.userName = settings?.firstName as string;
await accountsDB.open(); await accountsDB.open();
const account: { identity?: string } | undefined = await accountsDB.accounts const account: { identity?: string } | undefined = await accountsDB.accounts

View File

@@ -5,6 +5,7 @@ importScripts(
"https://storage.googleapis.com/workbox-cdn/releases/6.4.1/workbox-sw.js", "https://storage.googleapis.com/workbox-cdn/releases/6.4.1/workbox-sw.js",
); );
// similar method is in the src/db/index.ts file
function logConsoleAndDb(message, arg1, arg2) { function logConsoleAndDb(message, arg1, arg2) {
// in chrome://serviceworker-internals note that the arg1 and arg2 here will show as "[object Object]" in that page but will show as expandable objects in the console // in chrome://serviceworker-internals note that the arg1 and arg2 here will show as "[object Object]" in that page but will show as expandable objects in the console
console.log(`${new Date().toISOString()} ${message}`, arg1, arg2); console.log(`${new Date().toISOString()} ${message}`, arg1, arg2);
@@ -13,10 +14,18 @@ function logConsoleAndDb(message, arg1, arg2) {
if (appendDailyLog) { if (appendDailyLog) {
let fullMessage = `${new Date().toISOString()} ${message}`; let fullMessage = `${new Date().toISOString()} ${message}`;
if (arg1) { if (arg1) {
fullMessage += `\n${JSON.stringify(arg1)}`; if (typeof arg1 === "string") {
fullMessage += `\n${arg1}`;
} else {
fullMessage += `\n${JSON.stringify(arg1)}`;
}
} }
if (arg2) { if (arg2) {
fullMessage += `\n${JSON.stringify(arg2)}`; if (typeof arg2 === "string") {
fullMessage += `\n${arg2}`;
} else {
fullMessage += `\n${JSON.stringify(arg2)}`;
}
} }
// appendDailyLog is injected from safari-notifications.js at build time by the vue.config.js configureWebpack apply plugin // appendDailyLog is injected from safari-notifications.js at build time by the vue.config.js configureWebpack apply plugin
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
@@ -63,16 +72,16 @@ self.addEventListener("push", function (event) {
// See https://gitea.anomalistdesign.com/trent_larson/py-push-server/src/commit/c1ed026662e754348a5f91542680bd4f57e5b81e/app.py#L217 // See https://gitea.anomalistdesign.com/trent_larson/py-push-server/src/commit/c1ed026662e754348a5f91542680bd4f57e5b81e/app.py#L217
const DAILY_UPDATE_TITLE = "DAILY_CHECK"; const DAILY_UPDATE_TITLE = "DAILY_CHECK";
// This is a special value that tells the service worker to send a direct notification to the device, skipping filters.
// This is shared with the notification-test code and should be a constant. Look for the same name in HelpNotificationsView.vue // This is shared with the notification-test code and should be a constant. Look for the same name in HelpNotificationsView.vue
// Make sure it is something other than the DAILY_UPDATE_TITLE. // This is a special value that tells the service worker to send a direct notification to the device, skipping filters.
// Make sure it is something different from the DAILY_UPDATE_TITLE.
const DIRECT_PUSH_TITLE = "DIRECT_NOTIFICATION"; const DIRECT_PUSH_TITLE = "DIRECT_NOTIFICATION";
let title; let title;
let message = "Got some empty message."; let message = "Got some empty message.";
if (payload && payload.title == DIRECT_PUSH_TITLE) { if (payload && payload.title == DIRECT_PUSH_TITLE) {
// skip any search logic and show the message directly // skip any search logic and show the message directly
title = "Direct Notification"; title = "Direct Message";
message = payload.message || "No details were provided."; message = payload.message || "No details were provided.";
} else { } else {
// any other title will run through regular filtering logic // any other title will run through regular filtering logic
@@ -133,7 +142,8 @@ self.addEventListener("notificationclick", (event) => {
// This is invoked when the user chooses this as a share_target, mapped to share-target in the manifest. // This is invoked when the user chooses this as a share_target, mapped to share-target in the manifest.
self.addEventListener("fetch", (event) => { self.addEventListener("fetch", (event) => {
logConsoleAndDb("Service worker got fetch event.", event); // Skipping this because we get so many of them, at startup and other times, all with an event of: {isTrusted:true}
//logConsoleAndDb("Service worker got fetch event.", event);
// Bypass any regular requests not related to Web Share Target // Bypass any regular requests not related to Web Share Target
// and also requests that are not exactly to the timesafari.app // and also requests that are not exactly to the timesafari.app

View File

@@ -1,27 +1,13 @@
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
import { deleteContact, generateAndRegisterEthrUser, importUser } from './testUtils';
test('Confirm usage of test API (may fail if you are running your own Time Safari)', async ({ page }, testInfo) => { test('Check activity feed - check that server is running', async ({ page }) => {
// Load account view
await page.goto('./account');
await page.getByRole('heading', { name: 'Advanced' }).click();
// look into the config file: if it starts Time Safari, it might say which server it should set by default
const webServer = testInfo.config.webServer;
const endorserWords = webServer?.command.split(' ');
const ENDORSER_ENV_NAME = 'VITE_DEFAULT_ENDORSER_API_SERVER';
const endorserTerm = endorserWords?.find(word => word.startsWith(ENDORSER_ENV_NAME + '='));
const endorserTermInConfig = endorserTerm?.substring(ENDORSER_ENV_NAME.length + 1);
const endorserServer = endorserTermInConfig || 'https://test-api.endorser.ch';
await expect(page.getByRole('textbox').nth(1)).toHaveValue(endorserServer);
});
test('Check activity feed', async ({ page }) => {
// Load app homepage // Load app homepage
await page.goto('./'); await page.goto('./');
await page.getByTestId('closeOnboardingAndFinish').click();
// Check that initial 10 activities have been loaded // Check that initial 10 activities have been loaded
await page.locator('ul#listLatestActivity li:nth-child(10)'); await expect(page.locator('ul#listLatestActivity li:nth-child(10)')).toBeVisible();
// Scroll down a bit to trigger loading additional activities // Scroll down a bit to trigger loading additional activities
await page.locator('ul#listLatestActivity li:nth-child(50)').scrollIntoViewIfNeeded(); await page.locator('ul#listLatestActivity li:nth-child(50)').scrollIntoViewIfNeeded();
@@ -32,20 +18,12 @@ test('Check discover results', async ({ page }) => {
await page.goto('./discover'); await page.goto('./discover');
// Check that initial 10 projects have been loaded // Check that initial 10 projects have been loaded
await page.locator('ul#listDiscoverResults li.border-b:nth-child(10)'); await expect(page.locator('ul#listDiscoverResults li.border-b:nth-child(10)')).toBeVisible();
// Scroll down a bit to trigger loading additional projects // Scroll down a bit to trigger loading additional projects
await page.locator('ul#listDiscoverResults li.border-b:nth-child(20)').scrollIntoViewIfNeeded(); await page.locator('ul#listDiscoverResults li.border-b:nth-child(20)').scrollIntoViewIfNeeded();
}); });
test('Check no-ID messaging in homepage', async ({ page }) => {
// Load app homepage
await page.goto('./');
// Check 'someone must register you' notice
await expect(page.getByText('To share, someone must register you.')).toBeVisible();
});
test('Check no-ID messaging in account', async ({ page }) => { test('Check no-ID messaging in account', async ({ page }) => {
// Load account view // Load account view
await page.goto('./account'); await page.goto('./account');
@@ -60,6 +38,17 @@ test('Check no-ID messaging in account', async ({ page }) => {
await expect(page.locator('#sectionIdentityDetails code.truncate')).toBeEmpty(); await expect(page.locator('#sectionIdentityDetails code.truncate')).toBeEmpty();
}); });
test('Check ability to share contact', async ({ page }) => {
// Load Discover view
await page.goto('./discover');
// Check that initial 10 projects have been loaded
await expect(page.locator('ul#listDiscoverResults li.border-b:nth-child(10)')).toBeVisible();
// Scroll down a bit to trigger loading additional projects
await page.locator('ul#listDiscoverResults li.border-b:nth-child(20)').scrollIntoViewIfNeeded();
});
test('Check ID generation', async ({ page }) => { test('Check ID generation', async ({ page }) => {
// Load Account view // Load Account view
await page.goto('./account'); await page.goto('./account');
@@ -73,9 +62,85 @@ test('Check ID generation', async ({ page }) => {
// Wait for activity feed to start loading, as a delay // Wait for activity feed to start loading, as a delay
await expect(page.locator('ul#listLatestActivity li:nth-child(10)')).toBeVisible(); await expect(page.locator('ul#listLatestActivity li:nth-child(10)')).toBeVisible();
// Check 'someone must register you' notice
await expect(page.getByText('To share, someone must register you.')).toBeVisible();
// Go back to Account view // Go back to Account view
await page.goto('./account'); await page.goto('./account');
// Check that ID is now generated // Check that ID is now generated
await expect(page.locator('#sectionIdentityDetails code.truncate')).toContainText('did:ethr:'); await expect(page.locator('#sectionIdentityDetails code.truncate')).toContainText('did:ethr:');
}); });
test('Check setting name & sharing info', async ({ page }) => {
// Load homepage to trigger ID generation (?)
await page.goto('./');
await page.getByTestId('closeOnboardingAndFinish').click();
// Check 'someone must register you' notice
await expect(page.getByText('someone must register you.')).toBeVisible();
await page.getByRole('button', { name: /Show them/}).click();
// fill in a name
await expect(page.getByText('Set Your Name')).toBeVisible();
await page.getByRole('textbox').fill('Me Test User');
await page.locator('button:has-text("Save")').click();
await expect(page.getByText('share another way')).toBeVisible();
await page.getByRole('button', { name: /share another way/ }).click();
await expect(page.getByRole('button', { name: 'copy to clipboard' })).toBeVisible();
await page.getByRole('button', { name: 'copy to clipboard' }).click();
await expect(page.getByText('contact info was copied')).toBeVisible();
// dismiss alert and wait for it to go away
await page.locator('div[role="alert"] button > svg.fa-xmark').click();
await expect(page.getByText('contact info was copied')).toBeHidden();
// check that they're on the Contacts screen
await expect(page.getByText('your contacts')).toBeVisible();
});
test('Confirm test API setting (may fail if you are running your own Time Safari)', async ({ page }, testInfo) => {
// Load account view
await page.goto('./account');
await page.getByRole('heading', { name: 'Advanced' }).click();
// look into the config file: if it starts Time Safari, it might say which server it should set by default
const webServer = testInfo.config.webServer;
const endorserWords = webServer?.command.split(' ');
const ENDORSER_ENV_NAME = 'VITE_DEFAULT_ENDORSER_API_SERVER';
const endorserTerm = endorserWords?.find(word => word.startsWith(ENDORSER_ENV_NAME + '='));
const endorserTermInConfig = endorserTerm?.substring(ENDORSER_ENV_NAME.length + 1);
const endorserServer = endorserTermInConfig || 'https://test-api.endorser.ch';
await expect(page.getByRole('textbox').nth(1)).toHaveValue(endorserServer);
});
test('Check User 0 can register a random person', async ({ page }) => {
await importUser(page, '00');
const newDid = await generateAndRegisterEthrUser(page);
expect(newDid).toContain('did:ethr:');
await page.goto('./');
await page.getByTestId('closeOnboardingAndFinish').click();
await page.getByRole('heading', { name: 'Unnamed/Unknown' }).click();
await page.getByPlaceholder('What was given').fill('Gave me access!');
await page.getByRole('button', { name: 'Sign & Send' }).click();
await expect(page.getByText('That gift was recorded.')).toBeVisible();
// now ensure that alert goes away
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss alert
await expect(page.getByText('That gift was recorded.')).toBeHidden();
// now delete the contact to test that pages still do reasonable things
await deleteContact(page, newDid);
// go the activity page for this new person
await page.goto('./did/' + encodeURIComponent(newDid));
// maybe replace by: const popupPromise = page.waitForEvent('popup');
let error;
try {
await page.waitForSelector('div[role="alert"]', { timeout: 2000 });
error = new Error('Error alert should not show.');
} catch (error) {
// success
} finally {
if (error) {
throw error;
}
}
});

View File

@@ -1,27 +0,0 @@
const { test, expect } = require('@playwright/test');
test('Install PWA', async ({ page, context }) => {
await page.goto('./');
// Wait for the service worker to register
await page.waitForSelector('service-worker-registered-indicator', {
timeout: 10000, // Adjust timeout according to your needs
});
// Trigger the install prompt manually
const [installPrompt] = await Promise.all([
page.waitForEvent('beforeinstallprompt'),
page.evaluate(() => {
window.dispatchEvent(new Event('beforeinstallprompt'));
}),
]);
// Accept the install prompt
await installPrompt.prompt();
// Check if the PWA was installed successfully
const result = await installPrompt.userChoice;
expect(result.outcome).toBe('accepted');
// Additional checks go here
});

View File

@@ -0,0 +1,32 @@
import { test, expect } from '@playwright/test';
import { deleteContact, generateNewEthrUser, generateRandomString, importUser, switchToUser } from './testUtils';
test('Check User 0 can invite someone', async ({ page }) => {
const newDid = await generateNewEthrUser(page);
await importUser(page, '00');
await page.goto('./invite-one');
await page.locator('button > svg.fa-plus').click();
const neighborNum = await generateRandomString(5);
await page.getByPlaceholder('Notes', { exact: true }).fill(`Neighbor ${neighborNum}`);
// get the expiration date input and set to 14 days from now
const expirationDate = new Date(Date.now() + 14 * 24 * 60 * 60 * 1000);
await page.locator('input[type="date"]').fill(expirationDate.toISOString().split('T')[0]);
await page.locator('button:has-text("Save")').click();
await expect(page.locator('div[role="alert"] button:has-text("Yes")')).toBeHidden();
// check that the invite is in the list
const newInviteLine = page.locator(`td:has-text("Neighbor ${neighborNum}")`);
await expect(newInviteLine).toBeVisible();
// retrieve the link from the title
const inviteLink = await newInviteLine.getAttribute('data-testId');
expect(inviteLink).not.toBeNull();
// become the new user and accept the invite
await switchToUser(page, newDid);
await page.goto(inviteLink as string);
await page.getByPlaceholder('Name', { exact: true }).fill(`My pal User #0`);
await page.locator('button:has-text("Save")').click();
await expect(page.locator('button:has-text("Save")')).toBeHidden();
await expect(page.locator(`li:has-text("My pal User #0")`)).toBeVisible();
});

View File

@@ -7,12 +7,22 @@ test('Check usage limits', async ({ page }) => {
await expect(page.locator('div.bg-slate-100.rounded-md').filter({ hasText: 'Usage Limits' })).toBeHidden(); await expect(page.locator('div.bg-slate-100.rounded-md').filter({ hasText: 'Usage Limits' })).toBeHidden();
// Import user 01 // Import user 01
await importUser(page, '01'); const did = await importUser(page, '01');
// Verify that "Usage Limits" section is visible // Verify that "Usage Limits" section is visible
await expect(page.locator('#sectionUsageLimits')).toBeVisible(); await expect(page.locator('#sectionUsageLimits')).toBeVisible();
await expect(page.locator('#sectionUsageLimits')).toContainText('You have done');
await expect(page.locator('#sectionUsageLimits')).toContainText('You have uploaded');
await expect(page.getByText('Your claims counter resets')).toBeVisible(); await expect(page.getByText('Your claims counter resets')).toBeVisible();
await expect(page.getByText('Your registration counter resets')).toBeVisible(); await expect(page.getByText('Your registration counter resets')).toBeVisible();
await expect(page.getByText('Your image counter resets')).toBeVisible(); await expect(page.getByText('Your image counter resets')).toBeVisible();
await expect(page.getByRole('button', { name: 'Recheck Limits' })).toBeVisible(); await expect(page.getByRole('button', { name: 'Recheck Limits' })).toBeVisible();
// Set name
await page.getByRole('button', { name: 'Set Your Name' }).click();
const name = 'User ' + did.slice(11, 14);
await page.getByPlaceholder('Name').fill(name);
await page.getByRole('button', { name: 'Save' }).click();
}); });

View File

@@ -2,6 +2,8 @@ import { test, expect } from '@playwright/test';
import { importUser } from './testUtils'; import { importUser } from './testUtils';
test('Create new project, then search for it', async ({ page }) => { test('Create new project, then search for it', async ({ page }) => {
test.slow();
// Generate a random string of 16 characters // Generate a random string of 16 characters
let randomString = Math.random().toString(36).substring(2, 18); let randomString = Math.random().toString(36).substring(2, 18);
@@ -14,26 +16,46 @@ test('Create new project, then search for it', async ({ page }) => {
// Standard texts // Standard texts
const standardTitle = 'Idea '; const standardTitle = 'Idea ';
const standardDescription = 'Description of Idea '; const standardDescription = 'Description of Idea ';
const standardEdit = ' EDITED';
const standardWebsite = 'https://example.com';
const editedWebsite = 'https://example.com/edited';
// Set dates
const today = new Date();
const oneMonthAhead = new Date(today.setDate(today.getDate() + 30));
const twoMonthsAhead = new Date(today.setDate(today.getDate() + 30));
const finalDate = oneMonthAhead.toISOString().split('T')[0];
const editedDate = twoMonthsAhead.toISOString().split('T')[0];
// Set times
const now = new Date();
const oneHourAhead = new Date(now.setHours(now.getHours() + 1));
const twoHoursAhead = new Date(now.setHours(now.getHours() + 1));
const finalHour = oneHourAhead.getHours().toString().padStart(2, '0');
const editedHour = twoHoursAhead.getHours().toString().padStart(2, '0');
const finalMinute = oneHourAhead.getMinutes().toString().padStart(2, '0');
const finalTime = `${finalHour}:${finalMinute}`;
const editedTime = `${editedHour}:${finalMinute}`;
// Combine texts with the random string // Combine texts with the random string
const finalTitle = standardTitle + finalRandomString; const finalTitle = standardTitle + finalRandomString;
const finalDescription = standardDescription + finalRandomString; const finalDescription = standardDescription + finalRandomString;
const editedTitle = finalTitle + standardEdit;
const editedDescription = finalDescription + standardEdit;
// Import user 00 // Import user 00
await importUser(page, '00'); await importUser(page, '00');
// Pause for 5 seconds
await page.waitForTimeout(5000); // I have to wait, otherwise the (+) button to add a new project doesn't appear
// Create new project // Create new project
await page.goto('./projects'); await page.goto('./projects');
await page.getByRole('link', { name: 'Projects', exact: true }).click(); // close onboarding, but not with a click to go to the main screen
await page.getByRole('button').click(); await page.locator('div > svg.fa-xmark').click();
await page.getByPlaceholder('Idea Name').fill(finalTitle); // Add random suffix await page.locator('button > svg.fa-plus').click();
await page.getByPlaceholder('Idea Name').fill(finalTitle);
await page.getByPlaceholder('Description').fill(finalDescription); await page.getByPlaceholder('Description').fill(finalDescription);
await page.getByPlaceholder('Website').fill('https://example.com'); await page.getByPlaceholder('Website').fill(standardWebsite);
await page.getByPlaceholder('Start Date').fill('2025-12-01'); await page.getByPlaceholder('Start Date').fill(finalDate);
await page.getByPlaceholder('Start Time').fill('12:00'); await page.getByPlaceholder('Start Time').fill(finalTime);
await page.getByRole('button', { name: 'Save Project' }).click(); await page.getByRole('button', { name: 'Save Project' }).click();
// Check texts // Check texts
@@ -42,12 +64,27 @@ test('Create new project, then search for it', async ({ page }) => {
// Search for newly-created project in /projects // Search for newly-created project in /projects
await page.goto('./projects'); await page.goto('./projects');
await page.getByRole('link', { name: 'Projects', exact: true }).click(); await expect(page.locator('ul#listProjects li').filter({ hasText: finalTitle })).toBeVisible();
await expect(page.locator('ul#listProjects li.border-b:nth-child(1)')).toContainText(finalRandomString); // Assumes newest project always appears first in the Projects tab list
// Search for newly-created project in /discover // Search for newly-created project in /discover
await page.goto('./discover'); await page.goto('./discover');
await page.getByPlaceholder('Search…').fill(finalRandomString); await page.getByPlaceholder('Search…').fill(finalRandomString);
await page.locator('#QuickSearch button').click(); await page.locator('#QuickSearch button').click();
await expect(page.locator('ul#listDiscoverResults li.border-b:nth-child(1)')).toContainText(finalRandomString); await expect(page.locator('ul#listDiscoverResults li').filter({ hasText: finalTitle })).toBeVisible();
// Edit the project
await page.locator('a').filter({ hasText: finalTitle }).first().click();
await page.getByRole('button', { name: 'Edit' }).click();
await expect(page.getByPlaceholder('Idea Name')).toHaveValue(finalTitle); // Check that textfield value has loaded before proceeding
await page.getByPlaceholder('Idea Name').fill(editedTitle);
await page.getByPlaceholder('Description').fill(editedDescription);
await page.getByPlaceholder('Website').fill(editedWebsite);
await page.getByPlaceholder('Start Date').fill(editedDate);
await page.getByPlaceholder('Start Time').fill(editedTime);
await page.getByRole('button', { name: 'Save Project' }).click();
// Check edits
await expect(page.locator('h2')).toContainText(editedTitle);
await page.getByText('Read More').click();
await expect(page.locator('#Content')).toContainText(editedDescription);
}); });

View File

@@ -1,38 +1,20 @@
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
import { importUser } from './testUtils'; import { importUser, createUniqueStringsArray } from './testUtils';
// Function to generate a random string of specified length
function generateRandomString(length) {
return Math.random().toString(36).substring(2, 2 + length);
}
// Function to create an array of unique strings
function createUniqueStringsArray(count) {
const stringsArray = [];
const stringLength = 16;
for (let i = 0; i < count; i++) {
let randomString = generateRandomString(stringLength);
stringsArray.push(randomString);
}
return stringsArray;
}
test('Create 10 new projects', async ({ page }) => { test('Create 10 new projects', async ({ page }) => {
test.slow(); // Extend the test timeout
const projectCount = 10; const projectCount = 10;
// Standard texts // Standard texts
const standardTitle = "Idea "; const standardTitle = "Idea ";
const standardDescription = "Description of Idea "; const standardDescription = "Description of Idea ";
const standardWebsite = 'https://example.com';
// Title and description arrays // Title and description arrays
const finalTitles = []; const finalTitles = [];
const finalDescriptions = []; const finalDescriptions = [];
// Create an array of unique strings // Create an array of unique strings
const uniqueStrings = createUniqueStringsArray(projectCount); const uniqueStrings = await createUniqueStringsArray(projectCount);
// Populate arrays with titles and descriptions // Populate arrays with titles and descriptions
for (let i = 0; i < projectCount; i++) { for (let i = 0; i < projectCount; i++) {
@@ -42,24 +24,35 @@ test('Create 10 new projects', async ({ page }) => {
finalDescriptions.push(loopDescription); finalDescriptions.push(loopDescription);
} }
// Set date
const today = new Date();
const oneMonthAhead = new Date(today.setDate(today.getDate() + 30));
const standardDate = oneMonthAhead.toISOString().split('T')[0];
// Set time
const now = new Date();
const futureTime = new Date(now.setHours(now.getHours() + 1));
const standardHour = futureTime.getHours().toString().padStart(2, '0');
const standardMinute = futureTime.getMinutes().toString().padStart(2, '0');
const standardTime = `${standardHour}:${standardMinute}`;
// Import user 00 // Import user 00
await importUser(page, '00'); await importUser(page, '00');
// Pause a bit
await page.waitForTimeout(3000); // I have to wait, otherwise the (+) button to add a new project doesn't appear
// Create new projects // Create new projects
for (let i = 0; i < projectCount; i++) { for (let i = 0; i < projectCount; i++) {
await page.goto('./projects'); await page.goto('./projects');
await page.getByRole('link', { name: 'Projects', exact: true }).click(); if (i === 0) {
await page.getByRole('button').click(); // close onboarding, but not with a click to go to the main screen
await page.locator('div > svg.fa-xmark').click();
}
await page.locator('button > svg.fa-plus').click();
await page.getByPlaceholder('Idea Name').fill(finalTitles[i]); // Add random suffix await page.getByPlaceholder('Idea Name').fill(finalTitles[i]); // Add random suffix
await page.getByPlaceholder('Description').fill(finalDescriptions[i]); await page.getByPlaceholder('Description').fill(finalDescriptions[i]);
await page.getByPlaceholder('Website').fill('https://example.com'); await page.getByPlaceholder('Website').fill(standardWebsite);
await page.getByPlaceholder('Start Date').fill('2025-12-01'); await page.getByPlaceholder('Start Date').fill(standardDate);
await page.getByPlaceholder('Start Time').fill('12:00'); await page.getByPlaceholder('Start Time').fill(standardTime);
await page.getByRole('button', { name: 'Save Project' }).click(); await page.getByRole('button', { name: 'Save Project' }).click();
await page.waitForTimeout(1000); // Compensate for delay in loading Idea Name heading
// Check texts // Check texts
await expect(page.locator('h2')).toContainText(finalTitles[i]); await expect(page.locator('h2')).toContainText(finalTitles[i]);

View File

@@ -19,6 +19,7 @@ test('Record something given', async ({ page }) => {
// Record something given // Record something given
await page.goto('./'); await page.goto('./');
await page.getByTestId('closeOnboardingAndFinish').click();
await page.getByRole('heading', { name: 'Unnamed/Unknown' }).click(); await page.getByRole('heading', { name: 'Unnamed/Unknown' }).click();
await page.getByPlaceholder('What was given').fill(finalTitle); await page.getByPlaceholder('What was given').fill(finalTitle);
await page.getByRole('spinbutton').fill(randomNonZeroNumber.toString()); await page.getByRole('spinbutton').fill(randomNonZeroNumber.toString());

View File

@@ -1,50 +1,19 @@
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
import { importUser } from './testUtils'; import { importUser, createUniqueStringsArray, createRandomNumbersArray } from './testUtils';
// Function to generate a random string of specified length test('Record 9 new gifts', async ({ page }) => {
function generateRandomString(length) { const giftCount = 9; // because 10 has taken us above 30 seconds
return Math.random().toString(36).substring(2, 2 + length);
}
// Function to create an array of unique strings
function createUniqueStringsArray(count) {
const stringsArray = [];
const stringLength = 16;
for (let i = 0; i < count; i++) {
let randomString = generateRandomString(stringLength);
stringsArray.push(randomString);
}
return stringsArray;
}
// Function to create an array of two-digit non-zero numbers
function createRandomNumbersArray(count) {
const numbersArray = [];
for (let i = 0; i < count; i++) {
let randomNumber = Math.floor(Math.random() * 99) + 1;
numbersArray.push(randomNumber);
}
return numbersArray;
}
test('Record 10 new gifts', async ({ page }) => {
test.slow(); // Extend the test timeout
const giftCount = 10;
// Standard text // Standard text
const standardTitle = "Gift "; const standardTitle = 'Gift ';
// Field value arrays // Field value arrays
const finalTitles = []; const finalTitles = [];
const finalNumbers = []; const finalNumbers = [];
// Create arrays for field input // Create arrays for field input
const uniqueStrings = createUniqueStringsArray(giftCount); const uniqueStrings = await createUniqueStringsArray(giftCount);
const randomNumbers = createRandomNumbersArray(giftCount); const randomNumbers = await createRandomNumbersArray(giftCount);
// Populate array with titles // Populate array with titles
for (let i = 0; i < giftCount; i++) { for (let i = 0; i < giftCount; i++) {
@@ -57,13 +26,13 @@ test('Record 10 new gifts', async ({ page }) => {
// Import user 00 // Import user 00
await importUser(page, '00'); await importUser(page, '00');
// Pause a bit
await page.waitForTimeout(3000); // I have to wait, otherwise the (+) button to add a new project doesn't appear
// Record new gifts // Record new gifts
for (let i = 0; i < giftCount; i++) { for (let i = 0; i < giftCount; i++) {
// Record something given // Record something given
await page.goto('./'); await page.goto('./');
if (i === 0) {
await page.getByTestId('closeOnboardingAndFinish').click();
}
await page.getByRole('heading', { name: 'Unnamed/Unknown' }).click(); await page.getByRole('heading', { name: 'Unnamed/Unknown' }).click();
await page.getByPlaceholder('What was given').fill(finalTitles[i]); await page.getByPlaceholder('What was given').fill(finalTitles[i]);
await page.getByRole('spinbutton').fill(finalNumbers[i].toString()); await page.getByRole('spinbutton').fill(finalNumbers[i].toString());

View File

@@ -2,6 +2,7 @@ import { test, expect } from '@playwright/test';
import { importUser } from './testUtils'; import { importUser } from './testUtils';
test('Add contact, record gift, confirm gift', async ({ page }) => { test('Add contact, record gift, confirm gift', async ({ page }) => {
// Generate a random string of 16 characters // Generate a random string of 16 characters
let randomString = Math.random().toString(36).substring(2, 18); let randomString = Math.random().toString(36).substring(2, 18);
@@ -21,7 +22,7 @@ test('Add contact, record gift, confirm gift', async ({ page }) => {
const finalTitle = standardTitle + finalRandomString; const finalTitle = standardTitle + finalRandomString;
// Contact name // Contact name
const contactName = 'Contact #111'; const contactName = 'Contact #000 renamed';
// Import user 01 // Import user 01
await importUser(page, '01'); await importUser(page, '01');
@@ -30,9 +31,10 @@ test('Add contact, record gift, confirm gift', async ({ page }) => {
await page.goto('./contacts'); await page.goto('./contacts');
await page.getByPlaceholder('URL or DID, Name, Public Key').fill('did:ethr:0x0000694B58C2cC69658993A90D3840C560f2F51F, User #000'); await page.getByPlaceholder('URL or DID, Name, Public Key').fill('did:ethr:0x0000694B58C2cC69658993A90D3840C560f2F51F, User #000');
await page.locator('button > svg.fa-plus').click(); await page.locator('button > svg.fa-plus').click();
await expect(page.locator('div[role="alert"]')).toBeVisible(); await expect(page.locator('div[role="alert"] span:has-text("Contact Added")')).toBeVisible();
await page.locator('div[role="alert"] button:has-text("No")').click(); // don't register
await page.locator('div[role="alert"] button:has-text("Yes")').click(); await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
await expect(page.locator('div[role="alert"] button > svg.fa-xmark')).toBeHidden(); // ensure alert is gone
// Verify added contact // Verify added contact
await expect(page.locator('li.border-b')).toContainText('User #000'); await expect(page.locator('li.border-b')).toContainText('User #000');
@@ -43,9 +45,11 @@ test('Add contact, record gift, confirm gift', async ({ page }) => {
await expect(page.locator('div.dialog-overlay > div.dialog').filter({ hasText: 'Edit Name' })).toBeVisible(); await expect(page.locator('div.dialog-overlay > div.dialog').filter({ hasText: 'Edit Name' })).toBeVisible();
await page.getByPlaceholder('Name', { exact: true }).fill(contactName); await page.getByPlaceholder('Name', { exact: true }).fill(contactName);
await page.locator('.dialog > .flex > button').first().click(); await page.locator('.dialog > .flex > button').first().click();
// await page.locator('.dialog > .flex > button').first().click(); // close alert
// Confirm that home shows contact in "Record Something…" // Confirm that home shows contact in "Record Something…"
await page.goto('./'); await page.goto('./');
await page.getByTestId('closeOnboardingAndFinish').click();
await expect(page.locator('#sectionRecordSomethingGiven ul li').filter({ hasText: contactName }).nth(0)).toBeVisible(); await expect(page.locator('#sectionRecordSomethingGiven ul li').filter({ hasText: contactName }).nth(0)).toBeVisible();
// Record something given by new contact // Record something given by new contact
@@ -57,6 +61,9 @@ test('Add contact, record gift, confirm gift', async ({ page }) => {
// Refresh home view and check gift // Refresh home view and check gift
await page.goto('./'); await page.goto('./');
// Firefox complains on load the initial feed here when we use the test server.
// It may be similar to the CORS problem below.
await page.locator('li').filter({ hasText: finalTitle }).locator('a').click(); await page.locator('li').filter({ hasText: finalTitle }).locator('a').click();
await expect(page.getByRole('heading', { name: 'Verifiable Claim Details' })).toBeVisible(); await expect(page.getByRole('heading', { name: 'Verifiable Claim Details' })).toBeVisible();
await expect(page.getByText(finalTitle, { exact: true })).toBeVisible(); await expect(page.getByText(finalTitle, { exact: true })).toBeVisible();
@@ -72,6 +79,7 @@ test('Add contact, record gift, confirm gift', async ({ page }) => {
// Go to home view and look for gift // Go to home view and look for gift
await page.goto('./'); await page.goto('./');
await page.getByTestId('closeOnboardingAndFinish').click();
await page.locator('li').filter({ hasText: finalTitle }).locator('a').click(); await page.locator('li').filter({ hasText: finalTitle }).locator('a').click();
// Confirm gift as user 00 // Confirm gift as user 00
@@ -86,6 +94,24 @@ test('Add contact, record gift, confirm gift', async ({ page }) => {
await expect(page.locator('div[role="alert"]')).toBeVisible(); await expect(page.locator('div[role="alert"]')).toBeVisible();
}); });
test('Without being registered, add contacts without registration', async ({ page, context }) => {
await page.goto('./account');
// wait until the DID shows on the page in the 'did' element
const didElem = await page.getByTestId('didWrapper').locator('code');
const newDid = await didElem.innerText();
expect(newDid.trim()).toEqual('');
// Add new contact without registering
await page.goto('./contacts');
await page.getByPlaceholder('URL or DID, Name, Public Key').fill('did:ethr:0x111d15564f824D56C7a07b913aA7aDd03382aA39, User #111');
await page.locator('button > svg.fa-plus').click();
await expect(page.locator('div[role="alert"] span:has-text("Contact Added")')).toBeVisible();
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
// wait for the alert to disappear, which also ensures that there is no "Register" button waiting
await expect(page.locator('div[role="alert"]')).toBeHidden();
});
test('Add contact, copy details, delete, and import various ways', async ({ page, context }) => { test('Add contact, copy details, delete, and import various ways', async ({ page, context }) => {
await importUser(page, '00'); await importUser(page, '00');
@@ -94,8 +120,8 @@ test('Add contact, copy details, delete, and import various ways', async ({ page
await page.getByPlaceholder('URL or DID, Name, Public Key').fill('did:ethr:0x111d15564f824D56C7a07b913aA7aDd03382aA39, User #111'); await page.getByPlaceholder('URL or DID, Name, Public Key').fill('did:ethr:0x111d15564f824D56C7a07b913aA7aDd03382aA39, User #111');
await page.locator('button > svg.fa-plus').click(); await page.locator('button > svg.fa-plus').click();
await expect(page.locator('div[role="alert"]')).toBeVisible(); await expect(page.locator('div[role="alert"]')).toBeVisible();
await page.locator('div[role="alert"] button:has-text("No")').click(); await page.locator('div[role="alert"] button:has-text("No")').click(); // don't register
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
// wait for the alert to disappear // wait for the alert to disappear
await expect(page.locator('div[role="alert"]')).toBeHidden(); await expect(page.locator('div[role="alert"]')).toBeHidden();
@@ -103,8 +129,8 @@ test('Add contact, copy details, delete, and import various ways', async ({ page
await page.getByPlaceholder('URL or DID, Name, Public Key').fill('did:ethr:0x222BB77E6Ff3774d34c751f3c1260866357B677b, User #222, asdf1234'); await page.getByPlaceholder('URL or DID, Name, Public Key').fill('did:ethr:0x222BB77E6Ff3774d34c751f3c1260866357B677b, User #222, asdf1234');
await page.locator('button > svg.fa-plus').click(); await page.locator('button > svg.fa-plus').click();
await expect(page.locator('div[role="alert"]')).toBeVisible(); await expect(page.locator('div[role="alert"]')).toBeVisible();
await page.locator('div[role="alert"] button:has-text("No")').click(); await page.locator('div[role="alert"] button:has-text("No")').click(); // don't register
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
await expect(page.locator('div[role="alert"]')).toBeHidden(); await expect(page.locator('div[role="alert"]')).toBeHidden();
await expect(page.getByTestId('contactListItem')).toHaveCount(2); await expect(page.getByTestId('contactListItem')).toHaveCount(2);
@@ -115,6 +141,7 @@ test('Add contact, copy details, delete, and import various ways', async ({ page
await page.getByTestId('contactCheckAllTop').click(); await page.getByTestId('contactCheckAllTop').click();
await page.getByTestId('copySelectedContactsButtonTop').click(); await page.getByTestId('copySelectedContactsButtonTop').click();
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss alert await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss alert
await expect(page.locator('div[role="alert"]')).toBeHidden();
// I would prefer to copy from the clipboard, but the recommended approaches don't work. // I would prefer to copy from the clipboard, but the recommended approaches don't work.
// this seems to fail in non-chromium browsers // this seems to fail in non-chromium browsers
//await context.grantPermissions(['clipboard-read', 'clipboard-write']); //await context.grantPermissions(['clipboard-read', 'clipboard-write']);
@@ -123,12 +150,19 @@ test('Add contact, copy details, delete, and import various ways', async ({ page
// see contact details on the second contact // see contact details on the second contact
await page.getByTestId('contactListItem').nth(1).locator('a').click(); await page.getByTestId('contactListItem').nth(1).locator('a').click();
await page.getByRole('heading', { name: 'Identifier Details' }).isVisible();
// remove contact // remove contact
await page.locator('button > svg.fa-trash-can').click(); await page.locator('button > svg.fa-trash-can').click();
await page.locator('div[role="alert"] button:has-text("Yes")').click(); await page.locator('div[role="alert"] button:has-text("Yes")').click();
// for some reason, .isHidden() (without expect) doesn't work // for some reason, .isHidden() (without expect) doesn't work
await expect(page.locator('div[role="alert"] button:has-text("Yes")')).toBeHidden(); await expect(page.locator('div[role="alert"] button:has-text("Yes")')).toBeHidden();
// Firefox has a problem when we run this against the test server. It doesn't load the feed.
// It says there's a CORS problem; maybe it's more strict than the other browsers.
// It works when we set the config to use a local server.
// Seems like we hit a similar problem above.
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss alert await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss alert
await expect(page.locator('div[role="alert"]')).toBeHidden();
// go to the contacts page and paste the copied contact details // go to the contacts page and paste the copied contact details
await page.goto('./contacts'); await page.goto('./contacts');
@@ -144,4 +178,22 @@ test('Add contact, copy details, delete, and import various ways', async ({ page
await page.locator('button', { hasText: 'Import' }).click(); await page.locator('button', { hasText: 'Import' }).click();
// check that there are more contacts // check that there are more contacts
await expect(page.getByTestId('contactListItem')).toHaveCount(2); await expect(page.getByTestId('contactListItem')).toHaveCount(2);
// Import via the file backup-import
await page.goto('./account');
await page.getByRole('heading', { name: 'Advanced' }).click();
const fileSelect = await page.locator('input[type="file"]')
//fileSelect.click();
fileSelect.setInputFiles('./test-playwright/exported-data.json');
await page.locator('button', { hasText: 'Import Only Contacts' }).click();
// we're on the contact-import page
await expect(page.locator('li', { hasText: '- New' })).toHaveCount(3);
await expect(page.locator('li', { hasText: '- Existing' })).toHaveCount(1);
await expect(page.locator('span').filter({ hasText: 'the same as' })).toBeHidden();
await page.locator('button', { hasText: 'Import' }).click();
// check that there are more contacts
await expect(page.getByTestId('contactListItem')).toHaveCount(5);
// The visibility error is because currently the server returns an error for the same person.
// But it should only show that one, for User #000.
}); });

View File

@@ -9,35 +9,42 @@ test('Record an offer', async ({ page }) => {
const updatedDescription = `Updated ${description}`; const updatedDescription = `Updated ${description}`;
const randomNonZeroNumber = Math.floor(Math.random() * 998) + 1; const randomNonZeroNumber = Math.floor(Math.random() * 998) + 1;
// Create new ID for default user // Switch to user 0
await importUser(page); await importUser(page);
// Select a project // Select a project
await page.goto('./discover'); await page.goto('./discover');
await page.getByTestId('closeOnboardingAndFinish').click();
await page.locator('ul#listDiscoverResults li:nth-child(1)').click(); await page.locator('ul#listDiscoverResults li:nth-child(1)').click();
// Record an offer // Record an offer
await page.locator('button', { hasText: 'Edit' }).isVisible(); // since the 'edit' takes longer to show, wait for that (lest the click miss)
await page.getByTestId('offerButton').click(); await page.getByTestId('offerButton').click();
await page.getByTestId('inputDescription').fill(description); await page.getByTestId('inputDescription').fill(description);
await page.getByTestId('inputOfferAmount').fill(randomNonZeroNumber.toString()); await page.getByTestId('inputOfferAmount').fill(randomNonZeroNumber.toString());
expect(page.getByRole('button', { name: 'Sign & Send' }));
await page.getByRole('button', { name: 'Sign & Send' }).click(); await page.getByRole('button', { name: 'Sign & Send' }).click();
await expect(page.getByText('That offer was recorded.')).toBeVisible(); await expect(page.getByText('That offer was recorded.')).toBeVisible();
// go to the offer and check the values // go to the offer and check the values
await page.goto('./projects'); await page.goto('./projects');
await page.getByRole('link', { name: 'Offers', exact: true }).click();
await page.locator('li').filter({ hasText: description }).locator('a').first().click(); await page.locator('li').filter({ hasText: description }).locator('a').first().click();
await expect(page.getByRole('heading', { name: 'Verifiable Claim Details' })).toBeVisible(); await expect(page.getByRole('heading', { name: 'Verifiable Claim Details' })).toBeVisible();
await expect(page.getByText(description, { exact: true })).toBeVisible(); await expect(page.getByText(description, { exact: true })).toBeVisible();
await expect(page.getByText('Offered to a bigger plan')).toBeVisible();
const serverPagePromise = page.waitForEvent('popup'); const serverPagePromise = page.waitForEvent('popup');
await page.getByRole('link', { name: 'View on the Public Server' }).click(); await page.getByRole('link', { name: 'View on the Public Server' }).click();
const serverPage = await serverPagePromise; const serverPage = await serverPagePromise;
await serverPage.getByText(description); await expect(serverPage.getByText(description)).toBeVisible();
await serverPage.getByText('did:none:HIDDEN'); await expect(serverPage.getByText('did:none:HIDDEN')).toBeVisible();
// Now update that offer // Now update that offer
// find the edit page and check the old values again // find the edit page and check the old values again
await page.goto('./projects'); await page.goto('./projects');
await page.getByRole('link', { name: 'Offers', exact: true }).click();
await page.locator('li').filter({ hasText: description }).locator('a').first().click(); await page.locator('li').filter({ hasText: description }).locator('a').first().click();
await page.getByTestId('editClaimButton').click(); await page.getByTestId('editClaimButton').click();
await page.locator('heading', { hasText: 'What is offered' }).isVisible(); await page.locator('heading', { hasText: 'What is offered' }).isVisible();
@@ -49,15 +56,55 @@ test('Record an offer', async ({ page }) => {
await itemDesc.fill(updatedDescription); await itemDesc.fill(updatedDescription);
await amount.fill(String(randomNonZeroNumber + 1)); await amount.fill(String(randomNonZeroNumber + 1));
await page.getByRole('button', { name: 'Sign & Send' }).click(); await page.getByRole('button', { name: 'Sign & Send' }).click();
await expect(page.getByText('That offer was recorded.')).toBeVisible();
// go to the offer claim again and check the updated values // go to the offer claim again and check the updated values
await page.goto('./projects'); await page.goto('./projects');
await page.getByRole('link', { name: 'Offers', exact: true }).click();
await page.locator('li').filter({ hasText: description }).locator('a').first().click(); await page.locator('li').filter({ hasText: description }).locator('a').first().click();
const newItemDesc = await page.getByTestId('description'); const newItemDesc = page.getByTestId('description');
await expect(newItemDesc).toHaveText(updatedDescription); await expect(newItemDesc).toHaveText(updatedDescription);
// go to edit page // go to edit page
await page.getByTestId('editClaimButton').click(); await page.getByTestId('editClaimButton').click();
const newAmount = await page.getByTestId('inputOfferAmount'); const newAmount = page.getByTestId('inputOfferAmount');
await expect(newAmount).toHaveValue((randomNonZeroNumber + 1).toString()); await expect(newAmount).toHaveValue((randomNonZeroNumber + 1).toString());
// go to the home page and check that the offer is shown as new
await page.goto('./');
const offerNumElem = page.getByTestId('newOffersToUserProjectsActivityNumber');
await expect(offerNumElem).toHaveText('50+');
// click on the number of new offers to go to the list page
await offerNumElem.click();
await expect(page.getByText('New Offers To Your Projects', { exact: true })).toBeVisible();
// get the icon child of the showOffersToUserProjects
await page.getByTestId('showOffersToUserProjects').locator('div > svg.fa-chevron-right').click();
await expect(page.getByText(description)).toBeVisible();
});
test('Affirm delivery of an offer', async ({ page }) => {
// go to the home page and check that the offer is shown as new
await importUser(page);
await page.goto('./');
await page.getByTestId('closeOnboardingAndFinish').click();
const offerNumElem = page.getByTestId('newOffersToUserProjectsActivityNumber');
await expect(offerNumElem).toBeVisible();
// click on the number of new offers to go to the list page
await offerNumElem.click();
// get the link that comes after the showOffersToUserProjects and click it
await page.getByTestId('showOffersToUserProjects').locator('a').click();
// get the first item of the list and click on the icon with file-lines
const firstItem = page.getByTestId('listRecentOffersToUserProjects').locator('li').first();
await expect(firstItem).toBeVisible();
await firstItem.locator('svg.fa-file-lines').click();
await expect(page.getByText('Verifiable Claim Details', { exact: true })).toBeVisible();
// click on the 'Affirm Delivery' button
await page.getByRole('button', { name: 'Affirm Delivery' }).click();
// fill our offer info and submit
await page.getByPlaceholder('What was given').fill('Whatever the offer says');
await page.getByRole('spinbutton').fill('2');
await page.getByRole('button', { name: 'Sign & Send' }).click();
await expect(page.getByText('That gift was recorded.')).toBeVisible();
}); });

View File

@@ -0,0 +1,83 @@
import { test, expect } from '@playwright/test';
import { importUser, generateNewEthrUser, switchToUser } from './testUtils';
test('New offers for another user', async ({ page }) => {
const user01Did = await generateNewEthrUser(page);
await page.goto('./');
await expect(page.getByTestId('newDirectOffersActivityNumber')).toBeHidden();
await importUser(page, '00');
await page.goto('./contacts');
await page.getByPlaceholder('URL or DID, Name, Public Key').fill(user01Did + ', A Friend');
await expect(page.locator('button > svg.fa-plus')).toBeVisible();
await page.locator('button > svg.fa-plus').click();
await expect(page.locator('div[role="alert"] span:has-text("Contact Added")')).toBeVisible();
await page.locator('div[role="alert"] button:has-text("No")').click(); // don't register
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
await expect(page.locator('div[role="alert"] button > svg.fa-xmark')).toBeHidden(); // ensure alert is gone
// show buttons to make offers directly to people
await page.getByRole('button').filter({ hasText: /See Hours/i }).click();
// make an offer directly to user 1
// Generate a random string of 3 characters, skipping the "0." at the beginning
const randomString1 = Math.random().toString(36).substring(2, 5);
await page.getByTestId('offerButton').click();
await page.getByTestId('inputDescription').fill(`help of ${randomString1} from #000`);
await page.getByTestId('inputOfferAmount').fill('1');
await page.getByRole('button', { name: 'Sign & Send' }).click();
await expect(page.getByText('That offer was recorded.')).toBeVisible();
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
await expect(page.locator('div[role="alert"] button > svg.fa-xmark')).toBeHidden(); // ensure alert is gone
// make another offer to user 1
const randomString2 = Math.random().toString(36).substring(2, 5);
await page.getByTestId('offerButton').click();
await page.getByTestId('inputDescription').fill(`help of ${randomString2} from #000`);
await page.getByTestId('inputOfferAmount').fill('3');
await page.getByRole('button', { name: 'Sign & Send' }).click();
await expect(page.getByText('That offer was recorded.')).toBeVisible();
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
await expect(page.locator('div[role="alert"] button > svg.fa-xmark')).toBeHidden(); // ensure alert is gone
// as user 1, go to the home page and check that two offers are shown as new
await switchToUser(page, user01Did);
await page.goto('./');
await page.getByTestId('closeOnboardingAndFinish').click();
let offerNumElem = page.getByTestId('newDirectOffersActivityNumber');
await expect(offerNumElem).toHaveText('2');
// click on the number of new offers to go to the list page
await offerNumElem.click();
await expect(page.getByText('New Offers To You', { exact: true })).toBeVisible();
await page.getByTestId('showOffersToUser').locator('div > svg.fa-chevron-right').click();
// note that they show in reverse chronologicalorder
await expect(page.getByText(`help of ${randomString2} from #000`)).toBeVisible();
await expect(page.getByText(`help of ${randomString1} from #000`)).toBeVisible();
// click on the latest offer to keep it as "unread"
await page.hover(`li:has-text("help of ${randomString2} from #000")`);
// await page.locator('li').filter({ hasText: `help of ${randomString2} from #000` }).click();
// await page.locator('div').filter({ hasText: /keep all above/ }).click();
// now find the "Click to keep all above as new offers" after that list item and click it
const liElem = page.locator('li').filter({ hasText: `help of ${randomString2} from #000` });
await liElem.hover();
const keepAboveAsNew = await liElem.locator('div').filter({ hasText: /keep all above/ });
await keepAboveAsNew.click();
// now see that only one offer is shown as new
await page.goto('./');
offerNumElem = page.getByTestId('newDirectOffersActivityNumber');
await expect(offerNumElem).toHaveText('1');
await offerNumElem.click();
await expect(page.getByText('New Offer To You', { exact: true })).toBeVisible();
await page.getByTestId('showOffersToUser').locator('div > svg.fa-chevron-right').click();
// now see that no offers are shown as new
await page.goto('./');
// wait until the list with ID listLatestActivity has at least one visible item
await page.locator('#listLatestActivity li').first().waitFor({ state: 'visible' });
await expect(page.getByTestId('newDirectOffersActivityNumber')).toBeHidden();
});

8
test-playwright/LICENSE Normal file
View File

@@ -0,0 +1,8 @@
The author disclaims copyright to this source code. In place of a legal notice, here is a blessing:
May you do good and not evil.
May you find forgiveness for yourself and forgive others.
May you share freely, never taking more than you give.
________________________________________________________________
from https://www.sqlite.org/src/info/689401a6cfb4c234 and memorialized here https://spdx.org/licenses/blessing.html

View File

@@ -0,0 +1,86 @@
{
"formatName": "dexie",
"formatVersion": 1,
"data": {
"databaseName": "TimeSafari",
"databaseVersion": 4,
"tables": [
{
"name": "contacts",
"schema": "did,name",
"rowCount": 12
},
{
"name": "logs",
"schema": "date",
"rowCount": 0
},
{
"name": "settings",
"schema": "id,&accountDid",
"rowCount": 2
},
{
"name": "temp",
"schema": "id",
"rowCount": 0
}
],
"data": [{
"tableName": "contacts",
"inbound": true,
"rows": [
{
"did": "did:ethr:0x0000694B58C2cC69658993A90D3840C560f2F51F",
"name": "User #00",
"publicKeyBase64": "A7Ix5zQT8dNrMyd2OtmkS7gfyRSAoUl3qzz9Mt8FZK8d",
"nextPubKeyHashB64": "d9D/wZLUvI/EyOiMKyxcml0uPKrTh5T0tMGcQjjaqE4=",
"seesMe": false
},
{
"did": "did:ethr:0x0Fc2683554C20B3Ea75aa5bf77B3519005082037",
"name": "tester",
"nextPubKeyHashB64": "CCOqpInfn4Exg7rIdiUxU+K+BUr5GQUVdSmN6SHOHKs=",
"profileImageUrl": 0,
"publicKeyBase64": "AnWEewlbkBH7Q+DZgAglXkqd3Ufxvqvf5OcjenO62Opl",
"registered": true,
"seesMe": true
},
{
"did": "did:ethr:0x111d15564f824D56C7a07b913aA7aDd03382aA39",
"name": "User 111",
"nextPubKeyHashB64": "ge3fGAoxP+Ak48UFg2u9BPdd4ircmvqT34p9spU+h5M=",
"profileImageUrl": "https://test-image.timesafari.app/6b3cba6970f44a883bcbaf302384c50f9b0940e4812ac188649a3b9ec0ebada9.png",
"publicKeyBase64": "A1HdQoCMRkWkTgBvTcJFT6tZ6EXIWZaa0aFsnYNzfE/L",
"registered": true,
"seesMe": true
},
{
"did": "did:peer:0zKMFjvUgYrM1hXwDciKXRoR8dd5PXWoHxAFQZ9jU46wURZizUC128RpzpEc6CpzxQWMdHVS5b3W91yGR6hLUkfcC7UdLtU5jB2fW5TMrQTUte",
"name": "did:peer ixroo",
"publicKeyBase64": 0,
"nextPubKeyHashB64": 0,
"registered": true,
"seesMe": true
}
]
},{
"tableName": "settings",
"inbound": true,
"rows": [
{
"id": 1,
"activeDid": "did:ethr:0x0000694B58C2cC69658993A90D3840C560f2F51F",
"apiServer": "https://test-api.endorser.ch",
"lastViewedClaimId": "01J7SCRCJBYHS3RQWFP9EHXYJZ",
"firstName": "Me"
},
{
"isRegistered": false,
"accountDid": "did:ethr:0x0Fc2683554C20B3Ea75aa5bf77B3519005082037",
"id": 2
}
]
}]
}
}

View File

@@ -1,6 +1,9 @@
import { expect, Page } from '@playwright/test'; import { expect, Page } from '@playwright/test';
export async function importUser(page: Page, id?: string): Promise<void> { // Import the seed and switch to the user based on the ID.
// '01' -> 111
// otherwise -> 000
export async function importUser(page: Page, id?: string): Promise<string> {
let seedPhrase, userName, did; let seedPhrase, userName, did;
// Set seed phrase and DID based on user ID // Set seed phrase and DID based on user ID
@@ -21,14 +24,102 @@ export async function importUser(page: Page, id?: string): Promise<void> {
await page.getByText('You have a seed').click(); await page.getByText('You have a seed').click();
await page.getByPlaceholder('Seed Phrase').fill(seedPhrase); await page.getByPlaceholder('Seed Phrase').fill(seedPhrase);
await page.getByRole('button', { name: 'Import' }).click(); await page.getByRole('button', { name: 'Import' }).click();
await expect(page.locator('#sectionUsageLimits')).toContainText('You have done');
await expect(page.locator('#sectionUsageLimits')).toContainText('You have uploaded');
// Set name
await page.getByRole('link', { name: 'Set Your Name' }).click();
await page.getByPlaceholder('Name').fill(userName);
await page.getByRole('button', { name: 'Save Changes' }).click();
// Check DID // Check DID
await expect(page.getByRole('code')).toContainText(did); await expect(page.getByRole('code')).toContainText(did);
} // ... and ensure the app retrieves the registration status
await expect(page.getByText('Your claims counter resets')).toBeVisible();
return did;
}
// This is to switch to someone already in the identity table. It doesn't include registration.
export async function switchToUser(page: Page, did: string): Promise<void> {
// This is the direct approach but users have to tap on things so we'll do that instead.
//await page.goto('./identity-switcher');
await page.goto('./account');
await page.getByRole('heading', { name: 'Advanced' }).click();
await page.getByRole('link', { name: 'Switch Identifier' }).click();
const didElem = await page.locator(`code:has-text("${did}")`);
await didElem.isVisible();
await didElem.click();
// wait for the switch to happen and the account page to fully load
await page.getByTestId('didWrapper').locator('code:has-text("did:")');
}
function createContactName(did: string): string {
return "User " + did.slice(11, 14);
}
export async function deleteContact(page: Page, did: string): Promise<void> {
await page.goto('./contacts');
const contactName = createContactName(did);
// go to the detail page for this contact
await page.locator(`li[data-testid="contactListItem"] h2:has-text("${contactName}") + a`).click();
// delete the contact
await page.locator('button > svg.fa-trash-can').click();
await page.locator('div[role="alert"] button:has-text("Yes")').click();
// for some reason, .isHidden() (without expect) doesn't work
await expect(page.locator('div[role="alert"] button:has-text("Yes")')).toBeHidden();
}
export async function generateNewEthrUser(page: Page): Promise<string> {
await page.goto('./start');
await page.getByTestId('newSeed').click();
await expect(page.locator('span:has-text("Created")')).toBeVisible();
await page.goto('./account');
const didElem = await page.getByTestId('didWrapper').locator('code:has-text("did:")');
const newDid = await didElem.innerText();
return newDid;
}
// Generate a new random user and register them.
// Note that this makes 000 the active user. Use switchToUser to switch to this DID.
export async function generateAndRegisterEthrUser(page: Page): Promise<string> {
const newDid = await generateNewEthrUser(page);
await importUser(page, '000'); // switch to user 000
await page.goto('./contacts');
const contactName = createContactName(newDid);
await page.getByPlaceholder('URL or DID, Name, Public Key').fill(`${newDid}, ${contactName}`);
await page.locator('button > svg.fa-plus').click();
// register them
await page.locator('div[role="alert"] button:has-text("Yes")').click();
// wait for it to disappear because the next steps may depend on alerts being gone
await expect(page.locator('div[role="alert"] button:has-text("Yes")')).toBeHidden();
await expect(page.locator('li', { hasText: contactName })).toBeVisible();
return newDid;
}
// Function to generate a random string of specified length
export async function generateRandomString(length: number): Promise<string> {
return Math.random().toString(36).substring(2, 2 + length);
}
// Function to create an array of unique strings
export async function createUniqueStringsArray(count: number): Promise<string[]> {
const stringsArray = [];
const stringLength = 16;
for (let i = 0; i < count; i++) {
let randomString = await generateRandomString(stringLength);
stringsArray.push(randomString);
}
return stringsArray;
}
// Function to create an array of two-digit non-zero numbers
export async function createRandomNumbersArray(count: number): Promise<number[]> {
const numbersArray = [];
for (let i = 0; i < count; i++) {
let randomNumber = Math.floor(Math.random() * 99) + 1;
numbersArray.push(randomNumber);
}
return numbersArray;
}