Skip to content

Commit

Permalink
feat: integrate core/credit (#1489)
Browse files Browse the repository at this point in the history
* chore: remove dependency on accounting_init

* feat: introduce DisbursalCreditAccountId

* wip: integrate core/credit

* chore: complete integration of core/credit

* chore: bring in changes from app/credit_facility

* chore: disbursal credit account id type is LedgerAccountId

* chore: sumsub_enabled config for Credit

* chore: add disbursalCreditAccountId in CreateCreditFacilityDialog

* chore: sumsub_enabled -> customer_active_check_enabled

* chore: CustomerNotFound error

* chore: remove find_deposit_account_by_holder_id fn

---------

Co-authored-by: siddharth <siddharthtiwarikreplind@gmail.com>
  • Loading branch information
thevaibhav-dixit and siddhart1o1 authored Feb 25, 2025
1 parent 70a7a0f commit 6131b82
Show file tree
Hide file tree
Showing 40 changed files with 297 additions and 356 deletions.
82 changes: 41 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/admin-panel/app/command-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ const CommandMenu = () => {
openCreateCreditFacilityDialog={createFacility}
setOpenCreateCreditFacilityDialog={() => setCreateFacility(false)}
customerId={customer.customerId}
disbursalCreditAccountId={customer.depositAccount.depositAccountId}
/>
</>
)}
Expand Down
1 change: 1 addition & 0 deletions apps/admin-panel/app/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ const CreateButton = () => {
setCreateFacility(false)
}}
customerId={customer.customerId}
disbursalCreditAccountId={customer.depositAccount.depositAccountId}
/>
</>
)}
Expand Down
3 changes: 3 additions & 0 deletions apps/admin-panel/app/credit-facilities/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type CreateCreditFacilityDialogProps = {
setOpenCreateCreditFacilityDialog: (isOpen: boolean) => void
openCreateCreditFacilityDialog: boolean
customerId: string
disbursalCreditAccountId: string
}

