Skip to content

Commit

Permalink
Cust linking xyzabc 3 (#1886)
Browse files Browse the repository at this point in the history
* fix request payload for xyzabc custodian linking

* fix xyzabc country code

* Fix tests

* Add xyzabc to the list of custodians

---------

Co-authored-by: PavelBrm <[email protected]>
  • Loading branch information
husobee and pavelbrm committed Jul 7, 2023
1 parent edc7b85 commit cd02710
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion libs/datastore/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
}
dbs = map[string]*sqlx.DB{}
// CurrentMigrationVersion holds the default migration version
CurrentMigrationVersion = uint(60)
CurrentMigrationVersion = uint(61)
// MigrationTracks holds the migration version for a given track (eyeshade, promotion, wallet)
MigrationTracks = map[string]uint{
"eyeshade": 20,
Expand Down
5 changes: 5 additions & 0 deletions migrations/0061_wallet_custodian_check_custodian.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE wallet_custodian
DROP CONSTRAINT IF EXISTS check_custodian,
ADD CONSTRAINT check_custodian CHECK (
custodian IN ('brave', 'uphold', 'bitflyer', 'gemini')
);
5 changes: 5 additions & 0 deletions migrations/0061_wallet_custodian_check_custodian.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE wallet_custodian
DROP CONSTRAINT IF EXISTS check_custodian,
ADD CONSTRAINT check_custodian CHECK (
custodian IN ('brave', 'uphold', 'bitflyer', 'gemini', 'xyzabc')
);
2 changes: 1 addition & 1 deletion services/wallet/controllers_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ func TestLinkXyzAbcWalletV3(t *testing.T) {
"POST",
fmt.Sprintf("/v3/wallet/xyzabc/%s/claim", idFrom),
bytes.NewBufferString(fmt.Sprintf(
`{"linkingInfo": "%s"}`,
`{"linking_info": "%s"}`,
linkingInfo,
)),
)
Expand Down
6 changes: 3 additions & 3 deletions services/wallet/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ func (pg *Postgres) ConnectCustodialWallet(ctx context.Context, cl *CustodianLin
) values (
$1, $2, $3
)
on conflict (wallet_id, custodian, linking_id)
on conflict (wallet_id, custodian, linking_id)
do update set updated_at=now(), disconnected_at=null, unlinked_at=null, linked_at=now()
returning *
`
Expand Down Expand Up @@ -1019,7 +1019,7 @@ func (pg *Postgres) ConnectCustodialWallet(ctx context.Context, cl *CustodianLin

// InsertVerifiedWalletOutboxTx inserts a verifiedWalletOutbox for processing.
func (pg *Postgres) InsertVerifiedWalletOutboxTx(ctx context.Context, tx *sqlx.Tx, walletID uuid.UUID, verifiedWallet bool) error {
_, err := tx.ExecContext(ctx, `insert into verified_wallet_outbox(payment_id, verified_wallet)
_, err := tx.ExecContext(ctx, `insert into verified_wallet_outbox(payment_id, verified_wallet)
values ($1, $2)`, walletID, verifiedWallet)
if err != nil {
return fmt.Errorf("error inserting values into vefified wallet outbox: %w", err)
Expand All @@ -1041,7 +1041,7 @@ func (pg *Postgres) SendVerifiedWalletOutbox(ctx context.Context, client reputat
}
defer rollback()

err = tx.Get(&vw, `select id, payment_id, verified_wallet from verified_wallet_outbox
err = tx.Get(&vw, `select id, payment_id, verified_wallet from verified_wallet_outbox
order by created_at asc for update skip locked limit 1`)
if err != nil {
return false, fmt.Errorf("error get verified wallet: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion services/wallet/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (lbdar *LinkBraveDepositAccountRequest) HandleErrors(err error) *handlers.A

// XyzAbcLinkingRequest holds info needed to link xyzabc account.
type XyzAbcLinkingRequest struct {
VerificationToken string `json:"linkingInfo"`
VerificationToken string `json:"linking_info"`
}

// Validate implements DecodeValidate interface.
Expand Down
5 changes: 2 additions & 3 deletions services/wallet/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,7 @@ func (service *Service) LinkXyzAbcWallet(ctx context.Context, walletID uuid.UUID
providerLinkingID := uuid.NewV5(ClaimNamespace, accountID)

// tx.Destination will be stored as UserDepositDestination in the wallet info upon linking.
// FIXME - correct country
if err := service.Datastore.LinkWallet(ctx, walletID.String(), depositID, providerLinkingID, nil, "xyzabc", "US"); err != nil {
if err := service.Datastore.LinkWallet(ctx, walletID.String(), depositID, providerLinkingID, nil, "xyzabc", "IN"); err != nil {
if errors.Is(err, ErrUnusualActivity) {
return handlers.WrapError(err, "unable to link - unusual activity", http.StatusBadRequest)
}
Expand All @@ -471,7 +470,7 @@ func (service *Service) LinkXyzAbcWallet(ctx context.Context, walletID uuid.UUID
status = http.StatusConflict
}

return handlers.WrapError(err, "unable to link gemini wallets", status)
return handlers.WrapError(err, "unable to link xyzabc wallets", status)
}

return nil
Expand Down

0 comments on commit cd02710

Please sign in to comment.