Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 44 additions & 10 deletions account/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"github.com/code-payments/flipcash2-server/auth"
"github.com/code-payments/flipcash2-server/database"
"github.com/code-payments/flipcash2-server/model"
"github.com/code-payments/flipcash2-server/rpc"

Check failure on line 22 in account/server.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/code-payments/flipcash2-server/rpc; to add it:

Check failure on line 22 in account/server.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/code-payments/flipcash2-server/rpc; to add it:

Check failure on line 22 in account/server.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/code-payments/flipcash2-server/rpc; to add it:

Check failure on line 22 in account/server.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/code-payments/flipcash2-server/rpc; to add it:

Check failure on line 22 in account/server.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/code-payments/flipcash2-server/rpc; to add it:

Check failure on line 22 in account/server.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/code-payments/flipcash2-server/rpc; to add it:

Check failure on line 22 in account/server.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/code-payments/flipcash2-server/rpc; to add it:

Check failure on line 22 in account/server.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/code-payments/flipcash2-server/rpc; to add it:

Check failure on line 22 in account/server.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/code-payments/flipcash2-server/rpc; to add it:

Check failure on line 22 in account/server.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/code-payments/flipcash2-server/rpc; to add it:
ocp_client "github.com/code-payments/ocp-server/grpc/client"
ocp_common "github.com/code-payments/ocp-server/ocp/common"
)

Expand All @@ -40,17 +42,34 @@
DefaultNewCurrencyFeeAmount = ocp_common.ToCoreMintQuarks(15)
)

type onRampProviderConfig struct {
Provider accountpb.UserFlags_OnRampProvider
// MinVersion, when non-nil, gates this provider behind a minimum client
// version. Clients on older versions (or without a parseable user-agent)
// will not have this provider included.
MinVersion *ocp_client.Version
}

var (
defaultOnRampProviders = []accountpb.UserFlags_OnRampProvider{
accountpb.UserFlags_PHANTOM,
accountpb.UserFlags_MANUAL_DEPOSIT,
}
onRampProvidersByCountryAndPlatform = map[string]map[commonpb.Platform][]accountpb.UserFlags_OnRampProvider{
/*"us": {
onRampProvidersByCountryAndPlatform = map[string]map[commonpb.Platform][]onRampProviderConfig{
"us": {
commonpb.Platform_APPLE: {
accountpb.UserFlags_COINBASE_VIRTUAL,
{
Provider: accountpb.UserFlags_COINBASE_VIRTUAL,
MinVersion: &ocp_client.Version{Major: 1, Minor: 6, Patch: 0},
},
},
},*/
/*commonpb.Platform_GOOGLE: {
{
Provider: accountpb.UserFlags_COINBASE_VIRTUAL,
MinVersion: &ocp_client.Version{Major: 0, Minor: 0, Patch: 0}, // todo
},
},*/
},
}

staffAppleOnRampProviders = []accountpb.UserFlags_OnRampProvider{
Expand Down Expand Up @@ -208,7 +227,7 @@
supportedOnRampProvidersForUser = staffGoogleOnRampProviders
}
} else {
supportedOnRampProvidersForUser = getSupportedOnRampProviders(req.CountryCode, req.Platform)
supportedOnRampProvidersForUser = getSupportedOnRampProviders(ctx, req.CountryCode, req.Platform)
}
if slices.Contains(supportedOnRampProvidersForUser, accountpb.UserFlags_COINBASE_VIRTUAL) {
preferredOnRampProviderForUser = accountpb.UserFlags_COINBASE_VIRTUAL
Expand Down Expand Up @@ -245,7 +264,7 @@
}

func (s *Server) GetUnauthenticatedUserFlags(ctx context.Context, req *accountpb.GetUnauthenticatedUserFlagsRequest) (*accountpb.GetUnauthenticatedUserFlagsResponse, error) {
supportedOnRampProvidersForUser := getSupportedOnRampProviders(req.CountryCode, req.Platform)
supportedOnRampProvidersForUser := getSupportedOnRampProviders(ctx, req.CountryCode, req.Platform)

var preferredOnRampProviderForUser accountpb.UserFlags_OnRampProvider
if slices.Contains(supportedOnRampProvidersForUser, accountpb.UserFlags_COINBASE_VIRTUAL) {
Expand Down Expand Up @@ -275,7 +294,7 @@
}, nil
}