const initialFormValues = {
Expand All @@ -95,6 +96,7 @@ export const CreateCreditFacilityDialog: React.FC<CreateCreditFacilityDialogProp
setOpenCreateCreditFacilityDialog,
openCreateCreditFacilityDialog,
customerId,
disbursalCreditAccountId,
}) => {
const { navigate, isNavigating } = useModalNavigation({
closeModal: () => setOpenCreateCreditFacilityDialog(false),
Expand Down Expand Up @@ -215,6 +217,7 @@ export const CreateCreditFacilityDialog: React.FC<CreateCreditFacilityDialogProp
await createCreditFacility({
variables: {
input: {
disbursalCreditAccountId,
customerId,
facility: currencyConverter.usdToCents(Number(facility)),
terms: {
Expand Down
1 change: 1 addition & 0 deletions apps/admin-panel/lib/graphql/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ export type CreditFacilityConnection = {

export type CreditFacilityCreateInput = {
customerId: Scalars['UUID']['input'];
disbursalCreditAccountId: Scalars['UUID']['input'];
facility: Scalars['UsdCents']['input'];
terms: TermsInput;
};
Expand Down
1 change: 1 addition & 0 deletions apps/admin-panel/lib/graphql/generated/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ export const mockCreditFacilityCreateInput = (overrides?: Partial<CreditFacility
relationshipsToOmit.add('CreditFacilityCreateInput');
return {
customerId: overrides && overrides.hasOwnProperty('customerId') ? overrides.customerId! : generateMockValue.uuid(),
disbursalCreditAccountId: overrides && overrides.hasOwnProperty('disbursalCreditAccountId') ? overrides.disbursalCreditAccountId! : generateMockValue.uuid(),
facility: overrides && overrides.hasOwnProperty('facility') ? overrides.facility! : generateMockValue.usdCents(),
terms: overrides && overrides.hasOwnProperty('terms') ? overrides.terms! : relationshipsToOmit.has('TermsInput') ? {} as TermsInput : mockTermsInput({}, relationshipsToOmit),
};
Expand Down
34 changes: 31 additions & 3 deletions bats/credit-facility.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ teardown_file() {
cp "$LOG_FILE" "$PERSISTED_LOG_FILE"
}

wait_for_customer_activation() {
customer_id=$1

variables=$(
jq -n \
--arg customerId "$customer_id" \
'{ id: $customerId }'
)
exec_admin_graphql 'customer' "$variables"

status=$(graphql_output '.data.customer.status')
[[ "$status" == "ACTIVE" ]] || exit 1

}

wait_for_active() {
credit_facility_id=$1

Expand Down Expand Up @@ -80,15 +95,31 @@ ymd() {
# Setup prerequisites
customer_id=$(create_customer)

# retry 10 1 wait_for_customer_activation "$customer_id"

variables=$(
jq -n \
--arg customerId "$customer_id" \
'{
id: $customerId
}'
)
exec_admin_graphql 'customer' "$variables"

deposit_account_id=$(graphql_output '.data.customer.depositAccount.depositAccountId')
[[ "$deposit_account_id" != "null" ]] || exit 1

facility=100000
variables=$(
jq -n \
--arg customerId "$customer_id" \
--arg disbursal_credit_account_id "$deposit_account_id" \
--argjson facility "$facility" \
'{
input: {
customerId: $customerId,
facility: $facility,
disbursalCreditAccountId: $disbursal_credit_account_id,
terms: {
annualRate: "12",
accrualInterval: "END_OF_MONTH",
Expand All @@ -112,7 +143,6 @@ ymd() {

@test "credit-facility: can update collateral" {
credit_facility_id=$(read_value 'credit_facility_id')
echo "credit_facility_id: $credit_facility_id"

variables=$(
jq -n \
Expand All @@ -125,7 +155,6 @@ ymd() {
}'
)
exec_admin_graphql 'credit-facility-collateral-update' "$variables"
echo $(graphql_output)
credit_facility_id=$(graphql_output '.data.creditFacilityCollateralUpdate.creditFacility.creditFacilityId')
[[ "$credit_facility_id" != "null" ]] || exit 1

Expand All @@ -148,7 +177,6 @@ ymd() {
}'
)
exec_admin_graphql 'credit-facility-disbursal-initiate' "$variables"
echo $(graphql_output)
disbursal_index=$(graphql_output '.data.creditFacilityDisbursalInitiate.disbursal.index')
[[ "$disbursal_index" != "null" ]] || exit 1

Expand Down
2 changes: 2 additions & 0 deletions bats/lana-sim-time.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ app:
report:
dbt_output_dataset: "dbt_gha"
dev_disable_auto_create: true
credit_facility:
customer_active_check_enabled: false
time:
realtime: false
sim_time:
Expand Down
2 changes: 2 additions & 0 deletions bats/lana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ app:
root_folder: "gha"
report:
dbt_output_dataset: "dbt_gha"
credit_facility:
customer_active_check_enabled: false
2 changes: 1 addition & 1 deletion core/credit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "credit"
name = "core-credit"
version = "0.3.114-dev"
edition = "2021"

Expand Down
7 changes: 7 additions & 0 deletions core/credit/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@ use crate::terms::CVLPct;
pub struct CreditFacilityConfig {
#[serde(default = "default_upgrade_buffer_cvl_pct")]
pub upgrade_buffer_cvl_pct: CVLPct,
#[serde(default = "default_customer_active_check_enabled")]
pub customer_active_check_enabled: bool,
}

impl Default for CreditFacilityConfig {
fn default() -> Self {
CreditFacilityConfig {
upgrade_buffer_cvl_pct: default_upgrade_buffer_cvl_pct(),
customer_active_check_enabled: true,
}
}
}

fn default_upgrade_buffer_cvl_pct() -> CVLPct {
CVLPct::new(5)
}

fn default_customer_active_check_enabled() -> bool {
true
}
Loading

0 comments on commit 6131b82

Please sign in to comment.