-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(extension): LW-9669 show collateral on dapp dialogue (#864)
* feat(extension): add utility function to calculate the tx collateral * feat(core): add collateral component * feat(core,cardano): show collateral on dapp dialogue * refactor(extension): extract tx collateral computation to a hook * refactor(extension): use the SDK get collateral implementation * feat(ui): add tooltip property to amount tx summary * refactor(core): use ui toolkit amount component * refactor(core): remove eslint comment * refactor(extension): remove max-statements comment * refactor(extension): add return type annotation * refactor(extension): cache tx to avoid creating new object references * refactor(core): remove magic numbers comment * refactor(core): extract amount transformer * fix(core): add test id for tx fee * refactor(extension): use wallet state * fix(ui): use relative imports * refactor(core,ui): add back tx fee test id * refactor(core): add test id to transaction details
- Loading branch information
1 parent
d3fd071
commit 2d7b410
Showing
17 changed files
with
177 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
apps/browser-extension-wallet/src/hooks/useComputeTxCollateral.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Wallet } from '@lace/cardano'; | ||
import { createHistoricalOwnInputResolver } from '@src/utils/own-input-resolver'; | ||
import { useState, useEffect } from 'react'; | ||
import { getCollateral } from '@cardano-sdk/core'; | ||
import { ObservableWalletState } from './useWalletState'; | ||
|
||
export const useComputeTxCollateral = (wallet: ObservableWalletState, tx?: Wallet.Cardano.Tx): bigint | undefined => { | ||
const [txCollateral, setTxCollateral] = useState<bigint>(); | ||
|
||
useEffect(() => { | ||
if (!tx) return; | ||
|
||
const computeCollateral = async () => { | ||
const inputResolver = createHistoricalOwnInputResolver({ | ||
addresses: wallet.addresses, | ||
transactions: wallet.transactions | ||
}); | ||
|
||
const collateral = await getCollateral( | ||
tx, | ||
inputResolver, | ||
wallet.addresses.map((addr) => addr.address) | ||
); | ||
|
||
setTxCollateral(collateral); | ||
}; | ||
|
||
computeCollateral(); | ||
}, [tx, wallet]); | ||
|
||
return txCollateral; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/core/src/ui/components/ActivityDetail/Collateral.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
import { useTranslate } from '@src/ui/hooks'; | ||
import { TransactionSummary } from '@lace/ui'; | ||
|
||
export interface Props { | ||
collateral: string; | ||
amountTransformer: (amount: string) => string; | ||
coinSymbol: string; | ||
} | ||
export const Collateral = ({ collateral, amountTransformer, coinSymbol }: Props): React.ReactElement => { | ||
const { t } = useTranslate(); | ||
|
||
return ( | ||
<TransactionSummary.Amount | ||
amount={`${collateral} ${coinSymbol}`} | ||
fiatPrice={amountTransformer(collateral)} | ||
label={t('package.core.activityDetails.collateral')} | ||
tooltip={t('package.core.activityDetails.collateralInfo')} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 0 additions & 109 deletions
109
packages/core/src/ui/components/ActivityDetail/TransactionFee.module.scss
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.