Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some adjustments and fixes #67

Merged
merged 4 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,23 @@
"prepare": "husky install"
},
"dependencies": {
"@babel/eslint-parser": "^7.17.0",
"@braintree/sanitize-url": "^6.0.2",
"@dicebear/avatars": "4.2.5",
"@dicebear/avatars-bottts-sprites": "4.2.5",
"@dicebear/avatars-jdenticon-sprites": "4.2.5",
"@popperjs/core": "2.4.4",
"@serh11p/jest-webextension-mock": "4.0.0",
"@signumjs/core": "^1.0.0-rc.53",
"@signumjs/crypto": "^1.0.0-rc.53",
"@signumjs/http": "^1.0.0-rc.53",
"@signumjs/standards": "^1.0.0-rc.53",
"@signumjs/util": "^1.0.0-rc.53",
"@signumjs/core": "^1.0.0-rc.58",
"@signumjs/crypto": "^1.0.0-rc.58",
"@signumjs/http": "^1.0.0-rc.58",
"@signumjs/standards": "^1.0.0-rc.58",
"@signumjs/util": "^1.0.0-rc.58",
"async-retry": "1.3.1",
"bignumber.js": "9.0.1",
"buffer": "5.6.0",
"clsx": "1.1.1",
"constate": "2.0.0",
"date-fns": "2.15.0",
"debounce-promise": "3.1.2",
"dexie": "3.1.0-beta.13",
"effector": "21.2.0",
"fast-deep-equal": "3.1.3",
Expand All @@ -54,8 +52,6 @@
"hashicon": "^0.3.0",
"inter-ui": "3.13.1",
"micro-memoize": "4.0.9",
"node-forge": "0.10.0",
"p-memoize": "4.0.3",
"react": "^17.0.2",
"react-dom": "16.13.1",
"react-hook-form": "5.3.1",
Expand All @@ -75,6 +71,7 @@
"webextension-polyfill": "^0.8.0"
},
"devDependencies": {
"@babel/eslint-parser": "^7.17.0",
"@babel/core": "^7.17.2",
"@babel/preset-env": "^7.16.11",
"@peculiar/webcrypto": "1.1.6",
Expand Down
12 changes: 12 additions & 0 deletions public/_locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1988,5 +1988,17 @@
},
"transferToMany": {
"message": "an viele"
},
"transferOwnership": {
"message": "Token-Besitz übertragen"
},
"subscriptionCancellation": {
"message": "Automatische Zahlung stornieren"
},
"subscriptionCreation": {
"message": "Automatische Zahlung erstellen"
},
"aliasSell": {
"message": "Alias verkaufen"
}
}
12 changes: 12 additions & 0 deletions public/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,9 @@
"aliasBuy": {
"message": "Buy Alias"
},
"aliasSell": {
"message": "Sell Alias"
},
"addCommitment": {
"message": "Add Commitment"
},
Expand Down Expand Up @@ -1988,5 +1991,14 @@
},
"sendToAddress": {
"message": "Send Signa to this Address"
},
"transferOwnership": {
"message": "Transfer Token Ownership"
},
"subscriptionCreation": {
"message": "Create Auto-Payment"
},
"subscriptionCancellation": {
"message": "Cancel Auto-Payment"
}
}
12 changes: 12 additions & 0 deletions public/_locales/es/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1988,5 +1988,17 @@
},
"transferToMany": {
"message": "demasiados"
},
"transferOwnership": {
"message": "Transferir la propiedad del token"
},
"subscriptionCancellation": {
"message": "Cancelar pago automático"
},
"subscriptionCreation": {
"message": "Crear pago automático"
},
"aliasSell": {
"message": "vender alias"
}
}
12 changes: 12 additions & 0 deletions public/_locales/pt_BR/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1988,5 +1988,17 @@
},
"transferToMany": {
"message": "para várias"
},
"transferOwnership": {
"message": "Transferir propriedade de token"
},
"subscriptionCancellation": {
"message": "Cancelar pagamento automático"
},
"subscriptionCreation": {
"message": "Criar pagamento automático"
},
"aliasSell": {
"message": "Vender Alias"
}
}
12 changes: 12 additions & 0 deletions public/_locales/ru/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1988,5 +1988,17 @@
},
"transferToMany": {
"message": "слишком много"
},
"transferOwnership": {
"message": "Передача владения токеном"
},
"subscriptionCancellation": {
"message": "Отменить автоплатеж"
},
"subscriptionCreation": {
"message": "Создать автоплатеж"
},
"aliasSell": {
"message": "Продать псевдоним"
}
}
12 changes: 12 additions & 0 deletions public/_locales/th/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1988,5 +1988,17 @@
},
"transferToMany": {
"message": "มากมาย"
},
"transferOwnership": {
"message": "โอนกรรมสิทธิ์โทเค็น"
},
"subscriptionCancellation": {
"message": "ยกเลิกการชำระเงินอัตโนมัติ"
},
"subscriptionCreation": {
"message": "สร้างการชำระเงินอัตโนมัติ"
},
"aliasSell": {
"message": "ขายนามแฝง"
}
}
12 changes: 12 additions & 0 deletions public/_locales/uk/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1988,5 +1988,17 @@
},
"transferToMany": {
"message": "забагато"
},
"transferOwnership": {
"message": "Передача права власності на токени"
},
"subscriptionCancellation": {
"message": "Скасувати автоматичну оплату"
},
"subscriptionCreation": {
"message": "Створіть автоматичний платіж"
},
"aliasSell": {
"message": "Продати псевдонім"
}
}
6 changes: 3 additions & 3 deletions src/app/templates/SignumP2PMessages/P2PMessageItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const P2PMessageItem = memo<Props>(({ accountId, message }) => {

const dateFnsLocale = getDateFnsLocale();
const isPending = message.blockTimestamp === undefined;
const isEncrypted = message.attachment.encryptedMessage;
const plainMessage = message.attachment.message;
const isReceivedMessage = message.sender !== accountId;
const isEncrypted = message.attachment && message.attachment.encryptedMessage;
const plainMessage = message.attachment ? message.attachment.message : '';
const isReceivedMessage = message.sender !== accountId || message.sender === message.recipient;

const transactionStatus = useMemo(() => {
const content = isPending ? 'pending' : 'applied';
Expand Down
28 changes: 28 additions & 0 deletions src/lib/temple/activity/parseTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ function isDistribution(tx: Transaction): boolean {
return tx.type === TransactionType.Asset && tx.subtype === TransactionAssetSubtype.AssetDistributeToHolders;
}

function isSubscriptionCreation(tx: Transaction): boolean {
return tx.type === TransactionType.Escrow && tx.subtype === TransactionEscrowSubtype.SubscriptionSubscribe;
}
function isSubscriptionCancellation(tx: Transaction): boolean {
return tx.type === TransactionType.Escrow && tx.subtype === TransactionEscrowSubtype.SubscriptionCancel;
}

function isBurn(tx: Transaction): boolean {
return (
!tx.recipient &&
Expand Down Expand Up @@ -107,6 +114,9 @@ function isContractTransaction(tx: Transaction): boolean {
function isAddTreasuryAccount(tx: Transaction) {
return tx.type === TransactionType.Asset && tx.subtype === TransactionAssetSubtype.AssetAddTreasureyAccount;
}
function isTokenTransferOwnership(tx: Transaction) {
return tx.type === TransactionType.Asset && tx.subtype === TransactionAssetSubtype.AssetTransferOwnership;
}

export function parseTransaction(tx: Transaction, accountId: string, accountPrefix: string): TransactionItem {
// @ts-ignore
Expand Down Expand Up @@ -150,6 +160,24 @@ export function parseTransaction(tx: Transaction, accountId: string, accountPref
item.prefix = '🏦';
// @ts-ignore
item.name = 'addTreasuryAccount';
} else if (isTokenTransferOwnership(tx)) {
item.type = TransactionItemType.Other;
// @ts-ignore
item.prefix = '➡🪙';
// @ts-ignore
item.name = 'transferOwnership';
} else if (isSubscriptionCreation(tx)) {
item.type = TransactionItemType.Other;
// @ts-ignore
item.prefix = '🕖✨';
// @ts-ignore
item.name = 'subscriptionCreation';
} else if (isSubscriptionCancellation(tx)) {
item.type = TransactionItemType.Other;
// @ts-ignore
item.prefix = '❌🕖';
// @ts-ignore
item.name = 'subscriptionCreation';
} else {
item.type = TransactionItemType.Other;
// TODO: name the type more precisely
Expand Down
60 changes: 58 additions & 2 deletions src/lib/temple/front/parseSignumTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Transaction,
TransactionArbitrarySubtype,
TransactionAssetSubtype,
TransactionEscrowSubtype,
TransactionMiningSubtype,
TransactionPaymentSubtype,
TransactionSmartContractSubtype,
Expand Down Expand Up @@ -77,7 +78,11 @@ function isTransactionToSelf(tx: Transaction): boolean {
}

async function eventuallyResolveTokenId(signum: Ledger, jsonTx: Transaction) {
if (jsonTx.type === TransactionType.Asset && jsonTx.subtype === TransactionAssetSubtype.AssetAddTreasureyAccount) {
if (
jsonTx.type === TransactionType.Asset &&
(jsonTx.subtype === TransactionAssetSubtype.AssetAddTreasureyAccount ||
jsonTx.subtype === TransactionAssetSubtype.AssetTransferOwnership)
) {
try {
const tx = await signum.service.query<Transaction>('getTransaction', {
fullHash: jsonTx.referencedTransactionFullHash
Expand All @@ -89,7 +94,6 @@ async function eventuallyResolveTokenId(signum: Ledger, jsonTx: Transaction) {
return Promise.resolve(undefined);
}
}

return Promise.resolve(undefined);
}

Expand Down Expand Up @@ -140,6 +144,8 @@ function parseTransactionExpenses(tx: Transaction, resolvedTokenId?: string): Pa
switch (tx.type) {
case TransactionType.Payment:
return parsePaymentExpenses(tx);
case TransactionType.Escrow:
return parseEscrowExpenses(tx);
case TransactionType.Asset:
return parseAssetExpenses(tx, resolvedTokenId);
case TransactionType.AT:
Expand Down Expand Up @@ -316,6 +322,13 @@ function parseAssetExpenses(tx: Transaction, resolvedTokenId?: string): ParsedTr
tokenId: resolvedTokenId
}
];
case TransactionAssetSubtype.AssetTransferOwnership:
return [
{
to: tx.recipient || BURN_ADDRESS,
tokenId: resolvedTokenId
}
];
case TransactionAssetSubtype.AssetTransfer:
default:
return [
Expand Down Expand Up @@ -348,12 +361,30 @@ function parsePaymentExpenses(tx: Transaction): ParsedTransactionExpense[] {
}
}

function parseEscrowExpenses(tx: Transaction): ParsedTransactionExpense[] {
if (tx.subtype === TransactionEscrowSubtype.SubscriptionCancel) {
return [
{
to: tx.sender // self
}
];
}
return [
{
to: tx.recipient || BURN_ADDRESS,
amount: new BigNumber(tx?.amountNQT || 0)
}
];
}

// -- TYPE SECTION

function parseTransactionType(tx: Transaction): ParsedTransactionType {
switch (tx.type) {
case TransactionType.Payment:
return parsePaymentSubType(tx);
case TransactionType.Escrow:
return parseEscrowSubType(tx);
case TransactionType.Asset:
return parseAssetSubType(tx);
case TransactionType.AT:
Expand Down Expand Up @@ -385,6 +416,25 @@ function parsePaymentSubType(tx: Transaction): ParsedTransactionType {
};
}

function parseEscrowSubType(tx: Transaction): ParsedTransactionType {
switch (tx.subtype) {
case TransactionEscrowSubtype.SubscriptionCancel:
return {
i18nKey: 'subscriptionCancellation',
textIcon: '❌🕖',
hasAmount: false
};
case TransactionEscrowSubtype.SubscriptionSubscribe:
return {
i18nKey: 'subscriptionCreation',
textIcon: '🕖✨',
hasAmount: true
};
}

return throwInappropriateTransactionType();
}

function parseAssetSubType(tx: Transaction): ParsedTransactionType {
switch (tx.subtype) {
case TransactionAssetSubtype.AssetTransfer:
Expand Down Expand Up @@ -448,6 +498,12 @@ function parseAssetSubType(tx: Transaction): ParsedTransactionType {
textIcon: '🏦',
hasAmount: false
};
case TransactionAssetSubtype.AssetTransferOwnership:
return {
i18nKey: 'transferOwnership',
textIcon: '➡🪙',
hasAmount: false
};
}
return throwInappropriateTransactionType();
}
Expand Down
Loading