-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display consistent decimals when approving transactions (#1681)
- Closes #1675 - Closes #1659 --- | π· Asset | π· NFT | π· TX | | --- | --- | --- | | <img width="373" alt="asset" src="https://github.com/user-attachments/assets/51792048-919e-420c-bb19-0dc62df8e1e4"> | <img width="368" src="https://github.com/user-attachments/assets/6b4c4b3d-57c6-448b-a5fd-4a311aa83986"> | <img width="370" src="https://github.com/user-attachments/assets/3a1aabde-9fe7-416a-aca9-b1983813b0f6"> |
- Loading branch information
1 parent
a7e6e48
commit 6121fab
Showing
5 changed files
with
68 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"fuels-wallet": minor | ||
--- | ||
|
||
Show asset name, decimals and NFT badge when approving a transaction. |
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
9 changes: 1 addition & 8 deletions
9
packages/app/src/systems/DApp/machines/transactionRequestMachine.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
64 changes: 43 additions & 21 deletions
64
packages/app/src/systems/Transaction/hooks/useAssetsAmount.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 |
---|---|---|
@@ -1,36 +1,58 @@ | ||
import type { AssetFuelAmount } from '@fuel-wallet/types'; | ||
import type { OperationCoin } from 'fuels'; | ||
import { useEffect, useState } from 'react'; | ||
import { getFuelAssetByAssetId, useAssets } from '~/systems/Asset'; | ||
import { AssetsCache } from '~/systems/Asset/cache/AssetsCache'; | ||
import { useProvider } from '~/systems/Network/hooks/useProvider'; | ||
|
||
export const useAssetsAmount = (params: { | ||
type UseAmountAmountParams = { | ||
operationsCoin?: OperationCoin[]; | ||
}) => { | ||
const { assets } = useAssets(); | ||
}; | ||
|
||
const isAssetFuelAmount = ( | ||
value: AssetFuelAmount | null | ||
): value is AssetFuelAmount => value !== null; | ||
|
||
export const useAssetsAmount = (params: UseAmountAmountParams) => { | ||
const provider = useProvider(); | ||
const [assetsAmount, setAssetsAmount] = useState<AssetFuelAmount[]>([]); | ||
|
||
useEffect(() => { | ||
const fetchAssetsAmount = async () => { | ||
const assetsAmountAsync = await params.operationsCoin?.reduce( | ||
async (acc, operationCoin) => { | ||
const prev = await acc; | ||
const assetAmount = await getFuelAssetByAssetId({ | ||
assets, | ||
assetId: operationCoin.assetId, | ||
}); | ||
|
||
if (!assetAmount) return prev; | ||
|
||
return [...prev, { ...assetAmount, amount: operationCoin.amount }]; | ||
}, | ||
Promise.resolve([] as AssetFuelAmount[]) | ||
); | ||
|
||
setAssetsAmount(assetsAmountAsync || []); | ||
try { | ||
if (!params.operationsCoin || !provider) { | ||
setAssetsAmount([]); | ||
return; | ||
} | ||
|
||
const assetsCache = AssetsCache.getInstance(); | ||
|
||
const assetsWithAmount: (AssetFuelAmount | null)[] = await Promise.all( | ||
params.operationsCoin.map(async (operationCoin) => { | ||
const assetCached = await assetsCache.getAsset({ | ||
chainId: provider.getChainId(), | ||
assetId: operationCoin.assetId, | ||
dbAssets: [], | ||
save: false, | ||
}); | ||
|
||
if (!assetCached) return null; | ||
|
||
return { | ||
...assetCached, | ||
amount: operationCoin.amount, | ||
}; | ||
}) | ||
); | ||
|
||
setAssetsAmount(assetsWithAmount.filter(isAssetFuelAmount)); | ||
} catch (error) { | ||
console.error('Error fetching assets:', error); | ||
setAssetsAmount([]); | ||
} | ||
}; | ||
|
||
fetchAssetsAmount(); | ||
}, [params.operationsCoin, assets]); | ||
}, [provider, params.operationsCoin]); | ||
|
||
return assetsAmount; | ||
}; |