Skip to content

Commit

Permalink
feat: improved transaction typings - fixes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
ohager committed Jun 16, 2022
1 parent dc3b400 commit cea7f6a
Show file tree
Hide file tree
Showing 20 changed files with 418 additions and 228 deletions.
20 changes: 20 additions & 0 deletions public/_locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1859,5 +1859,25 @@
},
"messageFrom": {
"message": "Nachricht von"
},
"addTreasuryAccount": {
"message": "Treasury-Konto hinzufügen"
},
"originationOf": {
"message": "von $contract$",
"placeholders": {
"constract": {
"content": "$1"
}
}
},
"p2pMessage": {
"message": "P2P-Nachricht"
},
"tokenIssuance": {
"message": "Token-Erstellung"
},
"tokenMint": {
"message": "Münzprägung"
}
}
19 changes: 18 additions & 1 deletion public/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,14 @@
"origination": {
"message": "Contract Creation"
},
"originationOf": {
"message": "of $contract$",
"placeholders": {
"constract": {
"content": "$1"
}
}
},
"other": {
"message": "Other"
},
Expand Down Expand Up @@ -1862,5 +1870,14 @@
},
"messageFrom": {
"message": "Message from"
},
"tokenIssuance": {
"message": "Token Creation"
},
"tokenMint": {
"message": "Token Minting"
},
"addTreasuryAccount": {
"message": "Add Treasury Account"
}
}
}
20 changes: 20 additions & 0 deletions public/_locales/es/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1859,5 +1859,25 @@
},
"messageFrom": {
"message": "Mensaje de"
},
"addTreasuryAccount": {
"message": "Añadir cuenta de tesorería"
},
"originationOf": {
"message": "de $contract$",
"placeholders": {
"constract": {
"content": "$1"
}
}
},
"p2pMessage": {
"message": "Mensaje P2P"
},
"tokenIssuance": {
"message": "Creación de fichas"
},
"tokenMint": {
"message": "Acuñación de fichas"
}
}
20 changes: 20 additions & 0 deletions public/_locales/pt_BR/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1859,5 +1859,25 @@
},
"messageFrom": {
"message": "Mensagem de"
},
"addTreasuryAccount": {
"message": "Adicionar conta de tesouraria"
},
"originationOf": {
"message": "de $contract$",
"placeholders": {
"constract": {
"content": "$1"
}
}
},
"p2pMessage": {
"message": "Mensagem P2P"
},
"tokenIssuance": {
"message": "Criação de token"
},
"tokenMint": {
"message": "Cunhagem de Token"
}
}
20 changes: 20 additions & 0 deletions public/_locales/ru/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1859,5 +1859,25 @@
},
"messageFrom": {
"message": "Сообщение от"
},
"addTreasuryAccount": {
"message": "Добавить казначейский счет"
},
"originationOf": {
"message": "$contract$",
"placeholders": {
"constract": {
"content": "$1"
}
}
},
"p2pMessage": {
"message": "P2P-сообщение"
},
"tokenIssuance": {
"message": "Создание токена"
},
"tokenMint": {
"message": "Чеканка токенов"
}
}
20 changes: 20 additions & 0 deletions public/_locales/th/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1859,5 +1859,25 @@
},
"messageFrom": {
"message": "ข้อความจาก"
},
"addTreasuryAccount": {
"message": "เพิ่มบัญชีธนารักษ์"
},
"originationOf": {
"message": "ของ $contract$",
"placeholders": {
"constract": {
"content": "$1"
}
}
},
"p2pMessage": {
"message": "ข้อความ P2P"
},
"tokenIssuance": {
"message": "การสร้างโทเค็น"
},
"tokenMint": {
"message": "เหรียญกษาปณ์"
}
}
20 changes: 20 additions & 0 deletions public/_locales/uk/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1859,5 +1859,25 @@
},
"messageFrom": {
"message": "Повідомлення від"
},
"addTreasuryAccount": {
"message": "Додати казначейський рахунок"
},
"originationOf": {
"message": "$contract$",
"placeholders": {
"constract": {
"content": "$1"
}
}
},
"p2pMessage": {
"message": "P2P-повідомлення"
},
"tokenIssuance": {
"message": "Створення токена"
},
"tokenMint": {
"message": "Чеканка токенів"
}
}
File renamed without changes.
5 changes: 2 additions & 3 deletions src/app/pages/ImportAccount/WatchOnlyForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import NoSpaceField from 'app/atoms/NoSpaceField';
import { T, t } from 'lib/i18n/react';
import {
isSignumAddress,
SMART_CONTRACT_PUBLIC_KEY,
useSignum,
useSignumAccountPrefix,
useSignumAliasResolver,
Expand All @@ -21,8 +22,6 @@ interface WatchOnlyFormData {
address: string;
}

const SmartContractPk = '0000000000000000000000000000000000000000000000000000000000000000';

export const WatchOnlyForm: FC = () => {
const { importWatchOnlyAccount } = useTempleClient();
const signum = useSignum();
Expand Down Expand Up @@ -86,7 +85,7 @@ export const WatchOnlyForm: FC = () => {
}
// @ts-ignore
const publicKey = acc.publicKey;
if (!publicKey || publicKey === SmartContractPk) {
if (!publicKey || publicKey === SMART_CONTRACT_PUBLIC_KEY) {
throw new Error(t('cannotImportWatchAccount'));
}
return publicKey;
Expand Down
12 changes: 8 additions & 4 deletions src/app/templates/SignumActivity/ActivityItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import classNames from 'clsx';
import formatDistanceToNow from 'date-fns/formatDistanceToNow';

import OpenInExplorerChip from 'app/atoms/OpenInExplorerChip';
import Time from 'app/atoms/Time';
import HashChip from 'app/templates/HashChip';
import { getDateFnsLocale, t } from 'lib/i18n/react';
import { parseTransaction, parseAmountDiffs } from 'lib/temple/activity';
import { useSignumAssetMetadata, useSignumExplorerBaseUrls } from 'lib/temple/front';
import { useSignumAccountPrefix, useSignumAssetMetadata, useSignumExplorerBaseUrls } from 'lib/temple/front';

import MoneyDiffView from './MoneyDiffView';
import Time from './Time';
import TxItem from './TxItem';

type ActivityItemProps = {
Expand All @@ -24,12 +24,16 @@ type ActivityItemProps = {
const ActivityItem = memo<ActivityItemProps>(({ accountId, transaction, className }) => {
const { transaction: explorerBaseUrl } = useSignumExplorerBaseUrls();
const metadata = useSignumAssetMetadata();
const prefix = useSignumAccountPrefix();
const { transaction: txId, timestamp } = transaction;

const dateFnsLocale = getDateFnsLocale();
const moneyDiff = useMemo(() => parseAmountDiffs(transaction, accountId)[0], [transaction, accountId]);
const feeAmount = useMemo(() => Amount.fromPlanck(transaction.feeNQT!).getSigna(), [transaction.feeNQT]);
const parsedTransaction = useMemo(() => parseTransaction(transaction, accountId), [transaction, accountId]);
const parsedTransaction = useMemo(
() => parseTransaction(transaction, accountId, prefix),
[transaction, accountId, prefix]
);
const isPending = transaction.blockTimestamp === undefined;
const transactionStatus = useMemo(() => {
const content = isPending ? 'pending' : 'applied';
Expand Down Expand Up @@ -69,7 +73,7 @@ const ActivityItem = memo<ActivityItemProps>(({ accountId, transaction, classNam

<div className="flex flex-col flex-shrink-0">
<MoneyDiffView assetId="signa" diff={moneyDiff.diff} pending={isPending} />
<div className="text-xs text-gray-700 justify-end">
<div className="text-xs text-gray-700 text-right">
{feeAmount} {metadata.symbol}
</div>
</div>
Expand Down
50 changes: 39 additions & 11 deletions src/app/templates/SignumActivity/TxItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import classNames from 'clsx';
import { T, TProps } from 'lib/i18n/react';
import { TransactionItem, TransactionItemType } from 'lib/temple/activity';

import { ReactComponent as ClipboardIcon } from '../../icons/clipboard.svg';
import HashChip from '../HashChip';

type TxItemProps = {
Expand Down Expand Up @@ -34,21 +33,23 @@ const TxItemComponent = memo<TxItemComponentProps>(({ item }) => {
return {
base: (
<>
🤖&nbsp;
<T id="origination" />
</>
)
),
argsI18nKey: 'originationOf',
args: [item.contract]
};
// TODO: messages to smart contracts - problem: it has to be async to figure out if receiver is a contract
case TransactionItemType.Interaction:
return {
base: (
<>
<ClipboardIcon className="mr-1 h-3 w-auto stroke-current" />
⚙&nbsp;
<T id="interaction" />
</>
),
argsI18nKey: 'interactionWithContract',
args: [item.with]
args: [item.contract]
};

case TransactionItemType.TransferFrom:
Expand All @@ -72,14 +73,41 @@ const TxItemComponent = memo<TxItemComponentProps>(({ item }) => {
argsI18nKey: 'transferToSmb',
args: [item.to]
};

case TransactionItemType.MessageFrom:
return {
base: (
<>
{item.isEncrypted ? '🔐' : '✉'} <T id="p2pMessage" />
</>
),
argsI18nKey: 'transferFromSmb',
args: [item.from]
};
case TransactionItemType.MessageTo:
return {
base: (
<>
{item.isEncrypted ? '🔐' : '✉'} <T id="p2pMessage" />
</>
),
argsI18nKey: 'transferToSmb',
args: [item.to]
};
case TransactionItemType.SelfUpdate:
return {
base: (
<>
{item.prefix} <T id={item.i18nKey} />
</>
)
};
case TransactionItemType.Other:
return {
// TODO: once we have proper naming, need to adjust this.
base: item.name
.split('_')
.map(w => `${w.charAt(0).toUpperCase()}${w.substring(1)}`)
.join(' ')
base: (
<>
<T id={item.name} />
</>
)
};
}
})();
Expand Down
6 changes: 3 additions & 3 deletions src/app/templates/SignumP2PMessages/P2PMessageItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import classNames from 'clsx';
import formatDistanceToNow from 'date-fns/formatDistanceToNow';

import OpenInExplorerChip from 'app/atoms/OpenInExplorerChip';
import Time from 'app/atoms/Time';
import { ReactComponent as CopyIcon } from 'app/icons/copy.svg';
import { ReactComponent as LockAltIcon } from 'app/icons/lock-alt.svg';
import HashChip from 'app/templates/HashChip';
Expand All @@ -15,8 +16,6 @@ import { useAccount, useSignumExplorerBaseUrls, useTempleClient } from 'lib/temp
import useCopyToClipboard from 'lib/ui/useCopyToClipboard';
import useSafeState from 'lib/ui/useSafeState';

import Time from './Time';

type Props = {
accountId: string;
message: Transaction;
Expand Down Expand Up @@ -98,7 +97,8 @@ const P2PMessageItem = memo<Props>(({ accountId, message }) => {
</span>
)}
/>
<CopyButton toCopy={isEncrypted ? revealedMessage : plainMessage} />
{isEncrypted && revealedMessage && <CopyButton toCopy={revealedMessage} />}
{!isEncrypted && <CopyButton toCopy={plainMessage} />}
</div>
<div className="flex-1 flex-grow justify-end flex-wrap overflow-y-auto thin-scrollbar">
<div className="text-xs font-light text-gray-700">
Expand Down
23 changes: 0 additions & 23 deletions src/app/templates/SignumP2PMessages/Time.tsx

This file was deleted.

Loading

0 comments on commit cea7f6a

Please sign in to comment.