Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc98c680

Browse files
committed
feat: add btc tags
1 parentead303c commitc98c680

File tree

3 files changed

+163
-9
lines changed

3 files changed

+163
-9
lines changed

‎app/_locales/en/messages.json‎

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎ui/components/multichain-accounts/multichain-address-rows-hovered-list/multichain-aggregated-list-row.test.tsx‎

Lines changed: 129 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ import { MultichainAggregatedAddressListRow } from './multichain-aggregated-list
77

88
jest.mock('../../../hooks/useI18nContext',()=>({
99
useI18nContext:()=>(key:string)=>{
10-
if(key==='networkNameEthereum'){
11-
return'Ethereum';
12-
}
13-
returnkey;
10+
consttranslations:Record<string,string>={
11+
networkNameEthereum:'Ethereum',
12+
networkNameBitcoinLegacy:'Legacy',
13+
networkNameBitcoinNestedSegwit:'Nested SegWit',
14+
networkNameBitcoinSegwit:'Native SegWit',
15+
networkNameBitcoinTaproot:'Taproot',
16+
};
17+
returntranslations[key]||key;
1418
},
1519
}));
1620

@@ -25,6 +29,15 @@ const TEST_STRINGS = {
2529
EMPTY_STRING:'',
2630
ETHEREUM_GROUP_NAME:'Ethereum',
2731
SOLANA_NETWORK_NAME:'Solana Mainnet',
32+
BTC_LEGACY_ADDRESS:'1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa',
33+
BTC_NESTED_SEGWIT_ADDRESS:'3FZbgi29cpjq2GjdwV8eyHuJJnkLtktZc5',
34+
BTC_NATIVE_SEGWIT_ADDRESS:'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
35+
BTC_TAPROOT_ADDRESS:
36+
'bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr',
37+
BTC_LEGACY_TAG:'Legacy',
38+
BTC_NESTED_SEGWIT_TAG:'Nested SegWit',
39+
BTC_NATIVE_SEGWIT_TAG:'Native SegWit',
40+
BTC_TAPROOT_TAG:'Taproot',
2841
}asconst;
2942

3043
constTEST_CHAIN_IDS={
@@ -40,6 +53,7 @@ const TEST_CHAIN_IDS = {
4053
POLYGON_CAIP:'eip155:137',
4154
ARBITRUM_CAIP:'eip155:42161',
4255
SOLANA_CAIP:'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
56+
BITCOIN_CAIP:'bip122:000000000019d6689c085ae165831e93',
4357
}asconst;
4458

4559
constTEST_IDS={
@@ -444,4 +458,115 @@ describe('MultichainAggregatedAddressListRow', () => {
444458
).toBeInTheDocument();
445459
});
446460
});
461+
462+
describe('Bitcoin Address Tag',()=>{
463+
it('displays Legacy tag for P2PKH Bitcoin addresses',()=>{
464+
constprops=createTestProps({
465+
address:TEST_STRINGS.BTC_LEGACY_ADDRESS,
466+
chainIds:[TEST_CHAIN_IDS.BITCOIN_CAIP],
467+
});
468+
469+
render(
470+
<Providerstore={store}>
471+
<MultichainAggregatedAddressListRow{...props}/>
472+
</Provider>,
473+
);
474+
475+
expect(screen.getByText(TEST_STRINGS.BTC_LEGACY_TAG)).toBeInTheDocument();
476+
});
477+
478+
it('displays Nested SegWit tag for P2SH Bitcoin addresses',()=>{
479+
constprops=createTestProps({
480+
address:TEST_STRINGS.BTC_NESTED_SEGWIT_ADDRESS,
481+
chainIds:[TEST_CHAIN_IDS.BITCOIN_CAIP],
482+
});
483+
484+
render(
485+
<Providerstore={store}>
486+
<MultichainAggregatedAddressListRow{...props}/>
487+
</Provider>,
488+
);
489+
490+
expect(
491+
screen.getByText(TEST_STRINGS.BTC_NESTED_SEGWIT_TAG),
492+
).toBeInTheDocument();
493+
});
494+
495+
it('displays Native SegWit tag for P2WPKH Bitcoin addresses',()=>{
496+
constprops=createTestProps({
497+
address:TEST_STRINGS.BTC_NATIVE_SEGWIT_ADDRESS,
498+
chainIds:[TEST_CHAIN_IDS.BITCOIN_CAIP],
499+
});
500+
501+
render(
502+
<Providerstore={store}>
503+
<MultichainAggregatedAddressListRow{...props}/>
504+
</Provider>,
505+
);
506+
507+
expect(
508+
screen.getByText(TEST_STRINGS.BTC_NATIVE_SEGWIT_TAG),
509+
).toBeInTheDocument();
510+
});
511+
512+
it('displays Taproot tag for P2TR Bitcoin addresses',()=>{
513+
constprops=createTestProps({
514+
address:TEST_STRINGS.BTC_TAPROOT_ADDRESS,
515+
chainIds:[TEST_CHAIN_IDS.BITCOIN_CAIP],
516+
});
517+
518+
render(
519+
<Providerstore={store}>
520+
<MultichainAggregatedAddressListRow{...props}/>
521+
</Provider>,
522+
);
523+
524+
expect(
525+
screen.getByText(TEST_STRINGS.BTC_TAPROOT_TAG),
526+
).toBeInTheDocument();
527+
});
528+
529+
it('does not display tag for non-Bitcoin addresses',()=>{
530+
constprops=createTestProps({
531+
address:TEST_STRINGS.FULL_ADDRESS,
532+
chainIds:[TEST_CHAIN_IDS.ETHEREUM_CAIP],
533+
});
534+
535+
render(
536+
<Providerstore={store}>
537+
<MultichainAggregatedAddressListRow{...props}/>
538+
</Provider>,
539+
);
540+
541+
expect(
542+
screen.queryByText(TEST_STRINGS.BTC_LEGACY_TAG),
543+
).not.toBeInTheDocument();
544+
expect(
545+
screen.queryByText(TEST_STRINGS.BTC_NESTED_SEGWIT_TAG),
546+
).not.toBeInTheDocument();
547+
expect(
548+
screen.queryByText(TEST_STRINGS.BTC_NATIVE_SEGWIT_TAG),
549+
).not.toBeInTheDocument();
550+
expect(
551+
screen.queryByText(TEST_STRINGS.BTC_TAPROOT_TAG),
552+
).not.toBeInTheDocument();
553+
});
554+
555+
it('displays Bitcoin tag alongside Ethereum group name when address is Bitcoin',()=>{
556+
constprops=createTestProps({
557+
address:TEST_STRINGS.BTC_LEGACY_ADDRESS,
558+
chainIds:[TEST_CHAIN_IDS.BITCOIN_CAIP],
559+
});
560+
561+
render(
562+
<Providerstore={store}>
563+
<MultichainAggregatedAddressListRow{...props}/>
564+
</Provider>,
565+
);
566+
567+
constrow=screen.getByTestId(TEST_IDS.MULTICHAIN_ADDRESS_ROW);
568+
expect(row).toBeInTheDocument();
569+
expect(screen.getByText(TEST_STRINGS.BTC_LEGACY_TAG)).toBeInTheDocument();
570+
});
571+
});
447572
});

