be-components 2.0.7 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/lib/commonjs/Squares/api/index.js +10 -2
  2. package/lib/commonjs/Squares/api/index.js.map +1 -1
  3. package/lib/commonjs/Squares/components/BidForm.js +43 -4
  4. package/lib/commonjs/Squares/components/BidForm.js.map +1 -1
  5. package/lib/commonjs/Squares/components/OfferForm.js +4 -1
  6. package/lib/commonjs/Squares/components/OfferForm.js.map +1 -1
  7. package/lib/commonjs/Squares/index.js +15 -4
  8. package/lib/commonjs/Squares/index.js.map +1 -1
  9. package/lib/module/Squares/api/index.js +10 -2
  10. package/lib/module/Squares/api/index.js.map +1 -1
  11. package/lib/module/Squares/components/BidForm.js +42 -5
  12. package/lib/module/Squares/components/BidForm.js.map +1 -1
  13. package/lib/module/Squares/components/OfferForm.js +4 -1
  14. package/lib/module/Squares/components/OfferForm.js.map +1 -1
  15. package/lib/module/Squares/index.js +15 -4
  16. package/lib/module/Squares/index.js.map +1 -1
  17. package/lib/typescript/src/Squares/api/index.d.ts +3 -2
  18. package/lib/typescript/src/Squares/api/index.d.ts.map +1 -1
  19. package/lib/typescript/src/Squares/components/BidForm.d.ts +4 -3
  20. package/lib/typescript/src/Squares/components/BidForm.d.ts.map +1 -1
  21. package/lib/typescript/src/Squares/components/OfferForm.d.ts +3 -2
  22. package/lib/typescript/src/Squares/components/OfferForm.d.ts.map +1 -1
  23. package/lib/typescript/src/Squares/index.d.ts.map +1 -1
  24. package/package.json +1 -1
  25. package/src/Squares/api/index.ts +10 -3
  26. package/src/Squares/components/BidForm.tsx +33 -8
  27. package/src/Squares/components/OfferForm.tsx +8 -3
  28. package/src/Squares/index.tsx +20 -6
  29. package/src/types.d.ts +1 -1
@@ -1,6 +1,6 @@
1
1
  import axios from "axios"
2
2
  import { APIOverrides } from "../../ApiOverrides"
3
- import type { BuySquaresResponseProps, EventProps, LeagueProps, OfferResponseProps, PlayerSquareProps, PublicPlayerProps, SquareOfferProps, SquarePrizeProps, SquareProps, SquareResultProps, SquaresCompetitionProps, SquaresPayoutProps, SquaresTypeProps, SquareValueProps } from "../../types"
3
+ import type { BuySquaresResponseProps, EventProps, LeagueProps, OfferResponseProps, PlayerBalanceProps, PlayerSquareProps, PublicPlayerProps, SquareOfferProps, SquarePrizeProps, SquareProps, SquareResultProps, SquaresCompetitionProps, SquaresPayoutProps, SquaresTypeProps, SquareValueProps } from "../../types"
4
4
  import moment from "moment-mini"
5
5
 
6
6
  let AUTH_SVC_API = ''
@@ -30,8 +30,10 @@ const SquaresApi = {
30
30
  const resp = await axios.get(`${EVENT_SVC_API}/v1/leagues/league/${league_id}`)
31
31
  return resp.data.league
32
32
  },
