-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/multichain-block-explorer-format-urls
- Loading branch information
Showing
35 changed files
with
1,068 additions
and
178 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,7 +220,7 @@ | |
"@trezor/schema-utils@npm:1.0.2": "patch:@trezor/schema-utils@npm%3A1.0.2#~/.yarn/patches/@trezor-schema-utils-npm-1.0.2-7dd48689b2.patch", | ||
"lavamoat-core@npm:^15.1.1": "patch:lavamoat-core@npm%3A15.1.1#~/.yarn/patches/lavamoat-core-npm-15.1.1-51fbe39988.patch", | ||
"lavamoat-core@npm:^16.2.2": "patch:lavamoat-core@npm%3A16.2.2#~/.yarn/patches/lavamoat-core-npm-16.2.2-e361ff1f8a.patch", | ||
"@metamask/snaps-sdk": "^6.16.0", | ||
"@metamask/snaps-sdk": "^6.17.0", | ||
"@swc/[email protected]": "^0.1.6", | ||
"@babel/core": "patch:@babel/core@npm%3A7.25.9#~/.yarn/patches/@babel-core-npm-7.25.9-4ae3bff7f3.patch", | ||
"@babel/runtime": "patch:@babel/runtime@npm%3A7.25.9#~/.yarn/patches/@babel-runtime-npm-7.25.9-fe8c62510a.patch", | ||
|
@@ -348,11 +348,11 @@ | |
"@metamask/selected-network-controller": "^19.0.0", | ||
"@metamask/signature-controller": "^23.1.0", | ||
"@metamask/smart-transactions-controller": "^16.0.1", | ||
"@metamask/snaps-controllers": "^9.18.0", | ||
"@metamask/snaps-execution-environments": "^6.13.0", | ||
"@metamask/snaps-rpc-methods": "^11.10.0", | ||
"@metamask/snaps-sdk": "^6.16.0", | ||
"@metamask/snaps-utils": "^8.9.1", | ||
"@metamask/snaps-controllers": "^9.19.0", | ||
"@metamask/snaps-execution-environments": "^6.14.0", | ||
"@metamask/snaps-rpc-methods": "^11.11.0", | ||
"@metamask/snaps-sdk": "^6.17.0", | ||
"@metamask/snaps-utils": "^8.10.0", | ||
"@metamask/solana-wallet-snap": "^1.2.0", | ||
"@metamask/transaction-controller": "^43.0.0", | ||
"@metamask/user-operation-controller": "^22.0.0", | ||
|
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
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
110 changes: 110 additions & 0 deletions
110
ui/components/app/multichain-transaction-details-modal/helpers.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,110 @@ | ||
import { DateTime } from 'luxon'; | ||
import { | ||
MULTICHAIN_NETWORK_BLOCK_EXPLORER_URL_MAP, | ||
Check failure on line 3 in ui/components/app/multichain-transaction-details-modal/helpers.ts
|
||
MultichainNetworks, | ||
} from '../../../../shared/constants/multichain/networks'; | ||
import { | ||
formatDateWithYearContext, | ||
shortenAddress, | ||
} from '../../../helpers/utils/util'; | ||
|
||
/** | ||
* Creates a transaction URL for block explorer based on network type | ||
* Different networks have different URL patterns: | ||
* Bitcoin Mainnet: https://blockstream.info/tx/{txId} | ||
* Bitcoin Testnet: https://blockstream.info/testnet/tx/{txId} | ||
* Solana Mainnet: https://explorer.solana.com/tx/{txId} | ||
* Solana Devnet: https://explorer.solana.com/tx/{txId}?cluster=devnet | ||
* | ||
* @param txId - Transaction ID | ||
* @param chainId - Network chain ID | ||
* @returns Full URL to transaction in block explorer, or empty string if no explorer URL | ||
*/ | ||
export const getTransactionUrl = (txId: string, chainId: string): string => { | ||
const explorerBaseUrl = | ||
MULTICHAIN_NETWORK_BLOCK_EXPLORER_URL_MAP[chainId as MultichainNetworks]; | ||
if (!explorerBaseUrl) { | ||
return ''; | ||
} | ||
|
||
// Change address URL to transaction URL for Bitcoin | ||
if (chainId.startsWith('bip122:')) { | ||
return `${explorerBaseUrl.replace('/address', '/tx')}/${txId}`; | ||
} | ||
|
||
const baseUrl = explorerBaseUrl.split('?')[0]; | ||
if (chainId === MultichainNetworks.SOLANA) { | ||
return `${baseUrl}tx/${txId}`; | ||
} | ||
if (chainId === MultichainNetworks.SOLANA_DEVNET) { | ||
return `${baseUrl}tx/${txId}?cluster=devnet`; | ||
} | ||
|
||
return ''; | ||
}; | ||
|
||
/** | ||
* Creates an address URL for block explorer based on network type | ||
* Different networks have different URL patterns: | ||
* Bitcoin Mainnet: https://blockstream.info/address/{address} | ||
* Bitcoin Testnet: https://blockstream.info/testnet/address/{address} | ||
* Solana Mainnet: https://explorer.solana.com/address/{address} | ||
* Solana Devnet: https://explorer.solana.com/address/{address}?cluster=devnet | ||
* | ||
* @param address - Wallet address | ||
* @param chainId - Network chain ID | ||
* @returns Full URL to address in block explorer, or empty string if no explorer URL | ||
*/ | ||
export const getAddressUrl = (address: string, chainId: string): string => { | ||
const explorerBaseUrl = | ||
MULTICHAIN_NETWORK_BLOCK_EXPLORER_URL_MAP[chainId as MultichainNetworks]; | ||
|
||
if (!explorerBaseUrl) { | ||
return ''; | ||
} | ||
|
||
const baseUrl = explorerBaseUrl.split('?')[0]; | ||
if (chainId === MultichainNetworks.SOLANA) { | ||
return `${baseUrl}address/${address}`; | ||
} | ||
if (chainId === MultichainNetworks.SOLANA_DEVNET) { | ||
return `${baseUrl}address/${address}?cluster=devnet`; | ||
} | ||
|
||
// Bitcoin networks already have the correct address URL format | ||
return `${explorerBaseUrl}/${address}`; | ||
}; | ||
|
||
/** | ||
* Formats a timestamp into a localized date and time string | ||
* Example outputs: "Mar 15, 2024, 14:30" or "Dec 25, 2023, 09:45" | ||
* | ||
* @param timestamp - Unix timestamp in milliseconds | ||
* @returns Formatted date and time string, or empty string if timestamp is null | ||
*/ | ||
export const formatTimestamp = (timestamp: number | null) => { | ||
if (!timestamp) { | ||
return ''; | ||
} | ||
|
||
// It's typical for Solana timestamps to use seconds, while JS Dates and most EVM chains use milliseconds. | ||
// Hence we needed to use the conversion `timestamp < 1e12 ? timestamp * 1000 : timestamp` for it to work. | ||
const timestampMs = timestamp < 1e12 ? timestamp * 1000 : timestamp; | ||
|
||
const dateTime = DateTime.fromMillis(timestampMs); | ||
const date = formatDateWithYearContext(timestampMs, 'MMM d, y', 'MMM d'); | ||
const time = dateTime.toFormat('HH:mm'); | ||
|
||
return `${date}, ${time}`; | ||
}; | ||
|
||
/** | ||
* Formats a shorten version of a transaction ID. | ||
* | ||
* @param txId - Transaction ID. | ||
* @returns Formatted transaction ID. | ||
*/ | ||
export function shortenTransactionId(txId: string) { | ||
// For transactions we use a similar output for now, but shortenTransactionId will be added later. | ||
return shortenAddress(txId); | ||
} |
1 change: 1 addition & 0 deletions
1
ui/components/app/multichain-transaction-details-modal/index.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 @@ | ||
export { MultichainTransactionDetailsModal } from './multichain-transaction-details-modal'; |
51 changes: 51 additions & 0 deletions
51
...app/multichain-transaction-details-modal/multichain-transaction-details-modal.stories.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,51 @@ | ||
import { MultichainTransactionDetailsModal } from './multichain-transaction-details-modal'; | ||
|
||
export default { | ||
title: 'Components/App/MultichainTransactionDetailsModal', | ||
component: MultichainTransactionDetailsModal, | ||
}; | ||
|
||
const mockTransaction = { | ||
type: 'Send BTC', | ||
status: 'Confirmed', | ||
timestamp: new Date('Sep 30 2023 12:56').getTime(), | ||
id: 'b93ea2cb4eed0f9e13284ed8860bcfc45de2488bb6a8b0b2a843c4b2fbce40f3', | ||
from: [{ | ||
address: "bc1p7atgm33ak04ntsq9366mvym42ecrk4y34ssysc99340a39eq9arq0pu9uj", | ||
asset: { | ||
amount: '1.2', | ||
unit: 'BTC', | ||
} | ||
}], | ||
to: [{ | ||
address: "bc1p3t7744qewy262ym5afgeuqlwswtpfe22y7c4lwv0a7972p2k73msee7rr3", | ||
asset: { | ||
amount: '1.2', | ||
unit: 'BTC', | ||
} | ||
}], | ||
fees: [{ | ||
type: 'base', | ||
asset: { | ||
amount: '1.0001', | ||
unit: 'BTC', | ||
} | ||
}] | ||
}; | ||
|
||
export const Default = { | ||
args: { | ||
transaction: mockTransaction, | ||
onClose: () => console.log('Modal closed'), | ||
addressLink: 'https://explorer.bitcoin.com/btc/tx/3302...90c1', | ||
multichainNetwork: { | ||
nickname: 'Bitcoin', | ||
isEvmNetwork: false, | ||
chainId: 'bip122:000000000019d6689c085ae165831e93', | ||
network: { | ||
chainId: 'bip122:000000000019d6689c085ae165831e93', | ||
ticker: 'BTC', | ||
}, | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.