From 26c6fc1f47f871802012fd9cc92aa967faa98102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Dan?= Date: Wed, 22 Nov 2023 16:38:16 +0100 Subject: [PATCH 1/2] feat: update code to fit unique token symbol --- package-lock.json | 16 ++++++++-------- packages/frontend/package.json | 2 +- packages/frontend/src/components/steps/Step2.tsx | 2 +- .../hooks/useCheckTokenOnReceivingSubnet.test.ts | 6 +++--- .../src/hooks/useCheckTokenOnReceivingSubnet.ts | 2 +- packages/frontend/src/hooks/useSendToken.test.ts | 6 +++--- packages/frontend/src/hooks/useSendToken.ts | 14 ++++---------- 7 files changed, 21 insertions(+), 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index 21b5cc4..ba1f31d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6319,9 +6319,9 @@ } }, "node_modules/@topos-protocol/topos-smart-contracts": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@topos-protocol/topos-smart-contracts/-/topos-smart-contracts-2.0.0.tgz", - "integrity": "sha512-9ElAqlPg7puWCH0F58l7TgnXheybzkmyNr2ssla/olwKRxcfKJl10k3U5CN03KaTkbkZY+Jhp5JW7BLL+8xhNA==", + "version": "3.0.0-rc1", + "resolved": "https://registry.npmjs.org/@topos-protocol/topos-smart-contracts/-/topos-smart-contracts-3.0.0-rc1.tgz", + "integrity": "sha512-lQnnvGPtdDma8VGaawWR+cgQnsEeFD0AbQFj2ahmpRaabnqEG3T8iXkJ1SJj6XUckkGQ4XjWsCAXiJTU/R7FPw==", "dependencies": { "@openzeppelin/contracts": "^4.8.3", "ethers": "^5.7.2", @@ -21649,7 +21649,7 @@ "@opentelemetry/exporter-trace-otlp-proto": "^0.45.0", "@opentelemetry/sdk-metrics": "^1.17.1", "@opentelemetry/sdk-trace-web": "^1.17.1", - "@topos-protocol/topos-smart-contracts": "^2.0.0", + "@topos-protocol/topos-smart-contracts": "^3.0.0-rc1", "@types/event-source-polyfill": "^1.0.1", "antd": "^5.4.0", "axios": "^1.0.0", @@ -26148,9 +26148,9 @@ "dev": true }, "@topos-protocol/topos-smart-contracts": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@topos-protocol/topos-smart-contracts/-/topos-smart-contracts-2.0.0.tgz", - "integrity": "sha512-9ElAqlPg7puWCH0F58l7TgnXheybzkmyNr2ssla/olwKRxcfKJl10k3U5CN03KaTkbkZY+Jhp5JW7BLL+8xhNA==", + "version": "3.0.0-rc1", + "resolved": "https://registry.npmjs.org/@topos-protocol/topos-smart-contracts/-/topos-smart-contracts-3.0.0-rc1.tgz", + "integrity": "sha512-lQnnvGPtdDma8VGaawWR+cgQnsEeFD0AbQFj2ahmpRaabnqEG3T8iXkJ1SJj6XUckkGQ4XjWsCAXiJTU/R7FPw==", "requires": { "@openzeppelin/contracts": "^4.8.3", "ethers": "^5.7.2", @@ -31094,7 +31094,7 @@ "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "14.0.0", "@testing-library/user-event": "^14.4.3", - "@topos-protocol/topos-smart-contracts": "^2.0.0", + "@topos-protocol/topos-smart-contracts": "^3.0.0-rc1", "@types/event-source-polyfill": "^1.0.1", "@types/react": "^18.0.28", "@types/react-dom": "^18.0.11", diff --git a/packages/frontend/package.json b/packages/frontend/package.json index 70b5847..8c8a043 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -28,7 +28,7 @@ "@opentelemetry/exporter-trace-otlp-proto": "^0.45.0", "@opentelemetry/sdk-metrics": "^1.17.1", "@opentelemetry/sdk-trace-web": "^1.17.1", - "@topos-protocol/topos-smart-contracts": "^2.0.0", + "@topos-protocol/topos-smart-contracts": "^3.0.0-rc1", "@types/event-source-polyfill": "^1.0.1", "antd": "^5.4.0", "axios": "^1.0.0", diff --git a/packages/frontend/src/components/steps/Step2.tsx b/packages/frontend/src/components/steps/Step2.tsx index 73f82e0..3a5182a 100644 --- a/packages/frontend/src/components/steps/Step2.tsx +++ b/packages/frontend/src/components/steps/Step2.tsx @@ -229,7 +229,7 @@ const Step2 = ({ onFinish }: StepProps) => { return sendToken( receivingSubnet?.id, - token?.addr, + token?.symbol, recipientAddress, parsedAmount ) diff --git a/packages/frontend/src/hooks/useCheckTokenOnReceivingSubnet.test.ts b/packages/frontend/src/hooks/useCheckTokenOnReceivingSubnet.test.ts index cf5b378..ca8d837 100644 --- a/packages/frontend/src/hooks/useCheckTokenOnReceivingSubnet.test.ts +++ b/packages/frontend/src/hooks/useCheckTokenOnReceivingSubnet.test.ts @@ -35,10 +35,10 @@ const providerSpy = vi .spyOn(ethers.providers, 'WebSocketProvider') .mockReturnValue({ getCode: getCodeMock } as any) -const getTokenByAddressMock = vi.fn().mockResolvedValue(tokenMock) +const getTokenBySymbolMock = vi.fn().mockResolvedValue(tokenMock) const contractConnectMock = vi.fn().mockReturnValue({ - getTokenByAddress: getTokenByAddressMock, + getTokenBySymbol: getTokenBySymbolMock, }) const contractMock = { @@ -65,7 +65,7 @@ describe('useCheckTokenOnReceivingSubnet', () => { expect(contractSpy).toHaveBeenCalled() expect(getCodeMock).toHaveBeenCalledWith(contractMock.address) expect(contractConnectMock).toHaveBeenCalled() - expect(getTokenByAddressMock).toHaveBeenCalledWith(tokenMock.addr) + expect(getTokenBySymbolMock).toHaveBeenCalledWith(tokenMock.symbol) }) }) }) diff --git a/packages/frontend/src/hooks/useCheckTokenOnReceivingSubnet.ts b/packages/frontend/src/hooks/useCheckTokenOnReceivingSubnet.ts index 48a1dd8..00167f5 100644 --- a/packages/frontend/src/hooks/useCheckTokenOnReceivingSubnet.ts +++ b/packages/frontend/src/hooks/useCheckTokenOnReceivingSubnet.ts @@ -36,7 +36,7 @@ export default function useCheckTokenOnSubnet() { const contract = erc20MessagingContract.connect(subnetProvider) const onChainToken = await contract - .getTokenByAddress(token.addr) + .getTokenBySymbol(token.symbol) .finally(() => { setLoading(false) }) diff --git a/packages/frontend/src/hooks/useSendToken.test.ts b/packages/frontend/src/hooks/useSendToken.test.ts index 81ec757..3ad176f 100644 --- a/packages/frontend/src/hooks/useSendToken.test.ts +++ b/packages/frontend/src/hooks/useSendToken.test.ts @@ -34,18 +34,18 @@ describe('sendToken', () => { const { result } = renderHook(() => useSendToken()) const receivingSubnetId = 'receiving' - const tokenAddress = 'tokenAddr' + const tokenSymbol = 'tokenSymbol' const recipientAddress = 'receivingAddr' const amount = BigNumber.from(1) await act(() => { result.current - .sendToken(receivingSubnetId, tokenAddress, recipientAddress, amount) + .sendToken(receivingSubnetId, tokenSymbol, recipientAddress, amount) .then(() => { expect(result.current.loading).toBe(true) expect(sendTokenMock).toHaveBeenCalledWith( receivingSubnetId, - tokenAddress, + tokenSymbol, recipientAddress, amount, { gasLimit: 4_000_000 } diff --git a/packages/frontend/src/hooks/useSendToken.ts b/packages/frontend/src/hooks/useSendToken.ts index bf45085..91da202 100644 --- a/packages/frontend/src/hooks/useSendToken.ts +++ b/packages/frontend/src/hooks/useSendToken.ts @@ -23,7 +23,7 @@ export default function useSendToken() { const sendToken = useCallback( ( receivingSubnetId: string, - tokenAddress: string, + tokenSymbol: string, recipientAddress: string, amount: BigNumber ) => @@ -31,15 +31,9 @@ export default function useSendToken() { setLoading(true) contract - .sendToken( - receivingSubnetId, - tokenAddress, - recipientAddress, - amount, - { - gasLimit: 4_000_000, - } - ) + .sendToken(receivingSubnetId, tokenSymbol, recipientAddress, amount, { + gasLimit: 4_000_000, + }) .then((tx: ContractTransaction) => { tx.wait() .then((receipt) => { From f9151537ae37e685c60974db5a575e3dbf3a840a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Dan?= Date: Thu, 23 Nov 2023 14:52:23 +0100 Subject: [PATCH 2/2] chore: update contracts npm pck --- package-lock.json | 16 ++++++++-------- packages/frontend/package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index ba1f31d..9fa9e01 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6319,9 +6319,9 @@ } }, "node_modules/@topos-protocol/topos-smart-contracts": { - "version": "3.0.0-rc1", - "resolved": "https://registry.npmjs.org/@topos-protocol/topos-smart-contracts/-/topos-smart-contracts-3.0.0-rc1.tgz", - "integrity": "sha512-lQnnvGPtdDma8VGaawWR+cgQnsEeFD0AbQFj2ahmpRaabnqEG3T8iXkJ1SJj6XUckkGQ4XjWsCAXiJTU/R7FPw==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@topos-protocol/topos-smart-contracts/-/topos-smart-contracts-3.0.0.tgz", + "integrity": "sha512-ABDny/flDSRzfZntdxeV3ZZWBO1s7amI1+3pxHYBdQ4EhvD5FJzlv8Go1QYbYrUf2q+vW1p+soY7+T9KDFE1QA==", "dependencies": { "@openzeppelin/contracts": "^4.8.3", "ethers": "^5.7.2", @@ -21649,7 +21649,7 @@ "@opentelemetry/exporter-trace-otlp-proto": "^0.45.0", "@opentelemetry/sdk-metrics": "^1.17.1", "@opentelemetry/sdk-trace-web": "^1.17.1", - "@topos-protocol/topos-smart-contracts": "^3.0.0-rc1", + "@topos-protocol/topos-smart-contracts": "^3.0.0", "@types/event-source-polyfill": "^1.0.1", "antd": "^5.4.0", "axios": "^1.0.0", @@ -26148,9 +26148,9 @@ "dev": true }, "@topos-protocol/topos-smart-contracts": { - "version": "3.0.0-rc1", - "resolved": "https://registry.npmjs.org/@topos-protocol/topos-smart-contracts/-/topos-smart-contracts-3.0.0-rc1.tgz", - "integrity": "sha512-lQnnvGPtdDma8VGaawWR+cgQnsEeFD0AbQFj2ahmpRaabnqEG3T8iXkJ1SJj6XUckkGQ4XjWsCAXiJTU/R7FPw==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@topos-protocol/topos-smart-contracts/-/topos-smart-contracts-3.0.0.tgz", + "integrity": "sha512-ABDny/flDSRzfZntdxeV3ZZWBO1s7amI1+3pxHYBdQ4EhvD5FJzlv8Go1QYbYrUf2q+vW1p+soY7+T9KDFE1QA==", "requires": { "@openzeppelin/contracts": "^4.8.3", "ethers": "^5.7.2", @@ -31094,7 +31094,7 @@ "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "14.0.0", "@testing-library/user-event": "^14.4.3", - "@topos-protocol/topos-smart-contracts": "^3.0.0-rc1", + "@topos-protocol/topos-smart-contracts": "^3.0.0", "@types/event-source-polyfill": "^1.0.1", "@types/react": "^18.0.28", "@types/react-dom": "^18.0.11", diff --git a/packages/frontend/package.json b/packages/frontend/package.json index 8c8a043..f06d36a 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -28,7 +28,7 @@ "@opentelemetry/exporter-trace-otlp-proto": "^0.45.0", "@opentelemetry/sdk-metrics": "^1.17.1", "@opentelemetry/sdk-trace-web": "^1.17.1", - "@topos-protocol/topos-smart-contracts": "^3.0.0-rc1", + "@topos-protocol/topos-smart-contracts": "^3.0.0", "@types/event-source-polyfill": "^1.0.1", "antd": "^5.4.0", "axios": "^1.0.0",