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

[DDW-663] Use asset policyId+name as unique identifier instead of the fingerprint #2562

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Changelog

### Chores

- Changed the assets identifiers from fingerprint to policyId+name ([PR 2562](https://github.com/input-output-hk/daedalus/pull/2562))
- Implemented the Items Dropdown component and simplified the Wallets and Assets Dropdowns ([PR 2540](https://github.com/input-output-hk/daedalus/pull/2540))
- Included wallet names in dialog windows ([PR 2552](https://github.com/input-output-hk/daedalus/pull/2552))
- Updated `cardano-cli` version to always match the one from `cardano-wallet` ([PR 2561](https://github.com/input-output-hk/daedalus/pull/2561))
Expand Down
6 changes: 3 additions & 3 deletions source/renderer/app/actions/assets-actions.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// @flow
import Action from './lib/Action';
import type { WalletSummaryAsset } from '../api/assets/types';
import type { AssetToken } from '../api/assets/types';

// ======= ASSETS ACTIONS =======

export default class AssetsActions {
onAssetSettingsOpen: Action<{ asset: WalletSummaryAsset }> = new Action();
onAssetSettingsOpen: Action<{ asset: AssetToken }> = new Action();
onAssetSettingsSubmit: Action<{
asset: WalletSummaryAsset,
asset: AssetToken,
decimals: number,
}> = new Action();
onAssetSettingsCancel: Action<any> = new Action();
Expand Down
9 changes: 4 additions & 5 deletions source/renderer/app/actions/wallets-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
} from '../../../common/types/hardware-wallets.types';
import type { CsvFileContent } from '../../../common/types/csv-request.types';
import type { QuitStakePoolRequest } from '../api/staking/types';
import type { WalletSummaryAsset } from '../api/assets/types';
import type { AssetToken } from '../api/assets/types';

export type WalletImportFromFileParams = {
filePath: string,
Expand Down Expand Up @@ -55,7 +55,7 @@ export default class WalletsActions {
receiver: string,
amount: string,
passphrase: string,
assets?: Array<WalletSummaryAsset>,
assets?: Array<AssetToken>,
assetsAmounts?: Array<string>,
}> = new Action();
chooseWalletExportType: Action<{
Expand Down Expand Up @@ -89,9 +89,8 @@ export default class WalletsActions {
finishRewardsCsv: Action<any> = new Action();

/* ---------- Transfer Funds ---------- */
setActiveAssetFingerprint: Action<{
fingerprint: ?string,
}> = new Action();
setActiveAsset: Action<string> = new Action();
unsetActiveAsset: Action<any> = new Action();
transferFundsNextStep: Action<any> = new Action();
transferFundsPrevStep: Action<any> = new Action();
transferFundsSetSourceWalletId: Action<{
Expand Down
4 changes: 3 additions & 1 deletion source/renderer/app/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2851,16 +2851,18 @@ const _createAssetFromServerData = action(
fingerprint,
metadata,
} = data;
const uniqueId = `${policyId}${assetName}`;
thedanheller marked this conversation as resolved.
Show resolved Hide resolved
const { decimals } = localData;
const recommendedDecimals =
ASSETS_PREDEFINED_DECIMALS[policyId + assetName];
ASSETS_PREDEFINED_DECIMALS[`${policyId}${assetName}`];
return new Asset({
policyId,
assetName,
fingerprint,
metadata,
decimals,
recommendedDecimals,
uniqueId,
});
}
);
Expand Down
4 changes: 2 additions & 2 deletions source/renderer/app/api/assets/requests/getAssets.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// @flow
import type { RequestConfig } from '../../common/types';
import { request } from '../../utils/request';
import type { Assets, GetAssetsRequest } from '../types';
import type { ApiAssets, GetAssetsRequest } from '../types';
import { getRawWalletId, isLegacyWalletId } from '../../utils';

export const getAssets = (
config: RequestConfig,
{ walletId }: GetAssetsRequest
): Promise<Assets> =>
): Promise<ApiAssets> =>
request({
method: 'GET',
path: `/v2/${
Expand Down
109 changes: 60 additions & 49 deletions source/renderer/app/api/assets/types.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,88 @@
// @flow
import BigNumber from 'bignumber.js';

import Asset from '../../domains/Asset';
import AssetDomain from '../../domains/Asset';

export type SingleAsset = {
/**
*
* ASSET
* Fetched from the Assets API endpoint
* It's not attached to a particular wallet or transaction
* Therefore, it doesn't have `quantity` nor `address`
*
* Exclusive data: fingerprint, metadata
* Missing data: quantity, address
*
*/
export type ApiAsset = {
policy_id: string,
asset_name: string,
fingerprint: string,
metadata?: ?AssetMetadata,
};

export type ApiAsset = {
policy_id: string,
asset_name: string,
export type ApiAssets = Array<ApiAsset>;
export type Asset = {
assetName: string,
decimals: ?number,
fingerprint: string,
metadata?: ?AssetMetadata,
policyId: string,
recommendedDecimals: ?number,
uniqueId: string,
};

export type AssetMetadata = {
name: string,
ticker: string,
description: string,
unit?: {
decimals: number,
name: string,
},
url?: string,
logo?: string,
};

export type AssetItem = {
/**
*
* TOKEN
* Asset that is attached to a particular wallet and/or transaction
* It doesn't have the Asset details (fingerprint, metadata)
*
* Exclusive data: quantity, address
* Missing data: fingerprint, metadata
*
*/
export type ApiToken = {
policy_id: string,
asset_name: string,
quantity: number,
address?: ?string,
};

export type WalletAssetItem = {
export type ApiTokens = Array<ApiToken>;
DominikGuzei marked this conversation as resolved.
Show resolved Hide resolved
export type Token = {
policyId: string,
assetName: string,
quantity: BigNumber,
address?: ?string,
};

export type Assets = Array<SingleAsset>;

export type AssetItems = Array<AssetItem>;

export type WalletAssetItems = Array<WalletAssetItem>;

export type WalletAssets = {
available: WalletAssetItems,
total: WalletAssetItems,
export type Tokens = Array<Token>;
export type WalletTokens = {
available: Tokens,
total: Tokens,
};

export type WalletSummaryAsset = {
policyId: string,
assetName: string,
fingerprint: string,
quantity: BigNumber,
metadata: ?AssetMetadata,
decimals: ?number,
recommendedDecimals: ?number,
/**
*
* ASSET TOKEN
* Merged object from a Token and its relative Asset details
*
* It has all the data combined: quantity, address, fingerprint, metadata, etc.
*
*/
export type AssetToken = {
...$Exact<Token>,
...$Exact<Asset>,
};

export type WalletTransactionAsset = {
policyId: string,
assetName: string,
quantity: BigNumber,
fingerprint: string,
metadata: ?AssetMetadata,
address?: ?string,
decimals: ?number,
recommendedDecimals: ?number,
export type AssetMetadata = {
name: string,
ticker: string,
description: string,
unit?: {
decimals?: number,
name: string,
},
url?: string,
logo?: string,
};

export type GetUnknownAssetRequest = {
Expand All @@ -84,6 +95,6 @@ export type GetAssetsRequest = {
};

export type GetAssetsResponse = {
assets: Array<Asset>,
assets: Array<AssetDomain>,
total: number,
};
14 changes: 7 additions & 7 deletions source/renderer/app/api/transactions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import BigNumber from 'bignumber.js';
import { WalletTransaction } from '../../domains/WalletTransaction';
import { WalletUnits } from '../../domains/Wallet';
import type { DelegationAction } from '../../types/stakingTypes';
import type { AssetItems } from '../assets/types';
import type { ApiTokens } from '../assets/types';
import type { TransactionMetadata } from '../../types/TransactionMetadata';

export type TransactionAmount = {
Expand Down Expand Up @@ -60,15 +60,15 @@ export type Transactions = Array<Transaction>;
export type TransactionInputs = {
address: string,
amount?: TransactionAmount,
assets?: AssetItems,
assets?: ApiTokens,
id: string,
index: number,
};

export type TransactionOutputs = {
address: string,
amount: TransactionAmount,
assets?: AssetItems,
assets?: ApiTokens,
};

export type TransactionWithdrawals = {
Expand Down Expand Up @@ -114,7 +114,7 @@ export type GetTransactionFeeRequest = {
walletId: string,
address: string,
amount: number,
assets?: AssetItems,
assets?: ApiTokens,
walletBalance: BigNumber,
availableBalance: BigNumber,
rewardsBalance: BigNumber,
Expand All @@ -133,7 +133,7 @@ export type CreateTransactionRequest = {
amount: number,
passphrase: string,
isLegacy: boolean,
assets?: AssetItems,
assets?: ApiTokens,
withdrawal?: 'self' | Array<string>,
};

Expand Down Expand Up @@ -171,7 +171,7 @@ export type GetTransactionFeeParams = {
export type TransactionPaymentData = {
address: string,
amount: TransactionFeeAmount,
assets?: AssetItems,
assets?: ApiTokens,
};

export type TransactionFee = {
Expand Down Expand Up @@ -238,7 +238,7 @@ export type CoinSelectionsPaymentRequestType = {
walletId: string,
address: string,
amount: number,
assets?: AssetItems,
assets?: ApiTokens,
};

export type CoinSelectionsRequest =
Expand Down
8 changes: 6 additions & 2 deletions source/renderer/app/api/utils/localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,18 @@ export default class LocalStorageApi {
policyId: string,
assetName: string
): Promise<AssetLocalData> =>
LocalStorageApi.get(keys.ASSET_DATA, {}, policyId + assetName);
LocalStorageApi.get(keys.ASSET_DATA, {}, `${policyId}${assetName}`);

setAssetLocalData = (
policyId: string,
assetName: string,
assetLocalData: AssetLocalData
): Promise<void> =>
LocalStorageApi.set(keys.ASSET_DATA, assetLocalData, policyId + assetName);
LocalStorageApi.set(
keys.ASSET_DATA,
assetLocalData,
`${policyId}${assetName}`
);

getAssetSettingsDialogWasOpened = (): Promise<boolean> =>
LocalStorageApi.get(keys.ASSET_SETTINGS_DIALOG_WAS_OPENED, false);
Expand Down
6 changes: 3 additions & 3 deletions source/renderer/app/api/wallets/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import BigNumber from 'bignumber.js';
import { WalletUnits } from '../../domains/Wallet';
import type { ExportedByronWallet } from '../../types/walletExportTypes';
import type { Currency, LocalizedCurrency } from '../../types/currencyTypes';
import type { AssetItems } from '../assets/types';
import type { ApiTokens } from '../assets/types';

export type Block = {
slot_number: number,
Expand Down Expand Up @@ -41,8 +41,8 @@ export type AdaWallet = {
reward: WalletBalance,
},
assets: {
available: AssetItems,
total: AssetItems,
available: ApiTokens,
total: ApiTokens,
},
delegation: {
active: WalletDelegation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { PopOver } from 'react-polymorph/lib/components/PopOver';
import { defineMessages, intlShape } from 'react-intl';
import CopyToClipboard from 'react-copy-to-clipboard';
import { observer } from 'mobx-react';
import styles from './AssetToken.scss';
import styles from './Asset.scss';
import { ellipsis, hexToString } from '../../utils/strings';
import type { WalletSummaryAsset } from '../../api/assets/types';

import copyIcon from '../../assets/images/copy-asset.inline.svg';
import settingsIcon from '../../assets/images/asset-token-settings-ic.inline.svg';
import warningIcon from '../../assets/images/asset-token-warning-ic.inline.svg';
Expand All @@ -17,6 +17,7 @@ import {
ASSET_TOKEN_ID_COPY_FEEDBACK,
ASSET_TOKEN_DISPLAY_DELAY,
} from '../../config/timingConfig';
import type { Asset as AssetProps } from '../../api/assets/types';

const messages = defineMessages({
fingerprintItem: {
Expand Down Expand Up @@ -75,7 +76,7 @@ const messages = defineMessages({
});

type Props = {
asset: WalletSummaryAsset,
asset: AssetProps,
small?: boolean,
hidePopOver?: boolean,
onCopyAssetItem?: Function,
Expand All @@ -95,7 +96,7 @@ type State = {
};

@observer
export default class AssetToken extends Component<Props, State> {
export default class Asset extends Component<Props, State> {
static contextTypes = {
intl: intlShape.isRequired,
};
Expand Down
2 changes: 1 addition & 1 deletion source/renderer/app/components/assets/AssetAmount.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Props = {
};

@observer
export default class AssetToken extends Component<Props> {
export default class AssetAmount extends Component<Props> {
static contextTypes = {
intl: intlShape.isRequired,
};
Expand Down