Skip to content

Commit

Permalink
fix: also call the api if sending from eoa (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
sander2 authored and danielsimao committed Aug 6, 2024
1 parent 39e0e4b commit d1bcbee
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions apps/bob-pay/src/pages/Send/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,42 @@ const Send = (): JSX.Element => {
recipient: string;
currencyAmount: CurrencyAmount<Ether | ERC20Token>;
}) => {
const { recipientAddress } = await getAddressData(recipient);
const { isAddress: isRecipientAddress, recipientAddress } = await getAddressData(recipient);

let txid;

if (currencyAmount.currency.isNative) {
return sendTransactionAsync({
txid = await sendTransactionAsync({
to: recipientAddress,
value: currencyAmount.numerator
});
} else {
txid = await writeTransferErc20Async({
address: (currencyAmount.currency as Token).address,
abi: erc20Abi,
functionName: 'transfer',
args: [recipientAddress, currencyAmount.numerator]
});
}

return writeTransferErc20Async({
address: (currencyAmount.currency as Token).address,
abi: erc20Abi,
functionName: 'transfer',
args: [recipientAddress, currencyAmount.numerator]
// Record the tx in the db so that we can check for intract whether someone has sent to an email.
// The same data could be used to provide a better tx history to the user, where we can show the
// destination email address rather than the evm address.
fetch('/api/bob-pay-insert-transaction', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify({
receiverEmail: isRecipientAddress ? '' : recipient, // for now, also submit when transferring to evm address
sender: address,
receiver: recipientAddress,
userOperationHash: txid
})
});

return txid;
}
});

Expand Down

0 comments on commit d1bcbee

Please sign in to comment.