Skip to content

Commit

Permalink
Merge pull request #66 from multiversx/development
Browse files Browse the repository at this point in the history
Fix verify message
  • Loading branch information
CiprianDraghici committed Nov 6, 2023
2 parents 7e6c691 + 7c20c2c commit be9d464
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 74 deletions.
18 changes: 8 additions & 10 deletions src/pages/Authentication/AuthenticationContent.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useChain } from 'hooks/useChain';
import { Input } from './components/Input';
import { Metric } from './components/Metric';
import styles from './styles.module.scss';
import { useChain } from 'hooks/useChain';
import { useAuthenticationContext } from './context';
import styles from './styles.module.scss';

export const AuthenticationContent = () => {
const { chain } = useChain();
const { metrics, metricItems } = useAuthenticationContext();
const { metricItems } = useAuthenticationContext();

return (
<div className={styles.authentication}>
Expand All @@ -21,13 +21,11 @@ export const AuthenticationContent = () => {
<span>Decoded</span>
</h2>

{metrics && (
<div className={styles.metrics}>
{metricItems.map((metric) => (
<Metric key={metric.identifier} chain={chain} {...metric} />
))}
</div>
)}
<div className={styles.metrics}>
{metricItems.map((metric) => (
<Metric key={metric.identifier} chain={chain} {...metric} />
))}
</div>
</div>
</div>
);
Expand Down
16 changes: 2 additions & 14 deletions src/pages/Authentication/components/Input/hooks/useTokenActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,6 @@ export const useTokenActions = () => {
const [decoded, valid] = await Promise.allSettled(promises);
setIsValidating(false);

const tokenExpired =
valid.status === 'rejected' &&
['Token expired', 'maxExpirySeconds'].some((x) =>
valid.reason.message.includes(x),
);

if (tokenExpired) {
setFieldError('token', 'Token Expired');
setFieldError('message', undefined);
return;
}

if (decoded.status === 'rejected') {
setFieldError('token', 'Token Undecodable');
setFieldError(
Expand All @@ -75,8 +63,8 @@ export const useTokenActions = () => {
}

if (valid.status === 'rejected') {
setFieldError('token', 'Token Invalid');
setFieldError('message', "Signature doesn't match.");
setFieldError('token', valid.reason.message ?? 'Token Invalid');
setFieldError('message', undefined);
return;
}

Expand Down
43 changes: 3 additions & 40 deletions src/pages/Authentication/constants/metrics.contants.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,11 @@
import { DefaultMetricType, MetricType } from '../types';
import { EnvironmentsEnum } from '@multiversx/sdk-dapp/types';
import { MetricType } from '../types';

export const emptyMetrics: MetricType = {
address: '',
blockHash: '',
signature: '',
body: '',
host: '',
origin: '',
ttl: 0,
extraInfo: {}
};

export const DEFAULT_METRICS: DefaultMetricType = {
[EnvironmentsEnum.mainnet]: {
address: 'erd1wjytfn6zhqfcsejvhwv7q4usazs5ryc3j8hc78fldgjnyct8wejqkasunc',
blockHash:
'f68177510756edce45eca84b94544a6eacdfa36e69dfd3b8f24c4010d1990751',
signature:
'a29dba3f0d2fb4712cb662bc8050c87bf9f0e7fd28f3c98efe0fda074be5b087bd75c075243e832c2985a9da044496b2cff3c852c8c963f9d3d840aed8799c07',
body: 'bG9jYWxob3N0.f68177510756edce45eca84b94544a6eacdfa36e69dfd3b8f24c4010d1990751.300.eyJ0aW1lc3RhbXAiOjE2NzM5NzIyNDR9',
host: 'localhost',
ttl: 300,
extraInfo: { timestamp: 1673972244 }
},
[EnvironmentsEnum.devnet]: {
address: 'erd1wjytfn6zhqfcsejvhwv7q4usazs5ryc3j8hc78fldgjnyct8wejqkasunc',
blockHash:
'18bc982461d1b53c837a24de4b4623c2bb835867ea2e8df14365cf436dee1b23',
signature:
'f8d651eda06e82a894ff1dc9480a33aa1030b076dfd5983346eec6793381587b88c2daf770a10ac39f9911968c2f1d1304c0c7dd86a82bc79f07e89f873f7e02',
body: 'bG9jYWxob3N0.18bc982461d1b53c837a24de4b4623c2bb835867ea2e8df14365cf436dee1b23.600.eyJ0aW1lc3RhbXAiOjE2NzM5NzIzNjR9',
host: 'localhost',
ttl: 600,
extraInfo: { timestamp: 1673972364 }
},
[EnvironmentsEnum.testnet]: {
address: 'erd1wjytfn6zhqfcsejvhwv7q4usazs5ryc3j8hc78fldgjnyct8wejqkasunc',
blockHash:
'7d7418279345fbf1b3e0054032d1c3e3b2324b98223cc6a825e76f4fbfd4a7dd',
signature:
'6912c4dddb58fbc8aa3ee210c9a6e6e66847abcd6eebe72fe5b5df02632598c9b568c3b3499eea3d62f321db7aab3e5e7fef293f8ae17aaa6042141bd6a23208',
body: 'bG9jYWxob3N0.7d7418279345fbf1b3e0054032d1c3e3b2324b98223cc6a825e76f4fbfd4a7dd.900.eyJ0aW1lc3RhbXAiOjE2NzM5NzM5MDZ9',
host: 'localhost',
ttl: 900,
extraInfo: { timestamp: 1673973906 }
}
extraInfo: {},
};
17 changes: 7 additions & 10 deletions src/pages/Authentication/context/AuthenticationContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
} from 'react';
import axios from 'axios';
import { miscApi } from 'config';
import { useChain } from 'hooks/useChain';
import { DEFAULT_METRICS } from '../constants';
import { TokenColorsEnum } from '../enum';
import { MetricItemType, MetricType } from '../types';

Expand Down Expand Up @@ -46,8 +44,7 @@ export const useAuthenticationContext = () => {
};

export const useAuthenticationValue = () => {
const { chain } = useChain();
const [metrics, setMetrics] = useState<MetricType>(DEFAULT_METRICS[chain]);
const [metrics, setMetrics] = useState<MetricType>();
const [initialTokens, setInitialTokens] = useState<InitialTokensType>();
const [fetchingInitialTokens, setFetchingInitialTokens] = useState<boolean>();
const [isValidating, setIsValidating] = useState<boolean>();
Expand All @@ -58,7 +55,7 @@ export const useAuthenticationValue = () => {
name: 'Address',
identifier: 'address',
colors: [TokenColorsEnum.address],
data: metrics ? metrics.address : undefined,
data: metrics?.address,
},
{
name: 'Body',
Expand All @@ -69,20 +66,20 @@ export const useAuthenticationValue = () => {
TokenColorsEnum.ttl,
TokenColorsEnum.extra,
],
data: metrics ? metrics.body : undefined,
data: metrics?.body,
},
{
name: 'Origin',
identifier: 'origin',
colors: [TokenColorsEnum.origin],
data: metrics ? metrics.origin : undefined,
data: metrics?.origin,
subItem: true,
},
{
name: 'Block Hash',
identifier: 'blockHash',
colors: [TokenColorsEnum.blockHash],
data: metrics ? metrics.blockHash : undefined,
data: metrics?.blockHash,
explorer: metrics ? `/blocks/${metrics.blockHash}` : '',
subItem: true,
},
Expand All @@ -91,7 +88,7 @@ export const useAuthenticationValue = () => {
name: 'Time to live (seconds)',
identifier: 'ttl',
colors: [TokenColorsEnum.ttl],
data: metrics ? metrics.ttl : undefined,
data: metrics?.ttl,
subItem: true,
},
{
Expand All @@ -108,7 +105,7 @@ export const useAuthenticationValue = () => {
name: 'Signature',
identifier: 'signature',
colors: [TokenColorsEnum.signature],
data: metrics ? metrics.signature : undefined,
data: metrics?.signature,
},
],
[metrics],
Expand Down

0 comments on commit be9d464

Please sign in to comment.