diff --git a/src/core/getTokenInfo.ts b/src/core/getTokenInfo.ts index 5ee958b..b84c5a5 100644 --- a/src/core/getTokenInfo.ts +++ b/src/core/getTokenInfo.ts @@ -3,17 +3,37 @@ import { ETH_ADDRESS, isSameAddress } from "../helpers"; import { IToken } from "../typing"; import { getJsonRpcProvider } from "./internal/getJsonRpcProvider"; -const fetchTokenInfo = async (tokenAddress: string) => { +interface ITokenWithName extends IToken { + name?: string; +} + +const fetchTokenInfo = async (tokenAddress: string, withName?: boolean) => { const provider = getJsonRpcProvider(); const token = ERC20__factory.connect(tokenAddress, provider!); try { await token.symbol(); - return Promise.all([token.symbol(), token.decimals()]).then((results) => ({ - address: tokenAddress, - symbol: results[0], - decimals: results[1], - })); + const promises = [token.symbol(), token.decimals()]; + return Promise.all(withName ? [...promises, token.name()] : promises).then( + (results) => { + const [symbol, decimals] = results; + const result = { + address: tokenAddress, + symbol, + decimals, + }; + + if (withName) { + const name = results[3]; + return { + ...result, + name, + } as ITokenWithName; + } + + return result as IToken; + }, + ); } catch (e) { console.error(e); } @@ -27,7 +47,8 @@ const fetchTokenInfo = async (tokenAddress: string) => { */ export const getTokenInfo = async ( tokenAddress = ETH_ADDRESS, -): Promise => { + withName?: boolean, +): Promise => { if (isSameAddress(tokenAddress, ETH_ADDRESS)) { return { address: tokenAddress, @@ -37,7 +58,7 @@ export const getTokenInfo = async ( } const storedValue = window.localStorage.getItem(tokenAddress); - let tokenInfo: IToken | null = null; + let tokenInfo: IToken | ITokenWithName = null; // There was some value stored if (storedValue) { @@ -50,7 +71,7 @@ export const getTokenInfo = async ( } console.info("fetching new information"); - tokenInfo = await fetchTokenInfo(tokenAddress); + tokenInfo = await fetchTokenInfo(tokenAddress, withName); if (tokenInfo) { window.localStorage.setItem(tokenAddress, JSON.stringify(tokenInfo)); diff --git a/src/helpers/__tests__/validPayment.test.tsx b/src/helpers/__tests__/validPayment.test.tsx index 0a72e0b..c9eb9d9 100644 --- a/src/helpers/__tests__/validPayment.test.tsx +++ b/src/helpers/__tests__/validPayment.test.tsx @@ -25,7 +25,9 @@ describe("Valid payments function", () => { ...params, seller: "0x7bD733DBc10A1cD04e1e51cC89450941c928", }), - ).rejects.toThrow("seller is invalid: 0x7bD733DBc10A1cD04e1e51cC89450941c928."); + ).rejects.toThrow( + "seller is invalid: 0x7bD733DBc10A1cD04e1e51cC89450941c928.", + ); }); it("Should throw an error given an invalid marketplace address ", async () => { @@ -34,7 +36,9 @@ describe("Valid payments function", () => { ...params, marketplace: "0x7bD733DBc10A1cD04e1e51cC89450941c928", }), - ).rejects.toThrow("marketplace is invalid: 0x7bD733DBc10A1cD04e1e51cC89450941c928."); + ).rejects.toThrow( + "marketplace is invalid: 0x7bD733DBc10A1cD04e1e51cC89450941c928.", + ); }); it("Should throw an error given an invalid arbitrator address ", async () => { @@ -43,7 +47,9 @@ describe("Valid payments function", () => { ...params, marketplace: "0x7bD733DBc10A1cD04e1e51cC89450941c928", }), - ).rejects.toThrow("marketplace is invalid: 0x7bD733DBc10A1cD04e1e51cC89450941c928."); + ).rejects.toThrow( + "marketplace is invalid: 0x7bD733DBc10A1cD04e1e51cC89450941c928.", + ); }); it("Should throw an error given an invalid token address ", async () => { @@ -52,7 +58,9 @@ describe("Valid payments function", () => { ...params, marketplace: "0x7bD733DBc10A1cD04e1e51cC89450941c928", }), - ).rejects.toThrow("marketplace is invalid: 0x7bD733DBc10A1cD04e1e51cC89450941c928."); + ).rejects.toThrow( + "marketplace is invalid: 0x7bD733DBc10A1cD04e1e51cC89450941c928.", + ); }); it("Should throw an error given invalid amount", async () => { diff --git a/src/typing/index.ts b/src/typing/index.ts index 5b5adfb..2e3ad09 100644 --- a/src/typing/index.ts +++ b/src/typing/index.ts @@ -837,7 +837,7 @@ export interface IClaimTransactionCallbacks } export interface IPaymentModalProps { - paymentProps: IPaymentProps; + paymentProps: IPaymentPropsData; deferredPromise: Deferred; callbacks?: IPayTransactionCallbacks; }