From 0758e68c7f5d505269957005305f8d2a42398702 Mon Sep 17 00:00:00 2001 From: Kamil Pyszkowski Date: Tue, 3 Oct 2023 16:49:24 +0200 Subject: [PATCH 01/14] Update contract for AuthorizationIncreased event Replaced contract-providing hook (useStakingAppContract to useTStakingContract). --- .../useSubscribeToAuthorizationIncreasedEvent.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/hooks/staking-applications/useSubscribeToAuthorizationIncreasedEvent.ts b/src/hooks/staking-applications/useSubscribeToAuthorizationIncreasedEvent.ts index 5eca9e0a8..9d04b9778 100644 --- a/src/hooks/staking-applications/useSubscribeToAuthorizationIncreasedEvent.ts +++ b/src/hooks/staking-applications/useSubscribeToAuthorizationIncreasedEvent.ts @@ -2,14 +2,16 @@ import { stakingApplicationsSlice, StakingAppName, } from "../../store/staking-applications" -import { useSubscribeToContractEvent } from "../../web3/hooks" +import { + useSubscribeToContractEvent, + useTStakingContract, +} from "../../web3/hooks" import { useAppDispatch } from "../store" -import { useStakingAppContract } from "./useStakingAppContract" export const useSubscribeToAuthorizationIncreasedEvent = ( appName: StakingAppName ) => { - const contract = useStakingAppContract(appName) + const contract = useTStakingContract() const dispatch = useAppDispatch() useSubscribeToContractEvent( From 5d3587f27f58f22662f335db9956d72d681eba65 Mon Sep 17 00:00:00 2001 From: michalsmiarowski Date: Wed, 4 Oct 2023 15:40:52 +0200 Subject: [PATCH 02/14] Fix tbtc-v2.ts error after new update There was a change in https://github.com/keep-network/tbtc-v2/pull/702 in which we've added additional arguments to `assembleDepositTransaction` function. The order of the arguments was also changed. Because of that we couldn't build the project because we use that function in our dApp mock of the bitcoin client. We are fixing this by passing two additional arguments to the `assembleDepositTransaction` function - `network` and `fee`. We are also making sure that we pass the arguments in the correct order. --- src/tbtc/mock-bitcoin-client.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/tbtc/mock-bitcoin-client.ts b/src/tbtc/mock-bitcoin-client.ts index 57d9e39d7..988669d0c 100644 --- a/src/tbtc/mock-bitcoin-client.ts +++ b/src/tbtc/mock-bitcoin-client.ts @@ -38,6 +38,7 @@ export const testnetUTXO: UnspentTransactionOutput & RawTransaction = { ...testnetTransaction, } const testnetPrivateKey = "cRJvyxtoggjAm9A94cB86hZ7Y62z2ei5VNJHLksFi2xdnz1GJ6xt" +const fee = BigNumber.from(1520) export class MockBitcoinClient implements Client { private _unspentTransactionOutputs = new Map< @@ -168,10 +169,12 @@ export class MockBitcoinClient implements Client { depositUtxo, rawTransaction: transaction, } = await assembleDepositTransaction( + network, deposit, - [testnetUTXO], testnetPrivateKey, - true + true, + [testnetUTXO], + fee ) // mock second deposit transaction @@ -192,10 +195,12 @@ export class MockBitcoinClient implements Client { depositUtxo: depositUtxo2, rawTransaction: transaction2, } = await assembleDepositTransaction( + network, deposit2, - [testnetUtxo2], testnetPrivateKey, - true + true, + [testnetUtxo2], + fee ) const utxos = new Map() From 54c4650eb85b753ec3bbafc4675fbffa215e9a10 Mon Sep 17 00:00:00 2001 From: michalsmiarowski Date: Thu, 5 Oct 2023 15:15:07 +0200 Subject: [PATCH 03/14] Revert changes in mock-bitcoin-client We've decided that we don't have to apply the newest changes from `tbtc-v2.ts` yet, so we are reverting the changes made in the commit 5d3587f27f58f22662f335db9956d72d681eba65. In the next commit we will install the dev dependency of that library in the `package.json`. This should fix all the build errors that happened before applying the changes (that we are reverting in this commit). --- src/tbtc/mock-bitcoin-client.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/tbtc/mock-bitcoin-client.ts b/src/tbtc/mock-bitcoin-client.ts index 988669d0c..57d9e39d7 100644 --- a/src/tbtc/mock-bitcoin-client.ts +++ b/src/tbtc/mock-bitcoin-client.ts @@ -38,7 +38,6 @@ export const testnetUTXO: UnspentTransactionOutput & RawTransaction = { ...testnetTransaction, } const testnetPrivateKey = "cRJvyxtoggjAm9A94cB86hZ7Y62z2ei5VNJHLksFi2xdnz1GJ6xt" -const fee = BigNumber.from(1520) export class MockBitcoinClient implements Client { private _unspentTransactionOutputs = new Map< @@ -169,12 +168,10 @@ export class MockBitcoinClient implements Client { depositUtxo, rawTransaction: transaction, } = await assembleDepositTransaction( - network, deposit, - testnetPrivateKey, - true, [testnetUTXO], - fee + testnetPrivateKey, + true ) // mock second deposit transaction @@ -195,12 +192,10 @@ export class MockBitcoinClient implements Client { depositUtxo: depositUtxo2, rawTransaction: transaction2, } = await assembleDepositTransaction( - network, deposit2, - testnetPrivateKey, - true, [testnetUtxo2], - fee + testnetPrivateKey, + true ) const utxos = new Map() From 015050d4cdc542d928a463512667189ee8e20fe3 Mon Sep 17 00:00:00 2001 From: michalsmiarowski Date: Thu, 5 Oct 2023 16:48:07 +0200 Subject: [PATCH 04/14] Set `tbtc-v2.ts` package version to dev Set `tbtc-v2.ts` package version to `1.3.0-dev.9` version in package.json. This is the closest dev version to the last goerli version (which is `1.3.0-goerli.1`. There is a newer one - `1.4.0-goerli.0`, but it will be deprecated). --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index a95d3e815..02854bdc0 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "@keep-network/random-beacon": "development", "@keep-network/tbtc": "development", "@keep-network/tbtc-v2": "development", - "@keep-network/tbtc-v2.ts": "development", + "@keep-network/tbtc-v2.ts": "1.3.0-dev.9", "@ledgerhq/connect-kit-loader": "^1.1.2", "@reduxjs/toolkit": "^1.6.1", "@rehooks/local-storage": "^2.4.4", diff --git a/yarn.lock b/yarn.lock index a5d80305e..8daff56ef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3193,10 +3193,10 @@ "@openzeppelin/contracts" "^4.3.2" "@thesis/solidity-contracts" "github:thesis/solidity-contracts#4985bcf" -"@keep-network/tbtc-v2.ts@development": - version "1.3.0-dev.8" - resolved "https://registry.yarnpkg.com/@keep-network/tbtc-v2.ts/-/tbtc-v2.ts-1.3.0-dev.8.tgz#08fb1a06dbe6d78a9c7b0d610363c68a135a6741" - integrity sha512-Y5fej8YhBbTZesE+87LNLHGt7I/G97f75J+15ieYyb2nqsJ/CcvMscIEAE/hNgxpnq4IWv/8qwYoldrHY4ix8w== +"@keep-network/tbtc-v2.ts@1.3.0-dev.9": + version "1.3.0-dev.9" + resolved "https://registry.yarnpkg.com/@keep-network/tbtc-v2.ts/-/tbtc-v2.ts-1.3.0-dev.9.tgz#b8961e2701ec1395da747269fea8cb6b236c4b77" + integrity sha512-cGtylB9Rc1Mltltl9NQJ1YKvTcs8HYTRRDsXlqf1VVtZcntngrl5Mu/OymuH84PlmpZpYMS95ZldEH9QoEMaeQ== dependencies: "@keep-network/ecdsa" "2.1.0-dev.15" "@keep-network/tbtc-v2" "1.6.0-dev.0" From 6a017af9a2804dfcdd9dd421e734bc5077987245 Mon Sep 17 00:00:00 2001 From: michalsmiarowski Date: Thu, 5 Oct 2023 16:53:53 +0200 Subject: [PATCH 05/14] Remove unnecessary slash from README Becuase of the slash it's not possilbe to run the command given in README file. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c8b3c04af..d8ca59b2c 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ yarn upgrade @keep-network/coverage-pools@goerli \ @keep-network/tbtc-v2@goerli \ @keep-network/tbtc-v2.ts@goerli \ @threshold-network/coverage-pools@npm:@keep-network/coverage-pools@goerli \ - @threshold-network/solidity-contracts@goerli \ + @threshold-network/solidity-contracts@goerli ``` **NOTE 1:** We use the same Goerli versions for both From 475964925bbab027f9d3030a90948cb409018d63 Mon Sep 17 00:00:00 2001 From: Kamil Pyszkowski Date: Thu, 5 Oct 2023 17:51:05 +0200 Subject: [PATCH 06/14] Extract name from application address Extracted application name, removed hooks `appName` argument --- src/App.tsx | 3 +-- ...eSubscribeToAuthorizationIncreasedEvent.ts | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 6806aef6e..06cd66939 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -68,8 +68,7 @@ const Web3EventHandlerComponent = () => { useSubscribeToStakedEvent() useSubscribeToUnstakedEvent() useSubscribeToToppedUpEvent() - useSubscribeToAuthorizationIncreasedEvent("tbtc") - useSubscribeToAuthorizationIncreasedEvent("randomBeacon") + useSubscribeToAuthorizationIncreasedEvent() useSubscribeToAuthorizationDecreaseApprovedEvent("tbtc") useSubscribeToAuthorizationDecreaseApprovedEvent("randomBeacon") useSubscribeToAuthorizationDecreaseRequestedEvent("tbtc") diff --git a/src/hooks/staking-applications/useSubscribeToAuthorizationIncreasedEvent.ts b/src/hooks/staking-applications/useSubscribeToAuthorizationIncreasedEvent.ts index 9d04b9778..a3bb4c7b5 100644 --- a/src/hooks/staking-applications/useSubscribeToAuthorizationIncreasedEvent.ts +++ b/src/hooks/staking-applications/useSubscribeToAuthorizationIncreasedEvent.ts @@ -2,15 +2,25 @@ import { stakingApplicationsSlice, StakingAppName, } from "../../store/staking-applications" +import { threshold } from "../../utils/getThresholdLib" import { useSubscribeToContractEvent, useTStakingContract, } from "../../web3/hooks" import { useAppDispatch } from "../store" -export const useSubscribeToAuthorizationIncreasedEvent = ( - appName: StakingAppName -) => { +const getApplicationName = (address: string) => { + const { multiAppStaking } = threshold + const namesDictionary = Object.fromEntries( + Object.entries(multiAppStaking).map(([name, { address }]) => [ + address, + name === "ecdsa" ? "tbtc" : name, + ]) + ) + return namesDictionary[address] +} + +export const useSubscribeToAuthorizationIncreasedEvent = () => { const contract = useTStakingContract() const dispatch = useAppDispatch() @@ -18,7 +28,9 @@ export const useSubscribeToAuthorizationIncreasedEvent = ( contract, "AuthorizationIncreased", // @ts-ignore - async (stakingProvider, operator, fromAmount, toAmount) => { + async (stakingProvider, applicationAddress, fromAmount, toAmount) => { + const appName = getApplicationName(applicationAddress) + dispatch( stakingApplicationsSlice.actions.authorizationIncreased({ stakingProvider, From 9d1fbf2f08fefbf50b469abec994cd2c866ad27d Mon Sep 17 00:00:00 2001 From: Kamil Pyszkowski Date: Fri, 6 Oct 2023 11:05:01 +0200 Subject: [PATCH 07/14] Rename callback argument: applicationAddress -> application --- .../useSubscribeToAuthorizationIncreasedEvent.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hooks/staking-applications/useSubscribeToAuthorizationIncreasedEvent.ts b/src/hooks/staking-applications/useSubscribeToAuthorizationIncreasedEvent.ts index a3bb4c7b5..bf54693a9 100644 --- a/src/hooks/staking-applications/useSubscribeToAuthorizationIncreasedEvent.ts +++ b/src/hooks/staking-applications/useSubscribeToAuthorizationIncreasedEvent.ts @@ -28,8 +28,8 @@ export const useSubscribeToAuthorizationIncreasedEvent = () => { contract, "AuthorizationIncreased", // @ts-ignore - async (stakingProvider, applicationAddress, fromAmount, toAmount) => { - const appName = getApplicationName(applicationAddress) + async (stakingProvider, application, fromAmount, toAmount) => { + const appName = getApplicationName(application) dispatch( stakingApplicationsSlice.actions.authorizationIncreased({ From 36d20c74289d911ebc0964c4df8b95aae4db4c5f Mon Sep 17 00:00:00 2001 From: Kamil Pyszkowski Date: Mon, 9 Oct 2023 14:45:24 +0200 Subject: [PATCH 08/14] Refactor app name/label utils https://github.com/threshold-network/token-dashboard/pull/636\#discussion_r1350098230 --- .../InititateDeauthorization.tsx | 4 ++-- .../AuthorizeStakingApps.tsx | 4 ++-- ...eSubscribeToAuthorizationIncreasedEvent.ts | 20 +++-------------- .../Staking/OperatorAddressMappingCard.tsx | 4 ++-- src/utils/getStakingAppLabel.ts | 22 ++++++++++++------- 5 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/components/Modal/DeauthorizeApplicationModal/InititateDeauthorization.tsx b/src/components/Modal/DeauthorizeApplicationModal/InititateDeauthorization.tsx index a9e3dd103..195e7a3f1 100644 --- a/src/components/Modal/DeauthorizeApplicationModal/InititateDeauthorization.tsx +++ b/src/components/Modal/DeauthorizeApplicationModal/InititateDeauthorization.tsx @@ -24,7 +24,7 @@ import shortenAddress from "../../../utils/shortenAddress" import TokenBalance from "../../TokenBalance" import { StakingAppName } from "../../../store/staking-applications" import { useInitiateDeauthorization } from "../../../hooks/staking-applications" -import { getSakingAppLabel } from "../../../utils/getStakingAppLabel" +import { getStakingAppLabelFromAppName } from "../../../utils/getStakingAppLabel" import ModalCloseButton from "../ModalCloseButton" import { StakingProviderAppInfo } from "../../../threshold-ts/applications" @@ -62,7 +62,7 @@ const InitiateDeauthorization: FC<
You're about to initiate the decrease of your{" "} - {getSakingAppLabel(stakingAppName)} authorization. + {getStakingAppLabelFromAppName(stakingAppName)} authorization.
Initiation and confirmation of deauthorization is a two step action. diff --git a/src/components/Modal/StakingApplications/AuthorizeStakingApps.tsx b/src/components/Modal/StakingApplications/AuthorizeStakingApps.tsx index e1b61a61c..b4917c212 100644 --- a/src/components/Modal/StakingApplications/AuthorizeStakingApps.tsx +++ b/src/components/Modal/StakingApplications/AuthorizeStakingApps.tsx @@ -29,7 +29,7 @@ import { selectStakingAppByStakingProvider, StakingAppName, } from "../../../store/staking-applications" -import { getSakingAppLabel } from "../../../utils/getStakingAppLabel" +import { getStakingAppLabelFromAppName } from "../../../utils/getStakingAppLabel" import ModalCloseButton from "../ModalCloseButton" export type AuthorizeAppsProps = BaseModalProps & { @@ -125,7 +125,7 @@ const StakingApplicationToAuth: FC<{ - {getSakingAppLabel(appName)} app - {percentage} + {getStakingAppLabelFromAppName(appName)} app - {percentage} Authorization Amount { - const { multiAppStaking } = threshold - const namesDictionary = Object.fromEntries( - Object.entries(multiAppStaking).map(([name, { address }]) => [ - address, - name === "ecdsa" ? "tbtc" : name, - ]) - ) - return namesDictionary[address] -} - export const useSubscribeToAuthorizationIncreasedEvent = () => { const contract = useTStakingContract() const dispatch = useAppDispatch() @@ -29,7 +15,7 @@ export const useSubscribeToAuthorizationIncreasedEvent = () => { "AuthorizationIncreased", // @ts-ignore async (stakingProvider, application, fromAmount, toAmount) => { - const appName = getApplicationName(application) + const appName = getStakingAppNameFromAppAddress(application) dispatch( stakingApplicationsSlice.actions.authorizationIncreased({ diff --git a/src/pages/Staking/OperatorAddressMappingCard.tsx b/src/pages/Staking/OperatorAddressMappingCard.tsx index 3c4c303df..47e738ab3 100644 --- a/src/pages/Staking/OperatorAddressMappingCard.tsx +++ b/src/pages/Staking/OperatorAddressMappingCard.tsx @@ -23,7 +23,7 @@ import { selectMappedOperators } from "../../store/account/selectors" import shortenAddress from "../../utils/shortenAddress" import { isAddressZero } from "../../web3/utils" import { FcCheckmark, FiLink2 } from "react-icons/all" -import { getSakingAppLabel } from "../../utils/getStakingAppLabel" +import { getStakingAppLabelFromAppName } from "../../utils/getStakingAppLabel" import { StakingAppName } from "../../store/staking-applications" const OperatorAddressMappingCard: FC<{ stakingProvider: string }> = ({ @@ -63,7 +63,7 @@ const OperatorAddressMappingCard: FC<{ stakingProvider: string }> = ({ - {getSakingAppLabel(appName as StakingAppName)} App + {getStakingAppLabelFromAppName(appName as StakingAppName)} App diff --git a/src/utils/getStakingAppLabel.ts b/src/utils/getStakingAppLabel.ts index f8ce7ec95..5a9b475a2 100644 --- a/src/utils/getStakingAppLabel.ts +++ b/src/utils/getStakingAppLabel.ts @@ -6,16 +6,22 @@ const stakingAppNameToAppLabel: Record = { randomBeacon: "Random Beacon", } -const stakingAppAddressToName: { [key: string]: string } = { - [threshold.multiAppStaking.ecdsa.address]: stakingAppNameToAppLabel.tbtc, - [threshold.multiAppStaking.randomBeacon.address]: - stakingAppNameToAppLabel.randomBeacon, +const stakingAppAddressToAppName: Record = { + [threshold.multiAppStaking.ecdsa.address]: "tbtc", + [threshold.multiAppStaking.randomBeacon.address]: "randomBeacon", } -export const getStakingAppNameFromAddress = (stakingAppAddress: string) => { - return stakingAppAddressToName[stakingAppAddress] ?? "App" +export const getStakingAppNameFromAppAddress = (stakingAppAddress: string) => { + return stakingAppAddressToAppName[stakingAppAddress] } -export const getSakingAppLabel = (stakingAppName: StakingAppName) => { - return stakingAppNameToAppLabel[stakingAppName] +export const getStakingAppLabelFromAppName = ( + stakingAppName: StakingAppName +) => { + return stakingAppNameToAppLabel[stakingAppName] || "App" +} + +export const getStakingAppLabelFromAppAddress = (address: string) => { + const appName = getStakingAppNameFromAppAddress(address) + return getStakingAppLabelFromAppName(appName) || "App" } From 95b52b769bcb0242136d4e7ad70aeed326f94454 Mon Sep 17 00:00:00 2001 From: Kamil Pyszkowski Date: Mon, 9 Oct 2023 15:17:10 +0200 Subject: [PATCH 09/14] Add tests for app label/name utils --- .../__tests__/getStakingAppLabel.test.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/utils/__tests__/getStakingAppLabel.test.ts diff --git a/src/utils/__tests__/getStakingAppLabel.test.ts b/src/utils/__tests__/getStakingAppLabel.test.ts new file mode 100644 index 000000000..d289ff355 --- /dev/null +++ b/src/utils/__tests__/getStakingAppLabel.test.ts @@ -0,0 +1,47 @@ +import { + getStakingAppLabelFromAppAddress, + getStakingAppLabelFromAppName, + getStakingAppNameFromAppAddress, +} from "../getStakingAppLabel" +import { StakingAppName } from "../../store/staking-applications" +import { getThresholdLib } from "../getThresholdLib" + +const MOCK_ADDRESSES: Record = { + tbtc: getThresholdLib().multiAppStaking.ecdsa.address, + randomBeacon: getThresholdLib().multiAppStaking.randomBeacon.address, +} +const MOCK_LABELS: Record = { + tbtc: "tBTC", + randomBeacon: "Random Beacon", +} +const MOCK_APP_NAMES: StakingAppName[] = ["tbtc", "randomBeacon"] + +describe("Staking app label utils tests", () => { + const [tbtcName, rbName] = MOCK_APP_NAMES + const tbtcAddress = MOCK_ADDRESSES[tbtcName] + const rbAddress = MOCK_ADDRESSES[rbName] + + it("returns correct app label if app address is given", () => { + const resultTbtcLabel = getStakingAppLabelFromAppAddress(tbtcAddress) + const resultRbLabel = getStakingAppLabelFromAppAddress(rbAddress) + + expect(resultTbtcLabel).toBe(MOCK_LABELS[tbtcName]) + expect(resultRbLabel).toBe(MOCK_LABELS[rbName]) + }) + + it("returns correct app label if app name is given", () => { + const resultTbtcLabel = getStakingAppLabelFromAppName(tbtcName) + const resultRbLabel = getStakingAppLabelFromAppName(rbName) + + expect(resultTbtcLabel).toBe(MOCK_LABELS[tbtcName]) + expect(resultRbLabel).toBe(MOCK_LABELS[rbName]) + }) + + it("returns correct app name if address is given", () => { + const resultTbtcName = getStakingAppNameFromAppAddress(tbtcAddress) + const resultRbName = getStakingAppNameFromAppAddress(rbAddress) + + expect(resultTbtcName).toBe(tbtcName) + expect(resultRbName).toBe(rbName) + }) +}) From e79771c28e93912b0da92cfed73b30d7b511ee1b Mon Sep 17 00:00:00 2001 From: Kamil Pyszkowski Date: Mon, 9 Oct 2023 15:31:45 +0200 Subject: [PATCH 10/14] Update import --- .../StakingApplications/StakingApplicationsAuthorized.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Modal/StakingApplications/StakingApplicationsAuthorized.tsx b/src/components/Modal/StakingApplications/StakingApplicationsAuthorized.tsx index 5410c74fd..a79c88104 100644 --- a/src/components/Modal/StakingApplications/StakingApplicationsAuthorized.tsx +++ b/src/components/Modal/StakingApplications/StakingApplicationsAuthorized.tsx @@ -32,7 +32,7 @@ import { formatTokenAmount } from "../../../utils/formatAmount" import { ExplorerDataType } from "../../../utils/createEtherscanLink" import { ExternalHref } from "../../../enums" import { BaseModalProps } from "../../../types" -import { getStakingAppNameFromAddress } from "../../../utils/getStakingAppLabel" +import { getStakingAppNameFromAppAddress } from "../../../utils/getStakingAppLabel" import StakingTimeline from "../../StakingTimeline" import ButtonLink from "../../ButtonLink" import ModalCloseButton from "../ModalCloseButton" @@ -79,7 +79,7 @@ const StakingApplicationsAuthorizedBase: FC< {authorizedStakingApplications.map((_) => ( - {`${getStakingAppNameFromAddress( + {`${getStakingAppNameFromAppAddress( _.address )} Authorization Amount`} {`${formatTokenAmount(_.amount)} T (${formatPercentage( From b68d3b5aeb42ea33028f0fa850df723199844aae Mon Sep 17 00:00:00 2001 From: Kamil Pyszkowski Date: Thu, 12 Oct 2023 11:26:23 +0200 Subject: [PATCH 11/14] Remove fallback return value --- src/utils/getStakingAppLabel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/getStakingAppLabel.ts b/src/utils/getStakingAppLabel.ts index 5a9b475a2..90587750e 100644 --- a/src/utils/getStakingAppLabel.ts +++ b/src/utils/getStakingAppLabel.ts @@ -18,7 +18,7 @@ export const getStakingAppNameFromAppAddress = (stakingAppAddress: string) => { export const getStakingAppLabelFromAppName = ( stakingAppName: StakingAppName ) => { - return stakingAppNameToAppLabel[stakingAppName] || "App" + return stakingAppNameToAppLabel[stakingAppName] } export const getStakingAppLabelFromAppAddress = (address: string) => { From 112e081f8296f7a7a3c1a150331c8785721edfee Mon Sep 17 00:00:00 2001 From: Kamil Pyszkowski Date: Thu, 12 Oct 2023 11:33:07 +0200 Subject: [PATCH 12/14] Rename variables rb -> randomBeacon mock variables: CAPS -> camelCase --- .../__tests__/getStakingAppLabel.test.ts | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/utils/__tests__/getStakingAppLabel.test.ts b/src/utils/__tests__/getStakingAppLabel.test.ts index d289ff355..dabbd038a 100644 --- a/src/utils/__tests__/getStakingAppLabel.test.ts +++ b/src/utils/__tests__/getStakingAppLabel.test.ts @@ -6,42 +6,45 @@ import { import { StakingAppName } from "../../store/staking-applications" import { getThresholdLib } from "../getThresholdLib" -const MOCK_ADDRESSES: Record = { +const mockAddresses: Record = { tbtc: getThresholdLib().multiAppStaking.ecdsa.address, randomBeacon: getThresholdLib().multiAppStaking.randomBeacon.address, } -const MOCK_LABELS: Record = { +const mockLabels: Record = { tbtc: "tBTC", randomBeacon: "Random Beacon", } -const MOCK_APP_NAMES: StakingAppName[] = ["tbtc", "randomBeacon"] +const mockAppNames: StakingAppName[] = ["tbtc", "randomBeacon"] describe("Staking app label utils tests", () => { - const [tbtcName, rbName] = MOCK_APP_NAMES - const tbtcAddress = MOCK_ADDRESSES[tbtcName] - const rbAddress = MOCK_ADDRESSES[rbName] + const [tbtcName, randomBeaconName] = mockAppNames + const tbtcAddress = mockAddresses[tbtcName] + const randomBeaconAddress = mockAddresses[randomBeaconName] it("returns correct app label if app address is given", () => { const resultTbtcLabel = getStakingAppLabelFromAppAddress(tbtcAddress) - const resultRbLabel = getStakingAppLabelFromAppAddress(rbAddress) + const resultRandomBeaconLabel = + getStakingAppLabelFromAppAddress(randomBeaconAddress) - expect(resultTbtcLabel).toBe(MOCK_LABELS[tbtcName]) - expect(resultRbLabel).toBe(MOCK_LABELS[rbName]) + expect(resultTbtcLabel).toBe(mockLabels[tbtcName]) + expect(resultRandomBeaconLabel).toBe(mockLabels[randomBeaconName]) }) it("returns correct app label if app name is given", () => { const resultTbtcLabel = getStakingAppLabelFromAppName(tbtcName) - const resultRbLabel = getStakingAppLabelFromAppName(rbName) + const resultRandomBeaconLabel = + getStakingAppLabelFromAppName(randomBeaconName) - expect(resultTbtcLabel).toBe(MOCK_LABELS[tbtcName]) - expect(resultRbLabel).toBe(MOCK_LABELS[rbName]) + expect(resultTbtcLabel).toBe(mockLabels[tbtcName]) + expect(resultRandomBeaconLabel).toBe(mockLabels[randomBeaconName]) }) it("returns correct app name if address is given", () => { const resultTbtcName = getStakingAppNameFromAppAddress(tbtcAddress) - const resultRbName = getStakingAppNameFromAppAddress(rbAddress) + const resultRandomBeaconName = + getStakingAppNameFromAppAddress(randomBeaconAddress) expect(resultTbtcName).toBe(tbtcName) - expect(resultRbName).toBe(rbName) + expect(resultRandomBeaconName).toBe(randomBeaconName) }) }) From 6feb8e13ad59d7fde4f91bfbae1440d912f92db0 Mon Sep 17 00:00:00 2001 From: Kamil Pyszkowski Date: Thu, 12 Oct 2023 12:03:47 +0200 Subject: [PATCH 13/14] Add test for fallback app label if address is unexpected --- src/utils/__tests__/getStakingAppLabel.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/utils/__tests__/getStakingAppLabel.test.ts b/src/utils/__tests__/getStakingAppLabel.test.ts index dabbd038a..8629a2bdc 100644 --- a/src/utils/__tests__/getStakingAppLabel.test.ts +++ b/src/utils/__tests__/getStakingAppLabel.test.ts @@ -47,4 +47,10 @@ describe("Staking app label utils tests", () => { expect(resultTbtcName).toBe(tbtcName) expect(resultRandomBeaconName).toBe(randomBeaconName) }) + + it("returns fallback value if address is unexpected", () => { + const resultName = getStakingAppLabelFromAppAddress("0xun3xp3c73d400r3s5") + + expect(resultName).toBe("App") + }) }) From d8378ce48eaa77c6e1352698e6c1117417879d17 Mon Sep 17 00:00:00 2001 From: michalsmiarowski Date: Wed, 18 Oct 2023 13:17:35 +0200 Subject: [PATCH 14/14] Update T Token Dashboard version to v1.12.0-pre `v1.11.0` is live! --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 02854bdc0..fa263507d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "token-dashboard", - "version": "1.11.0-pre", + "version": "1.12.0-pre", "private": true, "dependencies": { "@chakra-ui/icons": "^1.0.15",