Skip to content

Commit

Permalink
feat: Provision mainnet account for customers on account bootstrap [D…
Browse files Browse the repository at this point in the history
…EV-4203] (#567)

* feat: Provision mainnet account for customers on account bootstrap

Signed-off-by: jay-dee7 <me@jsdp.dev>

* refactor: Split customer account provisioning to a method

Signed-off-by: jay-dee7 <me@jsdp.dev>

* fix: Convert the provisionCustomerAccount to static

Signed-off-by: jay-dee7 <me@jsdp.dev>

* fix: Include payment accounts in `GET Account` API

Signed-off-by: jay-dee7 <me@jsdp.dev>

* fix: Handle account provisioning on Account Create API

Signed-off-by: jay-dee7 <me@jsdp.dev>

* refactor: Update APIs referencing customer accounts

Signed-off-by: jay-dee7 <me@jsdp.dev>

* fix: Await on event submit calls and check before creating stripe customer

Signed-off-by: jay-dee7 <me@jsdp.dev>

* fix: Use null for missing accounts instead of undefined

Signed-off-by: jay-dee7 <me@jsdp.dev>

* fix: Fallback to empty string on missing addresses in get account

Signed-off-by: jay-dee7 <me@jsdp.dev>

---------

Signed-off-by: jay-dee7 <me@jsdp.dev>
  • Loading branch information
jay-dee7 authored Aug 6, 2024
1 parent 3968d87 commit 3ad0955
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 123 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,5 @@ cython_debug/
#.idea/

*.tar
*.prod
*.local
21 changes: 18 additions & 3 deletions src/controllers/admin/organisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { validate } from '../validator/decorator.js';
import { CustomerService } from '../../services/api/customer.js';
import { StatusCodes } from 'http-status-codes';
import type {
AdminOrganisationGetResponseBody,
AdminOrganisationGetUnsuccessfulResponseBody,
AdminOrganisationUpdateResponseBody,
AdminOrganisationUpdateUnsuccessfulResponseBody,
} from '../../types/admin.js';
import { PaymentAccountService } from '../../services/api/payment-account.js';
import { CheqdNetwork } from '@cheqd/sdk';

dotenv.config();

Expand Down Expand Up @@ -79,11 +81,17 @@ export class OrganisationController {
} satisfies AdminOrganisationUpdateUnsuccessfulResponseBody);
}

const testnetAddress = paymentAccount.find((acc) => acc.namespace === CheqdNetwork.Testnet)?.address;
const mainnetAddress = paymentAccount.find((acc) => acc.namespace === CheqdNetwork.Mainnet)?.address;

return response.status(StatusCodes.OK).json({
name: customer.name,
email: customer.email,
description: customer.description,
cosmosAddress: paymentAccount[0].address as string,
cosmosAddress: {
[CheqdNetwork.Testnet]: testnetAddress ?? null,
[CheqdNetwork.Mainnet]: mainnetAddress ?? null,
},
} satisfies AdminOrganisationUpdateResponseBody);
} catch (error) {
return response.status(500).json({
Expand Down Expand Up @@ -126,12 +134,19 @@ export class OrganisationController {
error: 'Customer for current user was not found or did not setup properly. Please contact administrator.',
} satisfies AdminOrganisationGetUnsuccessfulResponseBody);
}

const testnetAddress = paymentAccount.find((acc) => acc.namespace === CheqdNetwork.Testnet)?.address;
const mainnetAddress = paymentAccount.find((acc) => acc.namespace === CheqdNetwork.Mainnet)?.address;

return response.status(StatusCodes.OK).json({
name: customer.name,
email: customer.email,
description: customer.description,
cosmosAddress: paymentAccount[0].address as string,
});
cosmosAddress: {
[CheqdNetwork.Testnet]: testnetAddress ?? null,
[CheqdNetwork.Mainnet]: mainnetAddress ?? null,
},
} satisfies AdminOrganisationGetResponseBody);
} catch (error) {
return response.status(500).json({
error: `Internal error: ${(error as Error)?.message || error}`,
Expand Down
Loading

0 comments on commit 3ad0955

Please sign in to comment.