some fixes
how the id is shown refactoring some settings to use hooks
This commit is contained in:
parent
ea65d04f0c
commit
b023bb502e
@ -72,7 +72,7 @@ const exampleData = {
|
|||||||
summary: 'the summary',
|
summary: 'the summary',
|
||||||
fulfillmentMessage: '',
|
fulfillmentMessage: '',
|
||||||
},
|
},
|
||||||
proposalId: '#proposalId',
|
proposalId: '1EMJJH8EP1NX3XF7733NCYS2DBEJW4Q2KA5KEB37MCQJQ8Q5HMC0',
|
||||||
status: PaymentStatus.Accepted,
|
status: PaymentStatus.Accepted,
|
||||||
} as TransactionPayment,
|
} as TransactionPayment,
|
||||||
deposit: {
|
deposit: {
|
||||||
@ -94,7 +94,7 @@ const exampleData = {
|
|||||||
refund: {
|
refund: {
|
||||||
...commonTransaction,
|
...commonTransaction,
|
||||||
type: TransactionType.Refund,
|
type: TransactionType.Refund,
|
||||||
refundedTransactionId: '#refundId',
|
refundedTransactionId: 'payment:1EMJJH8EP1NX3XF7733NCYS2DBEJW4Q2KA5KEB37MCQJQ8Q5HMC0',
|
||||||
info: {
|
info: {
|
||||||
contractTermsHash: 'ASDZXCASD',
|
contractTermsHash: 'ASDZXCASD',
|
||||||
merchant: {
|
merchant: {
|
||||||
|
@ -46,7 +46,7 @@ import { useEffect, useState } from "preact/hooks";
|
|||||||
import * as i18n from "../i18n";
|
import * as i18n from "../i18n";
|
||||||
import { PageLink, renderAmount } from "../renderHtml";
|
import { PageLink, renderAmount } from "../renderHtml";
|
||||||
import * as wxApi from "../wxApi";
|
import * as wxApi from "../wxApi";
|
||||||
import { PermissionsCheckbox } from "./welcome";
|
import { PermissionsCheckbox, useExtendedPermissions, Diagnostics } from "./welcome";
|
||||||
|
|
||||||
interface TabProps {
|
interface TabProps {
|
||||||
target: string;
|
target: string;
|
||||||
@ -452,7 +452,7 @@ export function WalletTransactionView({ transaction, onDelete, onBack }: WalletT
|
|||||||
|
|
||||||
function Pending() {
|
function Pending() {
|
||||||
if (!transaction?.pending) return null
|
if (!transaction?.pending) return null
|
||||||
return <span style={{fontWeight:'normal', fontSize:16, color: 'gray'}}>(pending...)</span>
|
return <span style={{ fontWeight: 'normal', fontSize: 16, color: 'gray' }}>(pending...)</span>
|
||||||
}
|
}
|
||||||
|
|
||||||
function CommonFields() {
|
function CommonFields() {
|
||||||
@ -503,7 +503,7 @@ export function WalletTransactionView({ transaction, onDelete, onBack }: WalletT
|
|||||||
return (
|
return (
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', flex: 1, minHeight: '20rem' }} >
|
<div style={{ display: 'flex', flexDirection: 'column', flex: 1, minHeight: '20rem' }} >
|
||||||
<section>
|
<section>
|
||||||
<h1>Payment ({transaction.proposalId}) <Pending /></h1>
|
<h1>Payment ({transaction.proposalId.substring(0, 10)}...) <Pending /></h1>
|
||||||
<p>
|
<p>
|
||||||
To <b>{transaction.info.merchant.name}</b>
|
To <b>{transaction.info.merchant.name}</b>
|
||||||
</p>
|
</p>
|
||||||
@ -519,7 +519,7 @@ export function WalletTransactionView({ transaction, onDelete, onBack }: WalletT
|
|||||||
{transaction.info.products && transaction.info.products.length > 0 &&
|
{transaction.info.products && transaction.info.products.length > 0 &&
|
||||||
<tr>
|
<tr>
|
||||||
<td>Products</td>
|
<td>Products</td>
|
||||||
<td><ol style={{margin:0, textAlign:'left'}}>
|
<td><ol style={{ margin: 0, textAlign: 'left' }}>
|
||||||
{transaction.info.products.map(p =>
|
{transaction.info.products.map(p =>
|
||||||
<li>{p.description}</li>
|
<li>{p.description}</li>
|
||||||
)}</ol></td>
|
)}</ol></td>
|
||||||
@ -584,11 +584,12 @@ export function WalletTransactionView({ transaction, onDelete, onBack }: WalletT
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TRANSACTION_FROM_REFUND = /[a-z]*:([\w]{10}).*/
|
||||||
if (transaction.type === TransactionType.Refund) {
|
if (transaction.type === TransactionType.Refund) {
|
||||||
return (
|
return (
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', flex: 1, minHeight: '20rem' }} >
|
<div style={{ display: 'flex', flexDirection: 'column', flex: 1, minHeight: '20rem' }} >
|
||||||
<section>
|
<section>
|
||||||
<h1>Refund ({transaction.refundedTransactionId}) <Pending /></h1>
|
<h1>Refund ({TRANSACTION_FROM_REFUND.exec(transaction.refundedTransactionId)![1]}...) <Pending /></h1>
|
||||||
<p>
|
<p>
|
||||||
From <b>{transaction.info.merchant.name}</b>
|
From <b>{transaction.info.merchant.name}</b>
|
||||||
</p>
|
</p>
|
||||||
@ -633,6 +634,8 @@ function WalletTransaction({ tid }: { tid: string }): JSX.Element {
|
|||||||
const ts = res.transactions.filter(t => t.transactionId === tid)
|
const ts = res.transactions.filter(t => t.transactionId === tid)
|
||||||
if (ts.length === 1) {
|
if (ts.length === 1) {
|
||||||
setTransaction(ts[0]);
|
setTransaction(ts[0]);
|
||||||
|
} else {
|
||||||
|
route(Pages.history)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchData();
|
fetchData();
|
||||||
@ -640,20 +643,55 @@ function WalletTransaction({ tid }: { tid: string }): JSX.Element {
|
|||||||
|
|
||||||
return <WalletTransactionView
|
return <WalletTransactionView
|
||||||
transaction={transaction}
|
transaction={transaction}
|
||||||
onDelete={() => wxApi.deleteTransaction(tid)}
|
onDelete={() => wxApi.deleteTransaction(tid).then(_ => history.go(-1))}
|
||||||
onBack={() => { history.go(-1) }}
|
onBack={() => { history.go(-1) }}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|
||||||
class WalletSettings extends Component<any, any> {
|
function WalletSettings() {
|
||||||
render(): JSX.Element {
|
const [permissionsEnabled, togglePermissions] = useExtendedPermissions()
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h2>Permissions</h2>
|
<h2>Permissions</h2>
|
||||||
<PermissionsCheckbox />
|
<PermissionsCheckbox enabled={permissionsEnabled} onToggle={togglePermissions} />
|
||||||
</div>
|
{/*
|
||||||
);
|
<h2>Developer mode</h2>
|
||||||
}
|
<DebugCheckbox enabled={permissionsEnabled} onToggle={togglePermissions} />
|
||||||
|
*/}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function DebugCheckbox({ enabled, onToggle }: { enabled: boolean, onToggle: () => void }): JSX.Element {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<input
|
||||||
|
checked={enabled}
|
||||||
|
onClick={onToggle}
|
||||||
|
type="checkbox"
|
||||||
|
id="checkbox-perm"
|
||||||
|
style={{ width: "1.5em", height: "1.5em", verticalAlign: "middle" }}
|
||||||
|
/>
|
||||||
|
<label
|
||||||
|
htmlFor="checkbox-perm"
|
||||||
|
style={{ marginLeft: "0.5em", fontWeight: "bold" }}
|
||||||
|
>
|
||||||
|
Automatically open wallet based on page content
|
||||||
|
</label>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color: "#383838",
|
||||||
|
fontSize: "smaller",
|
||||||
|
display: "block",
|
||||||
|
marginLeft: "2em",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
(Enabling this option below will make using the wallet faster, but
|
||||||
|
requires more permissions from your browser.)
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function reload(): void {
|
function reload(): void {
|
||||||
@ -685,6 +723,7 @@ function WalletDebug(props: any): JSX.Element {
|
|||||||
<br />
|
<br />
|
||||||
<button onClick={confirmReset}>reset</button>
|
<button onClick={confirmReset}>reset</button>
|
||||||
<button onClick={reload}>reload chrome extension</button>
|
<button onClick={reload}>reload chrome extension</button>
|
||||||
|
<Diagnostics />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ import { extendedPermissions } from "../permissions";
|
|||||||
import { WalletDiagnostics } from "@gnu-taler/taler-util";
|
import { WalletDiagnostics } from "@gnu-taler/taler-util";
|
||||||
import { Fragment, JSX } from "preact/jsx-runtime";
|
import { Fragment, JSX } from "preact/jsx-runtime";
|
||||||
|
|
||||||
function Diagnostics(): JSX.Element | null {
|
export function Diagnostics(): JSX.Element | null {
|
||||||
const [timedOut, setTimedOut] = useState(false);
|
const [timedOut, setTimedOut] = useState(false);
|
||||||
const [diagnostics, setDiagnostics] = useState<WalletDiagnostics | undefined>(
|
const [diagnostics, setDiagnostics] = useState<WalletDiagnostics | undefined>(
|
||||||
undefined,
|
undefined,
|
||||||
@ -128,29 +128,32 @@ async function handleExtendedPerm(isEnabled: boolean): Promise<boolean> {
|
|||||||
return nextVal ?? false
|
return nextVal ?? false
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PermissionsCheckbox(): JSX.Element {
|
export function useExtendedPermissions(): [boolean, () => void] {
|
||||||
const [extendedPermissionsEnabled, setExtendedPermissionsEnabled] = useState(false);
|
const [enabled, setEnabled] = useState(false);
|
||||||
|
|
||||||
const togglePermission = () => {
|
const toggle = () => {
|
||||||
setExtendedPermissionsEnabled(v => !v)
|
setEnabled(v => !v)
|
||||||
handleExtendedPerm(extendedPermissionsEnabled).then( result => {
|
handleExtendedPerm(enabled).then( result => {
|
||||||
setExtendedPermissionsEnabled(result)
|
setEnabled(result)
|
||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getExtendedPermValue(): Promise<void> {
|
async function getExtendedPermValue(): Promise<void> {
|
||||||
const res = await wxApi.getExtendedPermissions();
|
const res = await wxApi.getExtendedPermissions();
|
||||||
setExtendedPermissionsEnabled(res.newValue);
|
setEnabled(res.newValue);
|
||||||
}
|
}
|
||||||
getExtendedPermValue();
|
getExtendedPermValue();
|
||||||
},[]);
|
},[]);
|
||||||
|
return [enabled, toggle]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PermissionsCheckbox({enabled, onToggle}: {enabled:boolean, onToggle: () => void}): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<input
|
<input
|
||||||
checked={extendedPermissionsEnabled}
|
checked={enabled}
|
||||||
onClick={togglePermission}
|
onClick={onToggle}
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id="checkbox-perm"
|
id="checkbox-perm"
|
||||||
style={{ width: "1.5em", height: "1.5em", verticalAlign: "middle" }}
|
style={{ width: "1.5em", height: "1.5em", verticalAlign: "middle" }}
|
||||||
@ -177,12 +180,13 @@ export function PermissionsCheckbox(): JSX.Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Welcome(): JSX.Element {
|
export function Welcome(): JSX.Element {
|
||||||
|
const [permissionsEnabled, togglePermissions] = useExtendedPermissions()
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p>Thank you for installing the wallet.</p>
|
<p>Thank you for installing the wallet.</p>
|
||||||
<Diagnostics />
|
<Diagnostics />
|
||||||
<h2>Permissions</h2>
|
<h2>Permissions</h2>
|
||||||
<PermissionsCheckbox />
|
<PermissionsCheckbox enabled={permissionsEnabled} onToggle={togglePermissions}/>
|
||||||
<h2>Next Steps</h2>
|
<h2>Next Steps</h2>
|
||||||
<a href="https://demo.taler.net/" style={{ display: "block" }}>
|
<a href="https://demo.taler.net/" style={{ display: "block" }}>
|
||||||
Try the demo »
|
Try the demo »
|
||||||
|
Loading…
Reference in New Issue
Block a user