ArboreumDev / credit-union-frontend

Frontend in Next.js + Typescript + GraphQL
https://frontend-two-sandy.vercel.app
1 stars 0 forks source link

Bug #179

Closed gparuthi closed 3 years ago

gparuthi commented 3 years ago

In #170, I get an error when making one of the last repayments of amount 7693. This is the next payment amount, shown in image below in comment.

Error:

{
  status: 'error',
  message: 'The server responded with an unexpected status.',
  data: {
    detail: 'user ca71626b-3071-4bc3-93a7-ec28e905a369 wants to spend 7692.596309800683 on repay on loan 49cd3b42-ec33-4d32-8c0c-2014560926cc but only has 4988.0 in their account.'
  }
}

To recreate:

Scenario:

{
    "users": [
        {
            "name": "a b",
            "email": "amitabh@mail.com",
            "user_type": "borrower",
            "demographic_info": {
                "income": 300,
                "credit_score": 600,
                "education_years": 3
            }
        },
        {
            "name": "d p",
            "email": "deepika@mail.com",
            "user_type": "lender",
            "demographic_info": {
                "income": 300,
                "credit_score": 600,
                "education_years": 3
            }
        },
        {
            "name": "s k",
            "email": "salman@mail.com",
            "user_type": "lender",
            "demographic_info": {}
        }
    ],
    "actions": [
        {
            "id": 1,
            "action_type": "ADJUST_BALANCES",
            "payload": {
                "userEmail": "salman@mail.com",
                "balanceDelta": "20000"
            }
        },
        {
            "id": 2,
            "action_type": "ADJUST_BALANCES",
            "payload": {
                "userEmail": "deepika@mail.com",
                "balanceDelta": "150000"
            }
        },
        {
            "id": 3,
            "action_type": "CONFIRM_LOAN",
            "payload": {
                "amount": 50000,
                "loan_id": "49cd3b42-ec33-4d32-8c0c-2014560926cc",
                "userEmail": "amitabh@mail.com",
                "supporters": [
                    {
                        "email": "salman@mail.com",
                        "pledge_amount": 10000
                    }
                ]
            }
        },
        {
            "id": 4,
            "action_type": "REPAY_LOAN",
            "payload": {
                "amount": "5800",
                "loan_id": "49cd3b42-ec33-4d32-8c0c-2014560926cc",
                "userEmail": "amitabh@mail.com"
            }
        },
        {
            "id": 5,
            "action_type": "REPAY_LOAN",
            "payload": {
                "amount": "8800",
                "loan_id": "49cd3b42-ec33-4d32-8c0c-2014560926cc",
                "userEmail": "amitabh@mail.com"
            }
        },
        {
            "id": 6,
            "action_type": "REPAY_LOAN",
            "payload": {
                "amount": "10000",
                "loan_id": "49cd3b42-ec33-4d32-8c0c-2014560926cc",
                "userEmail": "amitabh@mail.com"
            }
        },
        {
            "id": 7,
            "action_type": "REPAY_LOAN",
            "payload": {
                "amount": "10000",
                "loan_id": "49cd3b42-ec33-4d32-8c0c-2014560926cc",
                "userEmail": "amitabh@mail.com"
            }
        },
        {
            "id": 8,
            "action_type": "REPAY_LOAN",
            "payload": {
                "amount": "10412",
                "loan_id": "49cd3b42-ec33-4d32-8c0c-2014560926cc",
                "userEmail": "amitabh@mail.com"
            }
        }
    ]
}
gparuthi commented 3 years ago

image

gparuthi commented 3 years ago

SwarmAI request: https://gist.github.com/gparuthi/05dfc21e60831ef79b054ee4ac05bb61

djudjuu commented 3 years ago

that is actually expected. the borrower doesnt have enough funds, because they need to payback the loan + interest. so as the last payment crosses over 50k it fails.

when I adjusted the borrower balance it worked. I like how straightforward it was for me to investigate this. especially the swarmai-request was helpful