From d8fd6e31fd55b1053f8b9e0a56e07173ebf06108 Mon Sep 17 00:00:00 2001 From: Jakub Zajac Date: Mon, 30 Sep 2024 21:44:10 +0100 Subject: [PATCH 1/3] Fix: getDrainsHistory handler crashing when receipt is null --- amplify/backend/api/colonycdapp/schema/bridge.graphql | 2 +- .../bridgeXYZMutation/src/handlers/getDrainsHistory.js | 8 +++++--- .../partials/FiatTransfersTable/hooks.tsx | 5 +++++ src/graphql/generated.ts | 6 +++--- src/i18n/en.json | 1 + 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/amplify/backend/api/colonycdapp/schema/bridge.graphql b/amplify/backend/api/colonycdapp/schema/bridge.graphql index de7f8ce1127..315e16399c3 100644 --- a/amplify/backend/api/colonycdapp/schema/bridge.graphql +++ b/amplify/backend/api/colonycdapp/schema/bridge.graphql @@ -30,7 +30,7 @@ type BridgeDrain { currency: String! state: String! createdAt: String! - receipt: BridgeDrainReceipt! + receipt: BridgeDrainReceipt } type BridgeIbanBankAccount { diff --git a/amplify/backend/function/bridgeXYZMutation/src/handlers/getDrainsHistory.js b/amplify/backend/function/bridgeXYZMutation/src/handlers/getDrainsHistory.js index 3bb672ce016..f9bc1cc80ee 100644 --- a/amplify/backend/function/bridgeXYZMutation/src/handlers/getDrainsHistory.js +++ b/amplify/backend/function/bridgeXYZMutation/src/handlers/getDrainsHistory.js @@ -68,9 +68,11 @@ const getDrainsHistoryHandler = async ( currency: drain.currency, state: drain.state, createdAt: drain.created_at, - receipt: { - url: drain.receipt.url, - }, + receipt: drain.receipt + ? { + url: drain.receipt.url, + } + : null, })); drains.push(...mappedDrains); diff --git a/src/components/frame/v5/pages/UserCryptoToFiatPage/partials/FiatTransfersTable/hooks.tsx b/src/components/frame/v5/pages/UserCryptoToFiatPage/partials/FiatTransfersTable/hooks.tsx index 481ba1ac9e7..e80f43869cf 100644 --- a/src/components/frame/v5/pages/UserCryptoToFiatPage/partials/FiatTransfersTable/hooks.tsx +++ b/src/components/frame/v5/pages/UserCryptoToFiatPage/partials/FiatTransfersTable/hooks.tsx @@ -133,6 +133,11 @@ export const useFiatTransfersTableColumns = ( if (loading) { return
; } + + if (!row.original.receipt) { + return formatText({ id: 'table.content.receiptNotAvailable' }); + } + return ( ; state: Scalars['String']; }; @@ -9679,7 +9679,7 @@ export type ColonyMultiSigFragment = { __typename?: 'ColonyMultiSig', id: string export type BridgeBankAccountFragment = { __typename?: 'BridgeBankAccount', id: string, currency: string, bankName: string, accountOwner: string, iban?: { __typename?: 'BridgeIbanBankAccount', bic: string, country: string, last4: string } | null, usAccount?: { __typename?: 'BridgeUsBankAccount', last4: string, routingNumber: string } | null }; -export type BridgeDrainFragment = { __typename?: 'BridgeDrain', id: string, amount: string, currency: string, state: string, createdAt: string, receipt: { __typename?: 'BridgeDrainReceipt', url: string } }; +export type BridgeDrainFragment = { __typename?: 'BridgeDrain', id: string, amount: string, currency: string, state: string, createdAt: string, receipt?: { __typename?: 'BridgeDrainReceipt', url: string } | null }; export type ColonyFragment = { __typename?: 'Colony', name: string, version: number, reputation?: string | null, expendituresGlobalClaimDelay?: string | null, private?: boolean | null, lastUpdatedContributorsWithReputation?: string | null, colonyAddress: string, nativeToken: { __typename?: 'Token', decimals: number, name: string, symbol: string, type?: TokenType | null, avatar?: string | null, thumbnail?: string | null, tokenAddress: string }, status?: { __typename?: 'ColonyStatus', recovery?: boolean | null, nativeToken?: { __typename?: 'NativeTokenStatus', mintable?: boolean | null, unlockable?: boolean | null, unlocked?: boolean | null } | null } | null, chainMetadata: { __typename?: 'ChainMetadata', chainId: string, network?: Network | null }, tokens?: { __typename?: 'ModelColonyTokensConnection', items: Array<{ __typename?: 'ColonyTokens', colonyTokensId: string, token: { __typename?: 'Token', decimals: number, name: string, symbol: string, type?: TokenType | null, avatar?: string | null, thumbnail?: string | null, tokenAddress: string } } | null> } | null, motionsWithUnclaimedStakes?: Array<{ __typename?: 'ColonyUnclaimedStake', motionId: string, unclaimedRewards: Array<{ __typename?: 'StakerRewards', address: string, rewards: { __typename?: 'MotionStakeValues', nay: string, yay: string } }> }> | null, domains?: { __typename?: 'ModelDomainConnection', items: Array<{ __typename?: 'Domain', id: string, nativeId: number, isRoot: boolean, nativeFundingPotId: number, nativeSkillId: string, reputation?: string | null, reputationPercentage?: string | null, metadata?: { __typename?: 'DomainMetadata', name: string, color: DomainColor, description?: string | null, id: string, changelog?: Array<{ __typename?: 'DomainMetadataChangelog', transactionHash: string, oldName: string, newName: string, oldColor: DomainColor, newColor: DomainColor, oldDescription?: string | null, newDescription?: string | null }> | null } | null } | null> } | null, balances?: { __typename?: 'ColonyBalances', items?: Array<{ __typename?: 'ColonyBalance', id: string, balance: string, domain?: { __typename?: 'Domain', id: string, nativeId: number, isRoot: boolean, nativeFundingPotId: number, nativeSkillId: string, reputation?: string | null, reputationPercentage?: string | null, metadata?: { __typename?: 'DomainMetadata', name: string, color: DomainColor, description?: string | null, id: string, changelog?: Array<{ __typename?: 'DomainMetadataChangelog', transactionHash: string, oldName: string, newName: string, oldColor: DomainColor, newColor: DomainColor, oldDescription?: string | null, newDescription?: string | null }> | null } | null } | null, token: { __typename?: 'Token', decimals: number, name: string, symbol: string, type?: TokenType | null, avatar?: string | null, thumbnail?: string | null, tokenAddress: string } } | null> | null } | null, fundsClaims?: { __typename?: 'ModelColonyFundsClaimConnection', items: Array<{ __typename?: 'ColonyFundsClaim', id: string, createdAtBlock: number, createdAt: string, amount: string, isClaimed?: boolean | null, token: { __typename?: 'Token', decimals: number, name: string, symbol: string, type?: TokenType | null, avatar?: string | null, thumbnail?: string | null, tokenAddress: string } } | null> } | null, chainFundsClaim?: { __typename?: 'ColonyChainFundsClaim', id: string, createdAtBlock: number, createdAt: string, amount: string, isClaimed?: boolean | null } | null, metadata?: { __typename?: 'ColonyMetadata', displayName: string, avatar?: string | null, description?: string | null, thumbnail?: string | null, externalLinks?: Array<{ __typename?: 'ExternalLink', name: ExternalLinks, link: string }> | null, objective?: { __typename?: 'ColonyObjective', title: string, description: string, progress: number } | null, changelog?: Array<{ __typename?: 'ColonyMetadataChangelog', transactionHash: string, newDisplayName: string, oldDisplayName: string, hasAvatarChanged: boolean, hasDescriptionChanged?: boolean | null, haveExternalLinksChanged?: boolean | null, hasObjectiveChanged?: boolean | null, newSafes?: Array<{ __typename?: 'Safe', name: string, address: string, chainId: string, moduleContractAddress: string }> | null, oldSafes?: Array<{ __typename?: 'Safe', name: string, address: string, chainId: string, moduleContractAddress: string }> | null }> | null, safes?: Array<{ __typename?: 'Safe', name: string, address: string, chainId: string, moduleContractAddress: string }> | null } | null, roles?: { __typename?: 'ModelColonyRoleConnection', items: Array<{ __typename?: 'ColonyRole', id: string, targetAddress: string, role_0?: boolean | null, role_1?: boolean | null, role_2?: boolean | null, role_3?: boolean | null, role_5?: boolean | null, role_6?: boolean | null, isMultiSig?: boolean | null, domain: { __typename?: 'Domain', id: string, nativeId: number } } | null> } | null, colonyMemberInvite?: { __typename?: 'ColonyMemberInvite', id: string, invitesRemaining: number } | null }; @@ -10019,7 +10019,7 @@ export type SearchActionsQuery = { __typename?: 'Query', searchColonyActions?: { export type GetUserDrainsQueryVariables = Exact<{ [key: string]: never; }>; -export type GetUserDrainsQuery = { __typename?: 'Query', bridgeGetDrainsHistory?: Array<{ __typename?: 'BridgeDrain', id: string, amount: string, currency: string, state: string, createdAt: string, receipt: { __typename?: 'BridgeDrainReceipt', url: string } }> | null }; +export type GetUserDrainsQuery = { __typename?: 'Query', bridgeGetDrainsHistory?: Array<{ __typename?: 'BridgeDrain', id: string, amount: string, currency: string, state: string, createdAt: string, receipt?: { __typename?: 'BridgeDrainReceipt', url: string } | null }> | null }; export type CheckKycStatusQueryVariables = Exact<{ [key: string]: never; }>; diff --git a/src/i18n/en.json b/src/i18n/en.json index d2b3d026d15..dee12bff7e7 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -1446,6 +1446,7 @@ "table.row.asset": "Asset", "table.row.balance": "Balance", "table.content.viewReceipt": "View receipt", + "table.content.receiptNotAvailable": "Receipt not available", "user.not.verified.warning": "This member has not yet been verified. Ensure you know who this member and the address is correct.", "actionSidebar.distribution": "Distribution", "actionSidebar.distributionPlaceholder": "Select split type", From c2fb5b6f980bca42240626c244f81ca692269874 Mon Sep 17 00:00:00 2001 From: Jakub Zajac Date: Mon, 30 Sep 2024 22:46:43 +0100 Subject: [PATCH 2/3] Increase limit of get liquidation addresses request --- .../src/handlers/getDrainsHistory.js | 27 +++++-------------- .../bridgeXYZMutation/src/handlers/utils.js | 2 +- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/amplify/backend/function/bridgeXYZMutation/src/handlers/getDrainsHistory.js b/amplify/backend/function/bridgeXYZMutation/src/handlers/getDrainsHistory.js index f9bc1cc80ee..81600a26848 100644 --- a/amplify/backend/function/bridgeXYZMutation/src/handlers/getDrainsHistory.js +++ b/amplify/backend/function/bridgeXYZMutation/src/handlers/getDrainsHistory.js @@ -1,11 +1,7 @@ const fetch = require('cross-fetch'); const { graphqlRequest } = require('../utils'); -/* - * @TODO This needs to be imported properly into the project (maybe?) - * So that we can always ensure it follows the latest schema - * (currently it's just saved statically) - */ const { getUser } = require('../graphql'); +const { getLiquidationAddresses } = require('./utils'); const getDrainsHistoryHandler = async ( event, @@ -25,26 +21,17 @@ const getDrainsHistoryHandler = async ( const bridgeCustomerId = colonyUser?.bridgeCustomerId; - const res = await fetch( - `${apiUrl}/v0/customers/${bridgeCustomerId}/liquidation_addresses`, - { - headers: { - 'Content-Type': 'application/json', - 'Api-Key': apiKey, - }, - method: 'GET', - }, + const liquidationAddresses = await getLiquidationAddresses( + apiUrl, + apiKey, + bridgeCustomerId, ); - const liquidationAddressResult = await res.json(); - - if (!liquidationAddressResult.count) { + if (!liquidationAddresses.length) { return []; } - const liquidationAddressIds = liquidationAddressResult.data.map( - (item) => item.id, - ); + const liquidationAddressIds = liquidationAddresses.map((item) => item.id); const drains = []; diff --git a/amplify/backend/function/bridgeXYZMutation/src/handlers/utils.js b/amplify/backend/function/bridgeXYZMutation/src/handlers/utils.js index ddaee172c34..a3cb0826af5 100644 --- a/amplify/backend/function/bridgeXYZMutation/src/handlers/utils.js +++ b/amplify/backend/function/bridgeXYZMutation/src/handlers/utils.js @@ -45,7 +45,7 @@ const createExternalAccount = async ( const getLiquidationAddresses = async (apiUrl, apiKey, bridgeCustomerId) => { const liquidationAddressesRes = await fetch( - `${apiUrl}/v0/customers/${bridgeCustomerId}/liquidation_addresses`, + `${apiUrl}/v0/customers/${bridgeCustomerId}/liquidation_addresses?limit=100`, { headers: { 'Content-Type': 'application/json', From f6384b8f12202dbb6ac1c8c7e1786684476cd22b Mon Sep 17 00:00:00 2001 From: Jakub Zajac Date: Tue, 1 Oct 2024 13:03:35 +0100 Subject: [PATCH 3/3] Feat: Update table copy when no drain receipt available --- .../partials/FiatTransfersTable/hooks.tsx | 6 +++++- src/i18n/en.json | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/frame/v5/pages/UserCryptoToFiatPage/partials/FiatTransfersTable/hooks.tsx b/src/components/frame/v5/pages/UserCryptoToFiatPage/partials/FiatTransfersTable/hooks.tsx index e80f43869cf..c64d8b62729 100644 --- a/src/components/frame/v5/pages/UserCryptoToFiatPage/partials/FiatTransfersTable/hooks.tsx +++ b/src/components/frame/v5/pages/UserCryptoToFiatPage/partials/FiatTransfersTable/hooks.tsx @@ -135,7 +135,11 @@ export const useFiatTransfersTableColumns = ( } if (!row.original.receipt) { - return formatText({ id: 'table.content.receiptNotAvailable' }); + return ( +
+ {formatText({ id: 'table.content.receiptGenerating' })} +
+ ); } return ( diff --git a/src/i18n/en.json b/src/i18n/en.json index dee12bff7e7..f4e37362222 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -1446,7 +1446,7 @@ "table.row.asset": "Asset", "table.row.balance": "Balance", "table.content.viewReceipt": "View receipt", - "table.content.receiptNotAvailable": "Receipt not available", + "table.content.receiptGenerating": "Generating...", "user.not.verified.warning": "This member has not yet been verified. Ensure you know who this member and the address is correct.", "actionSidebar.distribution": "Distribution", "actionSidebar.distributionPlaceholder": "Select split type",