Skip to content

Commit 949d045

Browse files
authored
Added formatting to checksum addresses (#195)
1 parent e3d0d28 commit 949d045

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/create-invoice-form/src/lib/utils/prepareRequest.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { parseUnits, zeroAddress, getAddress } from "viem";
12
import { Types, Utils } from "@requestnetwork/request-client.js";
23
import type { CustomFormData } from "@requestnetwork/shared-types";
3-
import { parseUnits, zeroAddress } from "viem";
44

55
interface IRequestParams {
66
currency: any;
@@ -34,11 +34,11 @@ export const prepareRequestParams = ({
3434
).toString(),
3535
payee: {
3636
type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
37-
value: formData.creatorId,
37+
value: getAddress(formData.creatorId),
3838
},
3939
payer: {
4040
type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
41-
value: formData.payerAddress,
41+
value: getAddress(formData.payerAddress),
4242
},
4343
timestamp: Utils.getCurrentTimestampInSecond(),
4444
},
@@ -49,7 +49,7 @@ export const prepareRequestParams = ({
4949
: Types.Extension.PAYMENT_NETWORK_ID.ERC20_FEE_PROXY_CONTRACT,
5050
parameters: {
5151
paymentNetworkName: currency.network,
52-
paymentAddress: formData.payeeAddress,
52+
paymentAddress: getAddress(formData.payeeAddress),
5353
feeAddress: zeroAddress,
5454
feeAmount: "0",
5555
},
@@ -122,7 +122,7 @@ export const prepareRequestParams = ({
122122
},
123123
signer: {
124124
type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
125-
value: address as string,
125+
value: getAddress(address as string),
126126
},
127127
};
128128
};

packages/invoice-dashboard/src/utils/formatAddress.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getAddress } from "viem";
12
import { checkAddress } from "@requestnetwork/shared-utils/checkEthAddress";
23

34
export const formatAddress = (
@@ -9,5 +10,7 @@ export const formatAddress = (
910
console.error("Invalid address!");
1011
}
1112

12-
return `${address.slice(0, first)}...${address.slice(-last)}`;
13+
const checksumAddress = getAddress(address);
14+
15+
return `${checksumAddress.slice(0, first)}...${checksumAddress.slice(-last)}`;
1316
};

0 commit comments

Comments
 (0)