diff --git a/packages/yoroi-extension/app/connector/components/signin/CardanoSignTxPage.js b/packages/yoroi-extension/app/connector/components/signin/CardanoSignTxPage.js index 0aece1e870..844bbcadb7 100644 --- a/packages/yoroi-extension/app/connector/components/signin/CardanoSignTxPage.js +++ b/packages/yoroi-extension/app/connector/components/signin/CardanoSignTxPage.js @@ -17,7 +17,6 @@ import type { import type { CardanoConnectorSignRequest, SignSubmissionErrorType, - TxDataOutput, } from '../../types'; import type LocalizableError from '../../../i18n/LocalizableError'; import { Component } from 'react'; @@ -215,7 +214,7 @@ class SignTxPage extends Component { selectedExplorer={this.props.selectedExplorer} hash={fingerprint} light - linkType="address" + linkType="token" > {truncateAddressShort(getTokenName(tokenInfo), 10)} @@ -282,33 +281,6 @@ class SignTxPage extends Component { return null; }; - getUniqueAssets: ( - Array - ) => Array<{| - tokenInfo: ?$ReadOnly, - amount: BigNumber, - |}> = assets => { - return assets.reduce((acc, curr) => { - const newAcc: Array<{| - tokenInfo: ?$ReadOnly, - amount: BigNumber, - |}> = [].concat(acc); - - const defaultEntry = curr.value.getDefaultEntry(); - - [defaultEntry].concat(curr.value.nonDefaultEntries()).forEach(e => { - if (!newAcc.some(a => a.tokenInfo?.Identifier === e.identifier) && e.identifier) { - const tokenInfo = this.props.getTokenInfo(e); - if (tokenInfo != null) { - newAcc.push({ tokenInfo, amount: e.amount }); - }; - } - }); - - return newAcc; - }, []); - }; - getSummaryAssetsData: void => SummaryAssetsData = () => { const { txData } = this.props; @@ -323,10 +295,31 @@ class SignTxPage extends Component { const defaultTokenId = txData.amount.defaults.defaultIdentifier; const defaultTokenAmount = txData.amount.get(defaultTokenId) ?? new BigNumber('0'); const txFeeAmount = new BigNumber(txData.fee.amount); - const sentAssets = this.getUniqueAssets(txData.outputs.filter(o => !o.isForeign)); - const receivedAssets = this.getUniqueAssets( - txData.inputs.map(i => ({ ...i, isForeign: false })) - ); + + const assets = txData.amount.nonDefaultEntries(); + for (const asset of assets) { + const assetInfo = { + amount: asset.amount, + // todo: properly query the backend (but don't block the UI) instead of using a default + tokenInfo: this.props.getTokenInfo(asset) ?? { + Identifier: asset.identifier, + IsDefault: false, + Metadata: { + type: 'Cardano', + policyId: asset.identifier.split('.')[0], + assetName: asset.identifier.split('.')[1], + numberOfDecimals: 0, + ticker: null, + longName: null, + }, + }, + }; + if (asset.amount.isPositive()) { + assetsData.received.push(assetInfo); + } else { + assetsData.sent.push(assetInfo); + } + } // only tx fee (no sign) & one asset sent/received assetsData.total = this.getDisplayAmount({ @@ -337,12 +330,6 @@ class SignTxPage extends Component { }); assetsData.isOnlyTxFee = defaultTokenAmount.toNumber() === 0; - - // More than 1 asset sent/received (rather is NFT or not) - if (sentAssets.length > 1 || receivedAssets.length > 1) { - assetsData.sent = sentAssets.filter(Boolean); - assetsData.received = receivedAssets.filter(Boolean); - } } return assetsData; }; diff --git a/packages/yoroi-extension/app/connector/components/signin/cardano/SignTx.js b/packages/yoroi-extension/app/connector/components/signin/cardano/SignTx.js index 6704258f5b..6f964a6e9b 100644 --- a/packages/yoroi-extension/app/connector/components/signin/cardano/SignTx.js +++ b/packages/yoroi-extension/app/connector/components/signin/cardano/SignTx.js @@ -145,7 +145,8 @@ const ExpandableAssetsPanel = ({ )} - {(hasNativeToken || assets.length !== 0) && ( + {((total.amount.startsWith('-') && action === 'sent') || ( + !total.amount.startsWith('-') && action === 'received')) && ( {total.amount} {total.ticker} diff --git a/packages/yoroi-extension/app/connector/stores/ConnectorStore.js b/packages/yoroi-extension/app/connector/stores/ConnectorStore.js index 0d4f5f23b8..84a49140c9 100644 --- a/packages/yoroi-extension/app/connector/stores/ConnectorStore.js +++ b/packages/yoroi-extension/app/connector/stores/ConnectorStore.js @@ -652,6 +652,7 @@ export default class ConnectorStore extends Store { ownAddresses ); + let foreignInputDetails = []; if (foreignInputs.length) { const foreignUtxos = await this.stores.substores.ada.stateFetchStore.fetcher.getUtxoData({ network: connectedWallet.publicDeriver.getParent().networkInfo, @@ -682,7 +683,7 @@ export default class ConnectorStore extends Store { return; } const value = multiTokenFromRemote(foreignUtxo.output, defaultToken.NetworkId); - inputs.push({ + foreignInputDetails.push({ address: Buffer.from( RustModule.WalletV4.Address.from_bech32(foreignUtxo.output.address).to_bytes() ).toString('hex'), @@ -886,8 +887,7 @@ export default class ConnectorStore extends Store { runInAction(() => { this.adaTransaction = { inputs, - // $FlowFixMe[prop-missing] - foreignInputs, + foreignInputs: foreignInputDetails, outputs, fee, total, diff --git a/packages/yoroi-extension/chrome/extension/connector/index.js b/packages/yoroi-extension/chrome/extension/connector/index.js index c5f960b4d6..3f9b45b0e3 100644 --- a/packages/yoroi-extension/chrome/extension/connector/index.js +++ b/packages/yoroi-extension/chrome/extension/connector/index.js @@ -33,17 +33,16 @@ const initializeDappConnector: void => Promise = async () => { const history = syncHistoryWithStore(hashHistory, router); const stores = createStores(api, actions); - // ??? USAGE? - // window.ergo = { - // api, - // actions, - // translations, - // stores, - // reset: action(() => { - // Action.resetAllActions(); - // createStores(api, actions); - // }), - // }; + window.yoroi = { + api, + actions, + translations, + stores, + reset: action(() => { + Action.resetAllActions(); + createStores(api, actions); + }), + }; const root = document.querySelector('#root-yoroi-connector'); if (root == null) {