33
- buySquares: async(sq_comp_id:string, player_squares:PlayerSquareProps[]):Promise<BuySquaresResponseProps> => {
34
- const resp = await axios.post(`${TP_SVC_API}/tp/squares/square/buy`, { sq_comp_id, player_squares })
33
+ buySquares: async(sq_comp_id:string, player_squares:PlayerSquareProps[], promo_balance?:boolean):Promise<BuySquaresResponseProps> => {
34
+ console.log('HEre')
35
+ console.log(promo_balance)
36
+ const resp = await axios.post(`${TP_SVC_API}/tp/squares/square/buy`, { sq_comp_id, player_squares, promo_balance })
35
37
  if(resp.data.saved_player_squares.length != player_squares.length){ alert('Some of your bids could not be processed as they were outbid before purchasing') }
36
38
  console.log(resp.data)
37
39
  return resp.data
@@ -40,6 +42,11 @@ const SquaresApi = {
40
42
  const resp = await axios.post(`${TP_SVC_API}/tp/squares/square/offer`, { square_offer })
41
43
  return resp.data
42
44
  },
45
+ getMyBalance: async():Promise<PlayerBalanceProps> => {
46
+ const resp = await axios.get(`${AUTH_SVC_API}/v1/players/player/balance/me`);
47
+ console.log(resp.data)
48
+ return resp.data.player_balance
49
+ },
43
50
  getPlayersByPlayerIds : async(player_ids:string[]):Promise<PublicPlayerProps[]> => {
44
51
  if(player_ids.length == 0){ return [] }
45
52
  const resp = await axios.post(`${AUTH_SVC_API}/v1/players/bulk/get`, { player_ids })
@@ -1,9 +1,9 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import { ActivityIndicator, FlatList, TouchableOpacity, View, ScrollView } from 'react-native';
3
3
  import { view_styles } from '../../constants/styles';
4
- import { Text } from '../../Components';
4
+ import { Checkbox, Text } from '../../Components';
5
5
  import Colors from '../../constants/colors';
6
- import type { PlayerSquareProps, SquareProps } from '../../types';
6
+ import type { PlayerBalanceProps, PlayerSquareProps, SquareProps } from '../../types';
7
7
  import BidToggle from './BidToggle';
8
8
 
9
9
  type BidFormProps = {
@@ -11,20 +11,25 @@ type BidFormProps = {
11
11
  market_type:string,
12
12
  home_abbr?:string,
13
13
  width:number,
14
+ player_balance?:PlayerBalanceProps,
14
15
  away_abbr?:string,
15
16
  submit_ready: { is_loading:boolean, is_ready:Boolean }
16
- onSubmitBid: () => void,
17
+ onSubmitBid: (promo_balance?:boolean) => void,
17
18
  onClearBids: () => void,
18
19
  onBidAmountChange: (player_bid:PlayerSquareProps, square:SquareProps, direction: 'increase'|'decrease') => void,
19
20
  onRequestAuthenticate: () => void,
20
21
  square_bids:PlayerSquareProps[],
21
22
  squares:SquareProps[]
22
23
  }
23
- const BidForm = ({ player_id, width, market_type, home_abbr, away_abbr, submit_ready, square_bids, squares, onSubmitBid, onClearBids, onBidAmountChange, onRequestAuthenticate }:BidFormProps) => {
24
+ const BidForm = ({ player_id, player_balance, width, market_type, home_abbr, away_abbr, submit_ready, square_bids, squares, onSubmitBid, onClearBids, onBidAmountChange, onRequestAuthenticate }:BidFormProps) => {
25
+ const [ promo_balance, setPromoBalance ] = useState(false);
26
+
24
27
  const cl = market_type == 'FOR_MONEY' ? '$' : 'E'
25
28
  const total_bid_amount = square_bids.reduce((a,b) => a + b.purchase_price, 0)
26
29
 
27
-
30
+ let can_submit = player_balance && total_bid_amount < player_balance.balance ? true : false
31
+ if(player_balance && promo_balance && player_balance.promo_balance > total_bid_amount){ can_submit = true }
32
+
28
33
  const renderBids = (data: { item:PlayerSquareProps, index:number }) => {
29
34
  let square = squares.find(s => s.sq_square_id == data.item.sq_square_id)
30
35
  if(!square){ return ( <></> ) }
@@ -60,12 +65,32 @@ const BidForm = ({ player_id, width, market_type, home_abbr, away_abbr, submit_r
60
65
  <Text style={{ flex:1 }} theme='body'>Total</Text>
61
66
  <Text theme='header_2'>{cl}{total_bid_amount.toFixed(2)}</Text>
62
67
  </View>
68
+ {player_balance && player_balance.promo_balance > 0 ?
69
+ <TouchableOpacity style={{ ...view_styles.body_row, margin:5, padding:5, backgroundColor:Colors.incentive.gold, borderRadius:8 }} onPress={() => setPromoBalance(!promo_balance)}>
70
+ <Checkbox
71
+ checked={promo_balance}
72
+ disabled
73
+
74
+ size={26}
75
+ onSelect={() => setPromoBalance(!promo_balance)}
76
+ />
77
+ <View style={{ flex:1, marginLeft:10 }}>
78
+ <Text size={12} color={Colors.shades.white} weight='bold'>${player_balance.promo_balance.toFixed(2)} Promotion Available</Text>
79
+ <Text size={10} color={Colors.shades.white} weight='regular' style={{ marginTop:3 }}>Press / Click here to use promo balance</Text>
80
+ </View>
81
+ </TouchableOpacity>
82
+ :<></>}
63
83
  <View style={{ ...view_styles.body_row }}>
64
- <TouchableOpacity style={{ flex:1/3, padding:12, borderRadius:4, borderWidth:1, borderColor:Colors.brand.cobalt, justifyContent:'center', alignItems:'center', marginRight:4 }} onPress={() => onClearBids()}>
84
+ <TouchableOpacity
85
+ style={{ flex:1/3, padding:12, borderRadius:4, borderWidth:1, borderColor:Colors.brand.cobalt, justifyContent:'center', alignItems:'center', marginRight:4}} onPress={() => onClearBids()}>
65
86
  <Text size={14} weight='semibold' textAlign='center' color={Colors.brand.cobalt}>Clear</Text>
66
87
  </TouchableOpacity>
67
88
  {player_id ?
68
- <TouchableOpacity style={{ flex:2/3, padding:12, borderRadius:4, backgroundColor:submit_ready.is_ready?Colors.highlights.highlight400:Colors.highlights.highlight200, justifyContent:'center', alignItems:'center', marginLeft:4, opacity:submit_ready.is_loading?0.5:1 }} onPress={() => onSubmitBid()}>
89
+ <TouchableOpacity
90
+ style={{ flex:2/3, padding:12, borderRadius:4, backgroundColor:submit_ready.is_ready?Colors.highlights.highlight400:Colors.highlights.highlight200, justifyContent:'center', alignItems:'center', marginLeft:4, opacity:submit_ready.is_loading || !can_submit?0.5:1 }} onPress={() => onSubmitBid(promo_balance)}
91
+ disabled={!can_submit}
92
+
93
+ >
69
94
  {submit_ready.is_loading ?
70
95
  <ActivityIndicator size='small' color={Colors.shades.white}/>
71
96
  :
@@ -1,13 +1,14 @@
1
1
  import React from 'react';
2
2
  import { ActivityIndicator, FlatList, TouchableOpacity, View } from "react-native"
3
3
  import { Text } from "../../Components"
4
- import type { PlayerSquareProps, SquareOfferProps, SquareProps } from "../../types"
4
+ import type { PlayerBalanceProps, PlayerSquareProps, SquareOfferProps, SquareProps } from "../../types"
5
5
  import BidToggle from "./BidToggle"
6
6
  import { view_styles } from "../../constants/styles"
7
7
  import Colors from "../../constants/colors"
8
8
 
9
9
  type OfferFormProps = {
10
10
  player_id?:string,
11
+ player_balance?:PlayerBalanceProps,
11
12
  market_type:string,
12
13
  home_abbr?:string,
13
14
  away_abbr?:string,
@@ -22,10 +23,12 @@ type OfferFormProps = {
22
23
  squares:SquareProps[]
23
24
  }
24
25
 
25
- const OfferForm = ({ player_id, market_type, width, squares, submit_ready, home_abbr, away_abbr, player_squares, draft_square_offers, onRequestAuthenticate, onOfferAmountChange, onClearOffers, onSubmitOffer }:OfferFormProps) => {
26
+ const OfferForm = ({ player_id, player_balance, market_type, width, squares, submit_ready, home_abbr, away_abbr, player_squares, draft_square_offers, onRequestAuthenticate, onOfferAmountChange, onClearOffers, onSubmitOffer }:OfferFormProps) => {
26
27
  const cl = market_type == 'FOR_MONEY' ? '$' : 'E'
27
28
  const total_offer_amount = draft_square_offers.reduce((a,b) => a + b.amount, 0)
28
29
 
30
+ let can_submit = player_balance && total_offer_amount < player_balance.balance ? true : false
31
+
29
32
 
30
33
  const renderDraftOffers = (data: { item:SquareOfferProps, index:number }) => {
31
34
  let ps = player_squares.find(psQ => psQ.sq_player_square_id == data.item.sq_player_square_id)
@@ -74,7 +77,9 @@ const OfferForm = ({ player_id, market_type, width, squares, submit_ready, home_
74
77
  <Text size={14} weight='semibold' textAlign='center' color={Colors.brand.cobalt}>Clear</Text>
75
78
  </TouchableOpacity>
76
79
  {player_id ?
77
- <TouchableOpacity style={{ flex:2/3, padding:12, borderRadius:4, backgroundColor:submit_ready.is_ready?Colors.highlights.highlight400:Colors.highlights.highlight200, justifyContent:'center', alignItems:'center', marginLeft:4, opacity:submit_ready.is_loading?0.5:1 }} onPress={() => onSubmitOffer()}>
80
+ <TouchableOpacity
81
+ disabled={!can_submit}
82
+ style={{ flex:2/3, padding:12, borderRadius:4, backgroundColor:submit_ready.is_ready?Colors.highlights.highlight400:Colors.highlights.highlight200, justifyContent:'center', alignItems:'center', marginLeft:4, opacity:submit_ready.is_loading || !can_submit ? 0.5:1 }} onPress={() => onSubmitOffer()}>
78
83
  {submit_ready.is_loading ?
79
84
  <ActivityIndicator size='small' color={Colors.shades.white}/>
80
85
  :
@@ -1,6 +1,6 @@
1
1
  import React, { useEffect, useState } from "react"
2
2
  import { ActivityIndicator, View, Image, TouchableOpacity, ScrollView } from 'react-native';
3
- import type { BuySquaresResponseProps, EventProps, LeagueProps, OfferResponseProps, PlayerSquareProps, PublicPlayerProps, SquareOfferProps, SquarePrizeProps, SquareProps, SquareResultProps, SquaresCompetitionProps, SquaresPayoutProps, SquaresTypeProps } from "../types"
3
+ import type { BuySquaresResponseProps, EventProps, LeagueProps, OfferResponseProps, PlayerBalanceProps, PlayerSquareProps, PublicPlayerProps, SquareOfferProps, SquarePrizeProps, SquareProps, SquareResultProps, SquaresCompetitionProps, SquaresPayoutProps, SquaresTypeProps } from "../types"
4
4
  import Colors from "../constants/colors";
5
5
  import { SqauresHelpers, SquaresApi } from "./api";
6
6
  import { Button, Icons, Text } from "../Components";
@@ -36,7 +36,12 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
36
36
  const [ bid_form_expanded, setBidFormExpanded ] = useState(false);
37
37
  const [ updated_from_bid, setUpdatedFromBid ]= useState<BuySquaresResponseProps>();
38
38
  const [ updated_from_offer, setUpdatedFromOffer ]= useState<OfferResponseProps>();
39
+ const [ my_data, setMyData ] = useState<{
40
+ player_balance?:PlayerBalanceProps
41
+ }>({
39
42
 
43
+ })
44
+ const { player_balance } = my_data;
40
45
  const [ module_data, setModuleData ] = useState<{
41
46
  loading:boolean,
42
47
  loaded:boolean,
@@ -86,7 +91,7 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
86
91
  if(!sq_comp_id){ return }
87
92
  if(!loaded){ SquaresApi.setEnvironment(); }
88
93
  getDataFromServer(sq_comp_id);
89
- },[sq_comp_id])
94
+ },[sq_comp_id, player_id])
90
95
 
91
96
  useEffect(() => {
92
97
  if(!updated_from_bid?.squares_competition){ return }
@@ -104,7 +109,14 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
104
109
  const evs = await SquaresApi.getEventsByEventIds([d.squares_competition.event_id]);
105
110
  const league_id = evs[0]?.league_id
106
111
  let unique_player_ids = [ ...new Set(d.player_squares.map(ps => ps.player_id)) ]
107
- if(player_id){ unique_player_ids.push(player_id) }
112
+ if(player_id){
113
+ unique_player_ids.push(player_id)
114
+ const pb = await SquaresApi.getMyBalance();
115
+ setMyData({
116
+ ...my_data,
117
+ player_balance:pb
118
+ })
119
+ }
108
120
  let ps = await SquaresApi.getPlayersByPlayerIds(unique_player_ids)
109
121
  let l:LeagueProps | undefined = undefined
110
122
  if(league_id){
@@ -129,7 +141,7 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
129
141
  }
130
142
 
131
143
 
132
- const handleSubmitBid = async() => {
144
+ const handleSubmitBid = async(promo_balance?:boolean) => {
133
145
  if(!squares_competition){ return }
134
146
  if(!player_id){ return onRequestAuthenticate(squares_competition.auth_strategy_id) }
135
147
  if(!submit_ready.is_ready){
@@ -143,7 +155,7 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
143
155
  if(submit_ready.is_loading){ return } //Prevent button mashing
144
156
  //SUBMIT BIDS!
145
157
  setBoardData({ ...board_data, submit_ready: { ...submit_ready, is_loading:true } })
146
- await SquaresApi.buySquares(squares_competition.sq_comp_id, square_bids)
158
+ await SquaresApi.buySquares(squares_competition.sq_comp_id, square_bids, promo_balance)
147
159
  //if(needs_reload){ handleUpdateBoardFromBuy(resp) } //If we somehow got disconnected from the socket, we need to load it
148
160
  setBoardData({ ...board_data, square_bids:[], submit_ready:{ is_loading: false, is_ready: false } })
149
161
  setBidFormExpanded(false);
@@ -440,6 +452,7 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
440
452
  <View style={{ position:'absolute', bottom:0, left:0, right:0, top:0, justifyContent:module_size.width > 500 ? 'center' : 'flex-end', alignItems:'center', backgroundColor:Colors.shades.black_faded }}>
441
453
  <BidForm
442
454
  player_id={player_id}
455
+ player_balance={player_balance}
443
456
  home_abbr={home_abbr}
444
457
  away_abbr={away_abbr}
445
458
  width={module_size.width}
@@ -450,7 +463,7 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
450
463
  square_bids={square_bids}
451
464
  onClearBids={handleClearBids}
452
465
  onRequestAuthenticate={() => onRequestAuthenticate(squares_competition.auth_strategy_id)}
453
- onSubmitBid={() => handleSubmitBid()}
466
+ onSubmitBid={(promo_balance) => handleSubmitBid(promo_balance)}
454
467
  />
455
468
  </View>
456
469
  :<></>}
@@ -460,6 +473,7 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
460
473
  player_id={player_id}
461
474
  draft_square_offers={draft_square_offers}
462
475
  home_abbr={home_abbr}
476
+ player_balance={player_balance}
463
477
  width={module_size.width}
464
478
  away_abbr={away_abbr}
465
479
  squares={squares}
package/src/types.d.ts CHANGED
@@ -1605,7 +1605,7 @@ export interface BuySquaresResponseProps { squares_competition:SquaresCompetitio
1605
1605
 
1606
1606
  export interface PlayerSquareProps {
1607
1607
  sq_player_square_id:string, sq_comp_id:string, sq_square_id:string, player_id:string, purchase_price:number,
1608
- status:string, create_datetime:any, last_update_datetime:any
1608
+ status:string, promo_balance?:boolean, create_datetime:any, last_update_datetime:any
1609
1609
  }
1610
1610
 
1611
1611
  export interface SquareResultProps {