Skip to content

Commit

Permalink
Feat: Create liquidation address when updating account if currency ch…
Browse files Browse the repository at this point in the history
…anged
  • Loading branch information
jakubcolony committed Aug 1, 2024
1 parent 1c1dd10 commit 722b1bd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const checkKYCHandler = async (
if (!firstAccount) {
return {
kycStatus,
kyc_link: kycLink,
kycLink,
bankAccount: null,
};
}
Expand Down Expand Up @@ -193,7 +193,7 @@ const checkKYCHandler = async (

return {
kycStatus,
kyc_link: kycLink,
kycLink,
bankAccount: mappedAccount,
liquidationAddress: externalAccountLiquidationAddress,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ const updateExternalAccountHandler = async (
);

if (deleteAccountRes.status !== 200) {
console.error(await deleteAccountRes.json());
throw Error('Error deleting external account');
throw Error(
`Error deleting external account: ${await deleteAccountRes.text()}`,
);
}

const newAccount = await createExternalAccount(
Expand Down Expand Up @@ -85,8 +86,35 @@ const updateExternalAccountHandler = async (
);

if (updateAddressRes.status !== 200) {
console.error(await updateAddressRes.json());
throw Error('Error updating liquidation address');
throw Error(
`Error updating liquidation address: ${await updateAddressRes.text()}`,
);
}
} else {
const createAddressRes = await fetch(
`${apiUrl}/v0/customers/${bridgeCustomerId}/liquidation_addresses`,
{
headers: {
'Content-Type': 'application/json',
'Idempotency-Key': newAccount.id,
'Api-Key': apiKey,
},
method: 'POST',
body: JSON.stringify({
chain: 'arbitrum',
currency: 'usdc',
external_account_id: newAccount.id,
destination_payment_rail:
newAccount.currency === 'usd' ? 'ach' : 'sepa',
destination_currency: newAccount.currency,
}),
},
);

if (createAddressRes.status !== 201) {
throw Error(
`Error creating liquidation address: ${await createAddressRes.text()}`,
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions amplify/backend/function/bridgeXYZMutation/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const isDev = process.env.ENV === 'dev';

let graphqlURL = 'http://localhost:20002/graphql';
let appSyncApiKey = 'da2-fakeApiId123456';
let apiUrl = 'https://api.bridge.xyz';
let apiKey = 'sk-live-47c8b97f6d9f7e4d1c13e6a541d49b98';
let apiUrl = 'https://api.sandbox.bridge.xyz';
let apiKey = 'xx';

const setEnvVariables = async () => {
if (!isDev) {
Expand Down

0 comments on commit 722b1bd

Please sign in to comment.