-
Notifications
You must be signed in to change notification settings - Fork 13
Fix Daimo bugs #1132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix Daimo bugs #1132
Changes from 5 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
11ebdda
fix: bugs
Zishan-7 8416055
fix cross chain deposit details not correct
Zishan-7 2c06041
fix: request screen UI
Zishan-7 9982d47
add loading state
Zishan-7 c4af3cc
remove old daimo button
Zishan-7 27978d5
fix: missing dependencies and dead code
Zishan-7 3726f83
add try catch finally block
Zishan-7 b249bc4
remove clear Daimo errors inside the balance-check effect
Zishan-7 efe344c
fix copy
Zishan-7 fd31be6
minor fixes
Zishan-7 1333ae2
move ACTION_METHODS to constants file to remove circular dependency
Zishan-7 68ad69d
fix: circular dependency
Zishan-7 975396b
fix ts error
Zishan-7 99056f0
Merge remote-tracking branch 'origin/peanut-wallet-dev' into fix/daim…
Zishan-7 e1de3d4
update daimo version
Zishan-7 29b32b6
Merge remote-tracking branch 'origin/peanut-wallet-dev' into fix/daim…
Zishan-7 c649132
Merge remote-tracking branch 'origin/peanut-wallet-dev' into fix/daim…
Zishan-7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Zishan-7 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import React, { useCallback } from 'react' | ||
import { SearchResultCard } from '../SearchUsers/SearchResultCard' | ||
import { ACTION_METHODS } from './ActionList' | ||
import IconStack from '../Global/IconStack' | ||
import { useAppDispatch, usePaymentStore } from '@/redux/hooks' | ||
import { paymentActions } from '@/redux/slices/payment-slice' | ||
import { useCurrency } from '@/hooks/useCurrency' | ||
import { useSearchParams } from 'next/navigation' | ||
import { InitiatePaymentPayload, usePaymentInitiator } from '@/hooks/usePaymentInitiator' | ||
import DaimoPayButton from '../Global/DaimoPayButton' | ||
|
||
const ActionListDaimoPayButton = () => { | ||
const dispatch = useAppDispatch() | ||
const searchParams = useSearchParams() | ||
const method = ACTION_METHODS.find((method) => method.id === 'exchange-or-wallet') | ||
const { requestDetails, chargeDetails, attachmentOptions, parsedPaymentData, usdAmount } = usePaymentStore() | ||
const { | ||
code: currencyCode, | ||
symbol: currencySymbol, | ||
price: currencyPrice, | ||
} = useCurrency(searchParams.get('currency')) | ||
const requestId = searchParams.get('id') | ||
|
||
const { isProcessing, setLoadingStep, initiateDaimoPayment, completeDaimoPayment } = usePaymentInitiator() | ||
|
||
const handleInitiateDaimoPayment = useCallback(async () => { | ||
if (!usdAmount || parseFloat(usdAmount) <= 0) { | ||
console.error('Invalid amount entered') | ||
Zishan-7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return false | ||
} | ||
|
||
if (!parsedPaymentData) { | ||
console.error('Invalid payment data') | ||
dispatch(paymentActions.setError('Something went wrong. Please try again.')) | ||
return false | ||
} | ||
|
||
dispatch(paymentActions.setError(null)) | ||
dispatch(paymentActions.setDaimoError(null)) | ||
let tokenAmount = usdAmount | ||
|
||
setLoadingStep('Creating Charge') | ||
|
||
const payload: InitiatePaymentPayload = { | ||
recipient: parsedPaymentData?.recipient, | ||
tokenAmount, | ||
isPintaReq: false, // explicitly set to false for non-PINTA requests | ||
Zishan-7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
requestId: requestId ?? undefined, | ||
chargeId: chargeDetails?.uuid, | ||
currency: currencyCode | ||
? { | ||
code: currencyCode, | ||
symbol: currencySymbol!, | ||
price: currencyPrice!, | ||
} | ||
: undefined, | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
currencyAmount: usdAmount, | ||
isExternalWalletFlow: false, | ||
transactionType: 'DIRECT_SEND', | ||
attachmentOptions: attachmentOptions, | ||
} | ||
|
||
console.log('Initiating Daimo payment', payload) | ||
|
||
const result = await initiateDaimoPayment(payload) | ||
|
||
if (result.status === 'Charge Created') { | ||
console.log('Charge created!!') | ||
return true | ||
} else if (result.status === 'Error') { | ||
dispatch(paymentActions.setError('Something went wrong. Please try again.')) | ||
console.error('Payment initiation failed:', result) | ||
return false | ||
} else { | ||
console.warn('Unexpected status from usePaymentInitiator:', result.status) | ||
dispatch(paymentActions.setError('Something went wrong. Please try again.')) | ||
return false | ||
} | ||
}, [ | ||
usdAmount, | ||
dispatch, | ||
chargeDetails, | ||
requestDetails, | ||
requestId, | ||
parsedPaymentData, | ||
attachmentOptions, | ||
initiateDaimoPayment, | ||
]) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const handleCompleteDaimoPayment = useCallback( | ||
async (daimoPaymentResponse: any) => { | ||
dispatch(paymentActions.setIsDaimoPaymentProcessing(true)) | ||
if (chargeDetails) { | ||
setLoadingStep('Confirming Transaction') | ||
const result = await completeDaimoPayment({ | ||
chargeDetails: chargeDetails, | ||
txHash: daimoPaymentResponse.txHash as string, | ||
sourceChainId: daimoPaymentResponse.payment.source.chainId, | ||
payerAddress: daimoPaymentResponse.payment.source.payerAddress, | ||
}) | ||
|
||
if (result.status === 'Success') { | ||
dispatch(paymentActions.setView('STATUS')) | ||
} else if (result.status === 'Charge Created') { | ||
dispatch(paymentActions.setView('CONFIRM')) | ||
} else if (result.status === 'Error') { | ||
console.error('Payment initiation failed:', result.error) | ||
} else { | ||
console.warn('Unexpected status from usePaymentInitiator:', result.status) | ||
} | ||
setLoadingStep('Success') | ||
dispatch(paymentActions.setIsDaimoPaymentProcessing(false)) | ||
} | ||
}, | ||
[chargeDetails, completeDaimoPayment, dispatch] | ||
) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (!method || !parsedPaymentData) return null | ||
|
||
return ( | ||
<DaimoPayButton | ||
amount={usdAmount ?? '0.10'} | ||
toAddress={parsedPaymentData.recipient.resolvedAddress} | ||
onPaymentCompleted={handleCompleteDaimoPayment} | ||
onBeforeShow={handleInitiateDaimoPayment} | ||
disabled={!usdAmount} | ||
minAmount={0.1} | ||
maxAmount={4000} | ||
loading={isProcessing} | ||
onClose={() => setLoadingStep('Idle')} | ||
onValidationError={(error) => { | ||
dispatch(paymentActions.setDaimoError(error)) | ||
}} | ||
> | ||
{({ onClick, loading }) => ( | ||
<SearchResultCard | ||
isDisabled={loading || isProcessing} | ||
position="single" | ||
description={method.description} | ||
descriptionClassName="text-[12px]" | ||
title={method.title} | ||
onClick={onClick} | ||
rightContent={<IconStack icons={method.icons} iconSize={24} />} | ||
/> | ||
)} | ||
</DaimoPayButton> | ||
) | ||
} | ||
|
||
export default ActionListDaimoPayButton |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.