Skip to content

Commit b8b1fe1

Browse files
author
Rahul Patni
committed
Detect mainnet bridge transactions
Mainnet and testnet have different incoming and outgoing addresses for chainport bridge transactions.
1 parent f3702bc commit b8b1fe1

File tree

4 files changed

+60
-20
lines changed

4 files changed

+60
-20
lines changed

renderer/components/NotesList/NotesList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const messages = defineMessages({
2828
});
2929

3030
type Props = {
31+
networkId: number;
3132
notes: TransactionNote[];
3233
heading: string;
3334
asTransactions?: boolean;
@@ -38,6 +39,7 @@ type Props = {
3839
};
3940

4041
export function NotesList({
42+
networkId,
4143
notes,
4244
heading,
4345
asTransactions = false,
@@ -95,7 +97,7 @@ export function NotesList({
9597
status={note.status}
9698
memo={note.memo}
9799
asTransaction={asTransactions}
98-
isBridge={asTransactions && isChainportNote(note)}
100+
isBridge={asTransactions && isChainportNote(networkId, note)}
99101
/>
100102
);
101103
}}

renderer/pages/accounts/[account-name]/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ function AccountOverviewContent({ accountName }: { accountName: string }) {
7979
name: accountName,
8080
});
8181

82+
const { data: networkInfo } = trpcReact.getNetworkInfo.useQuery();
83+
8284
const {
8385
data: transactionsData,
8486
isLoading,
@@ -112,7 +114,7 @@ function AccountOverviewContent({ accountName }: { accountName: string }) {
112114
return chip;
113115
}, [accountData?.isLedger, accountData?.status.viewOnly]);
114116

115-
if (!accountData) {
117+
if (!accountData || !networkInfo) {
116118
// @todo: Error handling
117119
return null;
118120
}
@@ -147,6 +149,7 @@ function AccountOverviewContent({ accountName }: { accountName: string }) {
147149
<TabPanel p={0}>
148150
<AccountAssets accountName={accountName} />
149151
<NotesList
152+
networkId={networkInfo.networkId}
150153
asTransactions
151154
isLoading={isLoading}
152155
isError={isError}

renderer/pages/accounts/[account-name]/transaction/[transaction-hash].tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@ function SingleTransactionContent({
3939
name: accountName,
4040
});
4141

42+
const { data: networkInfo } = trpcReact.getNetworkInfo.useQuery();
43+
4244
const { data: transactionData } = trpcReact.getTransaction.useQuery({
4345
accountName,
4446
transactionHash,
4547
});
4648

4749
const isChainportTransaction =
48-
!!transactionData && isChainportTx(transactionData);
50+
!!transactionData &&
51+
!!networkInfo &&
52+
isChainportTx(networkInfo.networkId, transactionData);
4953

50-
if (!accountData) {
54+
if (!accountData || !networkInfo) {
5155
return null;
5256
}
5357

@@ -122,12 +126,14 @@ function SingleTransactionContent({
122126
/>
123127
)}
124128
<NotesList
129+
networkId={networkInfo.networkId}
125130
heading={formatMessage(messages.transactionNotes)}
126131
notes={showSelfSendNotes ? regularNotes : transactionData.notes}
127132
/>
128133
{showSelfSendNotes && (
129134
<Box mt={10}>
130135
<NotesList
136+
networkId={networkInfo.networkId}
131137
heading={formatMessage(messages.change)}
132138
notes={selfSendNotes}
133139
/>

renderer/utils/chainport/isChainportTx.ts

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,62 @@
11
import { TRPCRouterOutputs } from "@/providers/TRPCProvider";
22

3-
const OUTGOING_ADDRESSES = new Set(
4-
toLower([
5-
"06102d319ab7e77b914a1bd135577f3e266fd82a3e537a02db281421ed8b3d13",
6-
"db2cf6ec67addde84cc1092378ea22e7bb2eecdeecac5e43febc1cb8fb64b5e5",
7-
"3be494deb669ff8d943463bb6042eabcf0c5346cf444d569e07204487716cb85",
8-
]),
9-
);
10-
11-
const INCOMING_ADDRESSES = new Set(
12-
toLower(["06102d319ab7e77b914a1bd135577f3e266fd82a3e537a02db281421ed8b3d13"]),
13-
);
3+
const chainportConfig = {
4+
0: {
5+
outgoingAddresses: new Set(
6+
toLower([
7+
"06102d319ab7e77b914a1bd135577f3e266fd82a3e537a02db281421ed8b3d13",
8+
"db2cf6ec67addde84cc1092378ea22e7bb2eecdeecac5e43febc1cb8fb64b5e5",
9+
"3be494deb669ff8d943463bb6042eabcf0c5346cf444d569e07204487716cb85",
10+
]),
11+
),
12+
incomingAddresses: new Set(
13+
toLower([
14+
"06102d319ab7e77b914a1bd135577f3e266fd82a3e537a02db281421ed8b3d13",
15+
]),
16+
),
17+
},
18+
1: {
19+
outgoingAddresses: new Set(
20+
toLower([
21+
"576ffdcc27e11d81f5180d3dc5690294941170d492b2d9503c39130b1f180405",
22+
"7ac2d6a59e19e66e590d014af013cd5611dc146e631fa2aedf0ee3ed1237eebe",
23+
]),
24+
),
25+
incomingAddresses: new Set(
26+
toLower([
27+
"1216302193e8f1ad020f458b54a163039403d803e98673c6a85e59b5f4a1a900",
28+
]),
29+
),
30+
},
31+
};
1432

1533
type TransactionData = TRPCRouterOutputs["getTransaction"];
1634
type TransactionNote = TransactionData["notes"][number];
1735

18-
export function isChainportNote(note: TransactionNote) {
36+
export function isChainportNote(networkId: number, note: TransactionNote) {
37+
if (networkId !== 1 && networkId !== 0) {
38+
throw new Error(`Unknown network id: ${networkId}`);
39+
}
40+
41+
const config = chainportConfig[networkId];
42+
1943
if (note.type === "send") {
20-
return hasAddress(OUTGOING_ADDRESSES, toLower(note.to));
44+
const { outgoingAddresses } = config;
45+
return hasAddress(outgoingAddresses, toLower(note.to));
2146
}
2247
if (note.type === "receive") {
23-
return hasAddress(INCOMING_ADDRESSES, toLower(note.from));
48+
const { incomingAddresses } = config;
49+
return hasAddress(incomingAddresses, toLower(note.from));
2450
}
2551
return false;
2652
}
2753

28-
export function isChainportTx(transactionData: TransactionData) {
54+
export function isChainportTx(
55+
networkId: number,
56+
transactionData: TransactionData,
57+
) {
2958
return transactionData.notes.some((note) => {
30-
return isChainportNote(note);
59+
return isChainportNote(networkId, note);
3160
});
3261
}
3362

0 commit comments

Comments
 (0)