func getSupportedOnRampProviders(countryCode *commonpb.CountryCode, platform commonpb.Platform) []accountpb.UserFlags_OnRampProvider {
func getSupportedOnRampProviders(ctx context.Context, countryCode *commonpb.CountryCode, platform commonpb.Platform) []accountpb.UserFlags_OnRampProvider {
defaultSupported := make([]accountpb.UserFlags_OnRampProvider, len(defaultOnRampProviders))
copy(defaultSupported, defaultOnRampProviders)

Expand All @@ -297,8 +316,23 @@
return defaultSupported
}

allSupported := make([]accountpb.UserFlags_OnRampProvider, len(byPlatform)+len(defaultSupported))
copy(allSupported, byPlatform) // Country and platform specific providers take priority
copy(allSupported[len(byPlatform):], defaultSupported) // Followed by default global providers
var clientVersion *ocp_client.Version
if userAgent, err := ocp_client.GetUserAgent(ctx, rpc.UserAgentName); err == nil {
clientVersion = &userAgent.Version
}

filtered := make([]accountpb.UserFlags_OnRampProvider, 0, len(byPlatform))
for _, entry := range byPlatform {
if entry.MinVersion != nil {
if clientVersion == nil || clientVersion.Before(entry.MinVersion) {
continue
}
}
filtered = append(filtered, entry.Provider)
}

allSupported := make([]accountpb.UserFlags_OnRampProvider, 0, len(filtered)+len(defaultSupported))
allSupported = append(allSupported, filtered...) // Country and platform specific providers take priority
allSupported = append(allSupported, defaultSupported...) // Followed by default global providers
return allSupported
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/ReneKroon/ttlcache v1.7.0
github.com/code-payments/flipcash2-protobuf-api v1.3.1-0.20260420185108-1e0abce29a0a
github.com/code-payments/ocp-protobuf-api v1.9.0
github.com/code-payments/ocp-server v1.10.0
github.com/code-payments/ocp-server v1.10.1-0.20260427033937-2c1fcf69dcba
github.com/devsisters/go-applereceipt v0.0.0-20240805020915-fa22a0160fc2
github.com/georgysavva/scany/v2 v2.1.4
github.com/google/uuid v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ github.com/code-payments/flipcash2-protobuf-api v1.3.1-0.20260420185108-1e0abce2
github.com/code-payments/flipcash2-protobuf-api v1.3.1-0.20260420185108-1e0abce29a0a/go.mod h1:s/1pOsb4FTRD+LcvRKGjfmm6ygRS/m1ep34EIW0fuDs=
github.com/code-payments/ocp-protobuf-api v1.9.0 h1:VpcOENVTmebpTENhpVaDbFfPPliK1zuMtjHzdhBQY2U=
github.com/code-payments/ocp-protobuf-api v1.9.0/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8=
github.com/code-payments/ocp-server v1.10.0 h1:BKBYqfrQmmMORTVoQn0Qym5B6eb6G792qM+mnG1UWsc=
github.com/code-payments/ocp-server v1.10.0/go.mod h1:tk3LabRL/iRP3C6iImbW5B7oC3ceGRqtmVhkFlqOHZA=
github.com/code-payments/ocp-server v1.10.1-0.20260427033937-2c1fcf69dcba h1:U2mai8GSjwpgk5ywRMJQiF0HnxvZu0krj9YHsJ2EAdI=
github.com/code-payments/ocp-server v1.10.1-0.20260427033937-2c1fcf69dcba/go.mod h1:tk3LabRL/iRP3C6iImbW5B7oC3ceGRqtmVhkFlqOHZA=
github.com/containerd/continuity v0.4.3 h1:6HVkalIp+2u1ZLH1J/pYX2oBVXlJZvh1X1A7bEZ9Su8=
github.com/containerd/continuity v0.4.3/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ/7o4JzpodfroQ=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
Expand Down
Loading