Merge remote-tracking branch 'refs/remotes/origin/wip-account-creation' into wip-account-creation

This commit is contained in:
Carlosokumu 2024-08-28 14:19:08 +03:00
commit 3501a79aea
Signed by: carlos
GPG Key ID: 7BD6BC8160A5C953
6 changed files with 47 additions and 1 deletions

View File

@ -101,6 +101,7 @@ func main() {
rfs.AddLocalFunc("reset_transaction_amount", ussdHandlers.ResetTransactionAmount) rfs.AddLocalFunc("reset_transaction_amount", ussdHandlers.ResetTransactionAmount)
rfs.AddLocalFunc("get_recipient", ussdHandlers.GetRecipient) rfs.AddLocalFunc("get_recipient", ussdHandlers.GetRecipient)
rfs.AddLocalFunc("get_sender", ussdHandlers.GetSender) rfs.AddLocalFunc("get_sender", ussdHandlers.GetSender)
rfs.AddLocalFunc("get_amount", ussdHandlers.GetAmount)
rfs.AddLocalFunc("reset_incorrect", ussdHandlers.ResetIncorrectPin) rfs.AddLocalFunc("reset_incorrect", ussdHandlers.ResetIncorrectPin)
rfs.AddLocalFunc("save_firstname", ussdHandlers.SaveFirstname) rfs.AddLocalFunc("save_firstname", ussdHandlers.SaveFirstname)
rfs.AddLocalFunc("save_familyname", ussdHandlers.SaveFamilyname) rfs.AddLocalFunc("save_familyname", ussdHandlers.SaveFamilyname)
@ -115,6 +116,7 @@ func main() {
rfs.AddLocalFunc("verify_yob", ussdHandlers.VerifyYob) rfs.AddLocalFunc("verify_yob", ussdHandlers.VerifyYob)
rfs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rfs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
rfs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rfs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
rfs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
cont, err := en.Init(ctx) cont, err := en.Init(ctx)
en.SetDebugger(engine.NewSimpleDebug(nil)) en.SetDebugger(engine.NewSimpleDebug(nil))

View File

@ -501,8 +501,9 @@ func (h *Handlers) TransactionReset(ctx context.Context, sym string, input []byt
return res, err return res, err
} }
// reset the recipient // reset the transaction
accountData["Recipient"] = "" accountData["Recipient"] = ""
accountData["Amount"] = ""
err = h.accountFileHandler.WriteAccountData(accountData) err = h.accountFileHandler.WriteAccountData(accountData)
if err != nil { if err != nil {
@ -669,6 +670,21 @@ func (h *Handlers) GetSender(ctx context.Context, sym string, input []byte) (res
return res, nil return res, nil
} }
// GetAmount retrieves the amount from a JSON data file.
func (h *Handlers) GetAmount(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{}
accountData, err := h.accountFileHandler.ReadAccountData()
if err != nil {
return res, err
}
res.Content = accountData["Amount"]
return res, nil
}
// QuickWithBalance retrieves the balance for a given public key from the custodial balance API endpoint before // QuickWithBalance retrieves the balance for a given public key from the custodial balance API endpoint before
// gracefully exiting the session. // gracefully exiting the session.
func (h *Handlers) QuitWithBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (h *Handlers) QuitWithBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) {
@ -686,3 +702,13 @@ func (h *Handlers) QuitWithBalance(ctx context.Context, sym string, input []byte
res.FlagReset = append(res.FlagReset, models.USERFLAG_ACCOUNT_UNLOCKED) res.FlagReset = append(res.FlagReset, models.USERFLAG_ACCOUNT_UNLOCKED)
return res, nil return res, nil
} }
func (h *Handlers) InitiateTransaction(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{}
// TODO
// Use the amount, recipient and sender to call the API and initialize the transaction
res.FlagReset = append(res.FlagReset, models.USERFLAG_ACCOUNT_UNLOCKED)
return res, nil
}

View File

@ -0,0 +1 @@
Your request has been sent. {{.get_recipient}} will receive {{.get_amount}} from {{.get_sender}}.

View File

@ -0,0 +1,12 @@
LOAD reset_incorrect 0
LOAD get_amount 10
MAP get_amount
RELOAD get_recipient
MAP get_recipient
RELOAD get_sender
MAP get_sender
LOAD initiate_transaction 0
RELOAD transaction_reset
MOUT quit 9
HALT
INCMP quit 9

View File

@ -0,0 +1 @@
Ombi lako limetumwa. {{.get_recipient}} atapokea {{.get_amount}} kutoka kwa {{.get_sender}}.

View File

@ -6,5 +6,9 @@ MAP get_sender
MOUT back 0 MOUT back 0
MOUT quit 9 MOUT quit 9
HALT HALT
LOAD unlock_account 1
RELOAD unlock_account
CATCH incorrect_pin 15 1
INCMP _ 0 INCMP _ 0
INCMP quit 9 INCMP quit 9
MOVE transaction_initiated