From 39a2685506d547606bbfe91fbd9ccbb1937f36f6 Mon Sep 17 00:00:00 2001 From: Lucy C <12953208+elvece@users.noreply.github.com> Date: Wed, 23 Mar 2022 09:39:55 -0600 Subject: [PATCH] Fix/config obj list (#1351) * remove deprecated build check * fixed config types for object and union; cleaned up mock api fixtures * make form object element transition times consistent and emit expand event on list object items --- Makefile | 2 +- .../form-object/form-object.component.html | 5 +- .../form-object/form-object.component.ts | 2 + .../marketplaces/marketplaces.page.ts | 1 - .../app/pages/server-routes/wifi/wifi.page.ts | 3 +- .../ui/src/app/pkg-config/config-types.ts | 8 +- .../ui/src/app/services/api/api.fixures.ts | 347 +++--------------- .../ui/src/app/services/api/mock-patch.ts | 2 - 8 files changed, 67 insertions(+), 303 deletions(-) diff --git a/Makefile b/Makefile index 316b303eb..55755216f 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ EMBASSY_SRC := raspios.img product_key.txt $(EMBASSY_BINS) backend/embassyd.serv COMPAT_SRC := $(shell find system-images/compat/src) UTILS_SRC := $(shell find system-images/utils/Dockerfile) BACKEND_SRC := $(shell find backend/src) $(shell find patch-db/*/src) $(shell find rpc-toolkit/*/src) backend/Cargo.toml backend/Cargo.lock -FRONTEND_SRC := $(shell find frontend/projects) $(shell find frontend/styles) $(shell find frontend/assets) +FRONTEND_SRC := $(shell find frontend/projects) $(shell find frontend/assets) PATCH_DB_CLIENT_SRC = $(shell find patch-db/client -not -path patch-db/client/dist) GIT_REFS := $(shell find .git/refs/heads) TMP_FILE := $(shell mktemp) diff --git a/frontend/projects/ui/src/app/components/form-object/form-object.component.html b/frontend/projects/ui/src/app/components/form-object/form-object.component.html index c78c9dc87..ccc1ae273 100644 --- a/frontend/projects/ui/src/app/components/form-object/form-object.component.html +++ b/frontend/projects/ui/src/app/components/form-object/form-object.component.html @@ -246,7 +246,7 @@ transform: objectListDisplay[entry.key][i].expanded ? 'rotate(0deg)' : 'rotate(180deg)', - transition: 'transform 0.4s ease-out' + transition: 'transform 0.25s ease-out' }" > @@ -257,8 +257,7 @@ 'max-height': objectListDisplay[entry.key][i].height, overflow: 'hidden', 'transition-property': 'max-height', - 'transition-duration': '.5s', - 'transition-delay': '.05s' + 'transition-duration': '.25s' }" > { this.objectListDisplay[key][0].height = this.getDocSize(key, 0) + this.onExpand.emit() }) } } @@ -171,6 +172,7 @@ export class FormObjectComponent { .expanded ? this.getDocSize(key, i) : '0px' + this.onExpand.emit() } updateLabel(key: string, i: number, displayAs: string) { diff --git a/frontend/projects/ui/src/app/pages/server-routes/marketplaces/marketplaces.page.ts b/frontend/projects/ui/src/app/pages/server-routes/marketplaces/marketplaces.page.ts index 9d8a0259e..6799663e2 100644 --- a/frontend/projects/ui/src/app/pages/server-routes/marketplaces/marketplaces.page.ts +++ b/frontend/projects/ui/src/app/pages/server-routes/marketplaces/marketplaces.page.ts @@ -298,7 +298,6 @@ function getMarketplaceValueSpec(): ValueSpecObject { return { type: 'object', name: 'Add Marketplace', - 'unique-by': null, spec: { url: { type: 'string', diff --git a/frontend/projects/ui/src/app/pages/server-routes/wifi/wifi.page.ts b/frontend/projects/ui/src/app/pages/server-routes/wifi/wifi.page.ts index f8ddea78b..571e2476c 100644 --- a/frontend/projects/ui/src/app/pages/server-routes/wifi/wifi.page.ts +++ b/frontend/projects/ui/src/app/pages/server-routes/wifi/wifi.page.ts @@ -212,7 +212,7 @@ export class WifiPage { } else { attempts++ const diff = end - start - // depending on the response time, wait a min of 1000 ms, and a max of 4000 ms in between retries. Both 1000 and 4000 are arbitrary + // depending on the response time, wait a min of 1000 ms, and a max of 4000 ms in between retries. Both 1000 and 4000 are arbitrary await pauseFor(Math.max(1000, 4000 - diff)) } } catch (e) { @@ -354,7 +354,6 @@ function getWifiValueSpec( name: 'WiFi Credentials', description: 'Enter the network SSID and password. You can connect now or save the network for later.', - 'unique-by': null, spec: { ssid: { type: 'string', diff --git a/frontend/projects/ui/src/app/pkg-config/config-types.ts b/frontend/projects/ui/src/app/pkg-config/config-types.ts index 495dbaf7a..22ebd7089 100644 --- a/frontend/projects/ui/src/app/pkg-config/config-types.ts +++ b/frontend/projects/ui/src/app/pkg-config/config-types.ts @@ -53,8 +53,11 @@ export interface ValueSpecBoolean extends WithStandalone { default: boolean } -export interface ValueSpecUnion extends ListValueSpecUnion, WithStandalone { +export interface ValueSpecUnion extends WithStandalone { type: 'union' + tag: UnionTagSpec + variants: { [key: string]: ConfigSpec } + default: string } export interface ValueSpecPointer extends WithStandalone { @@ -67,8 +70,9 @@ export interface ValueSpecPointer extends WithStandalone { multi?: boolean // will only exist if target = config } -export interface ValueSpecObject extends ListValueSpecObject, WithStandalone { +export interface ValueSpecObject extends WithStandalone { type: 'object' + spec: ConfigSpec } export interface WithStandalone { diff --git a/frontend/projects/ui/src/app/services/api/api.fixures.ts b/frontend/projects/ui/src/app/services/api/api.fixures.ts index 9b0772add..8cd3d741c 100644 --- a/frontend/projects/ui/src/app/services/api/api.fixures.ts +++ b/frontend/projects/ui/src/app/services/api/api.fixures.ts @@ -243,7 +243,6 @@ export module Mock { 'emergency-contact': { name: 'Emergency Contact', type: 'object', - 'unique-by': null, description: 'The person to contact in case of emergency.', spec: { name: { @@ -286,7 +285,6 @@ export module Mock { bitcoinNode: { name: 'Bitcoin Node Settings', type: 'union', - 'unique-by': null, description: 'The node settings', default: 'internal', warning: 'Careful changing this', @@ -1147,286 +1145,7 @@ export module Mock { }, } as any // @TODO why is this necessary? - const realWorldConfigSpec: RR.GetPackageConfigRes = { - config: { - bitcoind: { - 'bitcoind-rpc': { - type: 'internal', - 'rpc-user': 'btcpayserver', - 'rpc-password': '3ZRIgPq60y3bpWRPXKPdhV', - }, - 'bitcoind-p2p': { - type: 'internal', - }, - }, - lightning: { - type: 'lnd', - }, - 'tor-address': - 'fzo2uwpfx3yxgvb2fjhmkbxa27logah3c7zw3fc6rxq5osqyegyy34qd.onion', - }, - spec: { - 'tor-address': { - type: 'pointer', - subtype: 'package', - target: 'tor-address', - 'package-id': 'btcpayserver', - interface: 'network', - description: 'The Tor address for the network interface.', - name: 'Network Tor Address', - }, - bitcoind: { - type: 'object', - spec: { - 'bitcoind-rpc': { - type: 'union', - tag: { - id: 'type', - name: 'Type', - description: - 'The Bitcoin Core node to connect to:\n - internal: The Bitcoin Core and Proxy services installed to your Embassy\n - external: An unpruned Bitcoin Core node running on a different device\n', - 'variant-names': { - external: 'External', - internal: 'Internal', - }, - }, - variants: { - external: { - 'connection-settings': { - type: 'union', - tag: { - id: 'type', - name: 'Type', - description: - '- Manual: Raw information for finding a Bitcoin Core node\n- Quick Connect: A Quick Connect URL for a Bitcoin Core node\n', - 'variant-names': { - manual: 'Manual', - 'quick-connect': 'Quick Connect', - }, - }, - variants: { - manual: { - 'rpc-host': { - type: 'string', - copyable: false, - masked: false, - nullable: false, - default: null, - description: - 'The public address of your Bitcoin Core server', - name: 'Public Address', - }, - 'rpc-user': { - type: 'string', - copyable: false, - masked: false, - nullable: false, - default: null, - description: - 'The username for the RPC user on your Bitcoin Core RPC server', - name: 'RPC Username', - }, - 'rpc-password': { - type: 'string', - copyable: false, - masked: false, - nullable: false, - default: null, - description: - 'The password for the RPC user on your Bitcoin Core RPC server', - name: 'RPC Password', - }, - 'rpc-port': { - type: 'number', - range: '[0,65535]', - integral: true, - nullable: false, - default: 8332, - description: - 'The port that your Bitcoin Core RPC server is bound to', - name: 'RPC Port', - }, - }, - 'quick-connect': { - 'quick-connect-url': { - type: 'string', - copyable: false, - masked: false, - nullable: false, - default: null, - description: - 'The Quick Connect URL for your Bitcoin Core RPC server\nNOTE: LND will not accept a .onion url for this option\n', - name: 'Quick Connect URL', - }, - }, - }, - 'display-as': null, - 'unique-by': null, - default: 'quick-connect', - description: - 'Information to connect to an external unpruned Bitcoin Core node', - name: 'Connection Settings', - }, - }, - internal: { - 'rpc-user': { - type: 'pointer', - subtype: 'package', - target: 'config', - 'package-id': 'btc-rpc-proxy', - selector: '$.users.[?(@.name == "btcpayserver")].name', - multi: false, - description: - 'The username for the RPC user allocated to BTCPay', - name: 'RPC Username', - interface: 'asdf', - }, - 'rpc-password': { - type: 'pointer', - subtype: 'package', - target: 'config', - 'package-id': 'btc-rpc-proxy', - selector: '$.users.[?(@.name == "btcpayserver")].password', - multi: false, - description: - 'The password for the RPC user allocated to BTCPay', - name: 'RPC Password', - interface: 'asdf', - }, - }, - }, - 'display-as': null, - 'unique-by': null, - default: 'internal', - description: - 'The Bitcoin Core node to connect to over the RPC interface', - name: 'Bitcoin Core RPC', - }, - pruning: { - default: 'disabled', - description: - 'Blockchain Pruning Options\nReduce the blockchain size on disk\n', - 'display-as': null, - name: 'Pruning Settings', - tag: { - description: - '- Disabled: Disable pruning\n- Automatic: Limit blockchain size on disk to a certain number of megabytes\n- Manual: Prune blockchain with the "pruneblockchain" RPC\n', - id: 'mode', - name: 'Pruning Mode', - 'variant-names': { - automatic: 'Automatic', - disabled: 'Disabled', - manual: 'Manual', - }, - }, - type: 'union', - 'unique-by': null, - variants: { - automatic: { - size: { - default: 550, - description: 'Limit of blockchain size on disk.', - integral: true, - name: 'Max Chain Size', - nullable: false, - range: '[550,1000000)', - type: 'number', - units: 'MiB', - }, - }, - disabled: {}, - manual: { - size: { - default: 65536, - description: 'Prune blockchain if size expands beyond this.', - integral: true, - name: 'Failsafe Chain Size', - nullable: false, - range: '[550,1000000)', - type: 'number', - units: 'MiB', - }, - }, - }, - }, - 'bitcoind-p2p': { - type: 'union', - tag: { - id: 'type', - name: 'type', - description: null, - 'variant-names': { - external: 'external', - internal: 'internal', - }, - }, - variants: { - external: { - 'p2p-host': { - type: 'string', - copyable: false, - masked: false, - nullable: false, - default: null, - description: 'The public address of your Bitcoin Core server', - name: 'Public Address', - }, - 'p2p-port': { - type: 'number', - range: '[0,65535]', - integral: true, - nullable: false, - default: 8333, - description: - 'The port that your Bitcoin Core P2P server is bound to', - name: 'P2P Port', - }, - }, - internal: {}, - }, - 'display-as': null, - 'unique-by': null, - default: 'internal', - description: - 'The Bitcoin Core node to connect to over the P2P interface', - name: 'Bitcoin Core P2P', - }, - }, - 'display-as': null, - 'unique-by': null, - description: - 'RPC and P2P interface configuration options for Bitcoin Core', - name: 'Bitcoin Settings', - }, - lightning: { - type: 'union', - tag: { - id: 'type', - name: 'Type', - description: - 'Enables BTCPay to use the selected internal lightning node.', - 'variant-names': { - 'c-lightning': 'C-Lightning', - lnd: 'LND', - none: 'No selection', - }, - }, - variants: { - 'c-lightning': {}, - lnd: {}, - none: {}, - }, - 'display-as': null, - 'unique-by': null, - default: 'none', - description: - 'Use this setting to grant BTCPay access to your Embassy\\\'s LND or c-lightning node. If you prefer to use an external Lightning node, or you do not intend to use Lightning, leave this setting blank. Please see the "Instructions" page for more details.', - name: 'Embassy Lightning Node', - }, - }, - } - - const testSpec: ConfigSpec = { + export const ConfigSpec: RR.GetPackageConfigRes['spec'] = { testnet: { name: 'Testnet', type: 'boolean', @@ -1595,14 +1314,12 @@ export module Mock { rpcsettings: { name: 'RPC Settings', type: 'object', - 'unique-by': null, description: 'rpc username and password', warning: 'Adding RPC users gives them special permissions on your node.', spec: { laws: { name: 'Laws', type: 'object', - 'unique-by': 'law1', description: 'the law of the realm', spec: { law1: { @@ -1688,7 +1405,6 @@ export module Mock { 'bitcoin-node': { name: 'Bitcoin Node Settings', type: 'union', - 'unique-by': null, description: 'The node settings', default: 'internal', warning: 'Careful changing this', @@ -1779,7 +1495,6 @@ export module Mock { advanced: { name: 'Advanced', type: 'object', - 'unique-by': null, description: 'Advanced settings', spec: { notifications: { @@ -1803,7 +1518,6 @@ export module Mock { rpcsettings: { name: 'RPC Settings', type: 'object', - 'unique-by': null, description: 'rpc username and password', warning: 'Adding RPC users gives them special permissions on your node.', @@ -1811,7 +1525,6 @@ export module Mock { laws: { name: 'Laws', type: 'object', - 'unique-by': 'law1', description: 'the law of the realm', spec: { law1: { @@ -1830,6 +1543,60 @@ export module Mock { masked: false, copyable: true, }, + law4: { + name: 'Fourth Law', + type: 'string', + description: 'the fourth law', + nullable: true, + masked: false, + copyable: true, + }, + law3: { + name: 'Third Law', + type: 'list', + subtype: 'object', + description: 'the third law', + range: '[0,2]', + default: [], + spec: { + 'unique-by': null, + spec: { + lawname: { + name: 'Law Name', + type: 'string', + description: 'the name of the law maker', + nullable: false, + default: { + charset: 'a-g,2-9', + len: 12, + }, + masked: false, + copyable: false, + }, + lawagency: { + name: 'Law agency', + type: 'string', + description: 'the ip of the law maker', + nullable: false, + default: '192.168.1.0', + pattern: + '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$', + 'pattern-description': + 'may only contain numbers and periods', + masked: false, + copyable: true, + }, + }, + }, + }, + law5: { + name: 'Fifth Law', + type: 'string', + description: 'the fifth law', + nullable: true, + masked: false, + copyable: true, + }, }, }, rulemakers: { @@ -1899,12 +1666,8 @@ export module Mock { }, } - export const ConfigSpec: RR.GetPackageConfigRes['spec'] = testSpec export const MockConfig = {} - // export const ConfigSpec: RR.GetPackageConfigRes['spec'] = realWorldConfigSpec.spec - // export const MockConfig = realWorldConfigSpec.config - export const MockDependencyConfig = { testnet: true, 'object-list': [ diff --git a/frontend/projects/ui/src/app/services/api/mock-patch.ts b/frontend/projects/ui/src/app/services/api/mock-patch.ts index 6b44313ae..94a504bce 100644 --- a/frontend/projects/ui/src/app/services/api/mock-patch.ts +++ b/frontend/projects/ui/src/app/services/api/mock-patch.ts @@ -273,7 +273,6 @@ export const mockPatchData: DataModel = { 'emergency-contact': { name: 'Emergency Contact', type: 'object', - 'unique-by': null, description: 'The person to contact in case of emergency.', spec: { name: { @@ -316,7 +315,6 @@ export const mockPatchData: DataModel = { bitcoinNode: { name: 'Bitcoin Node Settings', type: 'union', - 'unique-by': null, description: 'The node settings', default: 'internal', warning: 'Careful changing this',