‎ui/components/multichain-accounts/multichain-address-rows-hovered-list/multichain-aggregated-list-row.tsx‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import { getNetworksByScopes } from '../../../../shared/modules/selectors/networ
2424
import{MultichainAccountNetworkGroup}from'../multichain-account-network-group';
2525
// eslint-disable-next-line import/no-restricted-paths
2626
import{normalizeSafeAddress}from'../../../../app/scripts/lib/multichain/address';
27+
import{isBtcMainnetAddress}from'../../../../shared/lib/multichain/accounts';
28+
import{AddressType,getAddressInfo}from'bitcoin-address-validation';
29+
import{Tag}from'../../component-library';
2730

2831
typeMultichainAggregatedAddressListRowProps={
2932
/**
@@ -78,15 +81,31 @@ export const MultichainAggregatedAddressListRow = ({
7881
constnetworks=useSelector((state)=>getNetworksByScopes(state,chainIds));
7982

8083
constgroupName=useMemo(()=>{
81-
if(networks[0]?.name==='Bitcoin'){
82-
returnt('networkNameBitcoinSegwit');
83-
}
84-
8584
returnchainIds.some((chain)=>chain.startsWith('eip155:'))
8685
?t('networkNameEthereum')
8786
:networks[0]?.name;
8887
},[chainIds,t,networks]);
8988

89+
constbtcAddressTag=useMemo(()=>{
90+
if(!isBtcMainnetAddress(address)){
91+
returnundefined;
92+
}
93+
94+
const{ type}=getAddressInfo(address);
95+
switch(type){
96+
caseAddressType.p2pkh:
97+
returnt('networkNameBitcoinLegacy');
98+
caseAddressType.p2sh:
99+
returnt('networkNameBitcoinNestedSegwit');
100+
caseAddressType.p2wpkh:
101+
returnt('networkNameBitcoinSegwit');
102+
caseAddressType.p2tr:
103+
returnt('networkNameBitcoinTaproot');
104+
default:
105+
returnundefined;
106+
}
107+
},[address,t]);
108+
90109
// Helper function to get text color based on state
91110
constgetTextColor=()=>{
92111
if(addressCopied){
@@ -167,6 +186,7 @@ export const MultichainAggregatedAddressListRow = ({
167186
<Textvariant={TextVariant.BodySm}fontWeight={FontWeight.Bold}>
168187
{groupName}
169188
</Text>
189+
{btcAddressTag&&<Taglabel={btcAddressTag}/>}
170190
</Box>
171191
<Box
172192
gap={1}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp