@@ -9,11 +9,20 @@ import (
9
9
10
10
type KYC interface {
11
11
MeetsRequirements (ctx context.Context , userId string , assetType string , cost float64 ) (met bool , err error )
12
- GetTransactionLevel (assetType string , cost float64 ) int
13
- GetUserLevel (ctx context.Context , userId string ) (level int , err error )
14
- UpdateUserLevel (ctx context.Context , userId string ) (level int , err error )
12
+ GetTransactionLevel (assetType string , cost float64 ) KYCLevel
13
+ GetUserLevel (ctx context.Context , userId string ) (level KYCLevel , err error )
14
+ UpdateUserLevel (ctx context.Context , userId string ) (level KYCLevel , err error )
15
15
}
16
16
17
+ type KYCLevel int
18
+
19
+ const (
20
+ Level0 KYCLevel = iota
21
+ Level1
22
+ Level2
23
+ Level3
24
+ )
25
+
17
26
type kyc struct {
18
27
repos repository.Repositories
19
28
}
@@ -36,25 +45,25 @@ func (k kyc) MeetsRequirements(ctx context.Context, userId string, assetType str
36
45
}
37
46
}
38
47
39
- func (k kyc ) GetTransactionLevel (assetType string , cost float64 ) int {
48
+ func (k kyc ) GetTransactionLevel (assetType string , cost float64 ) KYCLevel {
40
49
if assetType == "NFT" {
41
50
if cost < 1000.00 {
42
- return 1
51
+ return Level1
43
52
} else if cost < 5000.00 {
44
- return 2
53
+ return Level2
45
54
} else {
46
- return 3
55
+ return Level3
47
56
}
48
57
} else {
49
58
if cost < 5000.00 {
50
- return 2
59
+ return Level2
51
60
} else {
52
- return 3
61
+ return Level3
53
62
}
54
63
}
55
64
}
56
65
57
- func (k kyc ) GetUserLevel (ctx context.Context , userId string ) (level int , err error ) {
66
+ func (k kyc ) GetUserLevel (ctx context.Context , userId string ) (level KYCLevel , err error ) {
58
67
level , err = k .UpdateUserLevel (ctx , userId )
59
68
if err != nil {
60
69
return level , err
@@ -63,7 +72,7 @@ func (k kyc) GetUserLevel(ctx context.Context, userId string) (level int, err er
63
72
return level , nil
64
73
}
65
74
66
- func (k kyc ) UpdateUserLevel (ctx context.Context , userId string ) (level int , err error ) {
75
+ func (k kyc ) UpdateUserLevel (ctx context.Context , userId string ) (level KYCLevel , err error ) {
67
76
identity , err := k .repos .Identity .GetByUserId (ctx , userId )
68
77
if err != nil {
69
78
return level , err
@@ -84,19 +93,19 @@ func (k kyc) UpdateUserLevel(ctx context.Context, userId string) (level int, err
84
93
}
85
94
86
95
if points >= 4 {
87
- if identity .Level != 2 {
88
- identity .Level = 2
96
+ if identity .Level != int ( Level2 ) {
97
+ identity .Level = int ( Level2 )
89
98
k .repos .Identity .Update (ctx , userId , model.IdentityUpdates {Level : & identity .Level })
90
99
}
91
100
} else if points >= 1 && identity .EmailVerified != nil {
92
- if identity .Level != 1 {
93
- identity .Level = 1
101
+ if identity .Level != int ( Level1 ) {
102
+ identity .Level = int ( Level1 )
94
103
k .repos .Identity .Update (ctx , userId , model.IdentityUpdates {Level : & identity .Level })
95
104
}
96
- } else if points <= 1 && identity .Level != 0 {
97
- identity .Level = 0
105
+ } else if points <= 1 && identity .Level != int ( Level0 ) {
106
+ identity .Level = int ( Level0 )
98
107
k .repos .Identity .Update (ctx , userId , model.IdentityUpdates {Level : & identity .Level })
99
108
}
100
109
101
- return identity .Level , nil
110
+ return KYCLevel ( identity .Level ) , nil
102
111
}
0 commit comments