wip-account-creation #4

Merged
lash merged 143 commits from wip-account-creation into master 2024-08-30 14:37:58 +02:00
5 changed files with 61 additions and 7 deletions
Showing only changes of commit e4ebb02b77 - Show all commits

View File

@ -29,6 +29,7 @@ const (
const ( const (
createAccountURL = "https://custodial.sarafu.africa/api/account/create" createAccountURL = "https://custodial.sarafu.africa/api/account/create"
trackStatusURL = "https://custodial.sarafu.africa/api/track/" trackStatusURL = "https://custodial.sarafu.africa/api/track/"
checkBalanceURL = "https://custodial.sarafu.africa/api/account/status/"
) )
type accountResponse struct { type accountResponse struct {
@ -53,6 +54,14 @@ type trackStatusResponse struct {
} `json:"result"` } `json:"result"`
} }
type balanceResponse struct {
Ok bool `json:"ok"`
Result struct {
Balance string `json:"balance"`
Nonce json.Number `json:"nonce"`
} `json:"result"`
}
type fsData struct { type fsData struct {
path string path string
st *state.State st *state.State
@ -262,6 +271,45 @@ func (fsd *fsData) quit(ctx context.Context, sym string, input []byte) (resourc
return res, nil return res, nil
} }
func (fsd *fsData) checkBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{}
fp := fsd.path + "_data"
jsonData, err := os.ReadFile(fp)
if err != nil {
return res, err
Outdated
Review

this shouldnt switch on the input string; that requires manual syncing between here and the menu code.

how about using INCMP and the language switches on the sym instead?

Have a look at the lash/reuse-example go-vise branch, I've added an example that might illustrate.

this shouldnt switch on the input string; that requires manual syncing between here and the menu code. how about using INCMP and the language switches on the sym instead? Have a look at the `lash/reuse-example` go-vise branch, I've added an example that might illustrate.
Outdated
Review

priority

**priority**
Outdated
Review

I see this still isn't resolved.

I will make an issue of this, and mark it priority. We will handle it after merge.

I see this still isn't resolved. I will make an issue of this, and mark it priority. We will handle it after merge.
}
var accountData map[string]string
err = json.Unmarshal(jsonData, &accountData)
if err != nil {
return res, err
Alfred-mk marked this conversation as resolved Outdated
Outdated
Review

should error?

should error?
Outdated
Review

priority

**priority**

The switch only takes in two options, 0 or 1.
The menu remains on the select language node if an alternative input is provided

The switch only takes in two options, 0 or 1. The menu remains on the select language node if an alternative input is provided
}
resp, err := http.Get(checkBalanceURL + accountData["PublicKey"])
if err != nil {
return res, nil
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return res, nil
}
var balanceResp balanceResponse
err = json.Unmarshal(body, &balanceResp)
if err != nil {
return res, nil
}
balance := balanceResp.Result.Balance
res.Content = balance
return res, nil
}
var ( var (
scriptDir = path.Join("services", "registration") scriptDir = path.Join("services", "registration")
@ -327,6 +375,7 @@ func main() {
rfs.AddLocalFunc("check_account_status", fs.check_account_status) rfs.AddLocalFunc("check_account_status", fs.check_account_status)
rfs.AddLocalFunc("unlock_account", fs.unlock) rfs.AddLocalFunc("unlock_account", fs.unlock)
rfs.AddLocalFunc("quit",fs.quit) rfs.AddLocalFunc("quit",fs.quit)
rfs.AddLocalFunc("check_balance", fs.checkBalance)
cont, err := en.Init(ctx) cont, err := en.Init(ctx)
if err != nil { if err != nil {

@ -1 +1 @@
Subproject commit ef9a4c3073e7e878846693d4aa7fd0cf1cc977a7 Subproject commit 1f47a674d95380be8c387f410f0342eb72357df5

View File

@ -1,2 +1 @@
Balance: 0.00 SRF Balance: {{.check_balance}}

View File

@ -1,9 +1,15 @@
LOAD check_identifier 64 LOAD check_balance 64
RELOAD check_identifier RELOAD check_balance
MAP check_identifier MAP check_balance
MOUT send 1 MOUT send 1
MOUT vouchers 2 MOUT vouchers 2
MOUT account 3 MOUT account 3
MOUT help 4 MOUT help 4
MOUT quit 9
HALT HALT
INCMP send 1
INCMP vouchers 2
INCMP my_account 3 INCMP my_account 3
INCMP help 4
Alfred-mk marked this conversation as resolved Outdated
Outdated
Review

not implemented, and state gets stuck if its chosen. At a minimum please add an immediate quit in such cases.

not implemented, and state gets stuck if its chosen. At a minimum please add an immediate quit in such cases.
INCMP quit 9
INCMP . *

View File

@ -1 +1 @@
Salio: 0.00 SRF Salio: {{.check_balance}}