Skip to content

Commit

Permalink
Merge pull request #44 from Samuellyworld/dev
Browse files Browse the repository at this point in the history
cleaning/fixing and debugging MVC 🥑
  • Loading branch information
Samuellyworld authored Dec 3, 2022
2 parents 05ed320 + 00dc5c9 commit aa0e3ef
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 73 deletions.
12 changes: 6 additions & 6 deletions providers/AlertModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import React from "react";
import { useSelector, useDispatch } from "react-redux";
import { RootState } from "../store/store";
import GridLoader from 'react-spinners/GridLoader';
import HashLoader from 'react-spinners/HashLoader';

// JSX Component AlertModal
const AlertModal = () => {
Expand Down Expand Up @@ -72,21 +72,21 @@ const AlertModal = () => {
}}
className="p"
>
<GridLoader
<HashLoader
color="#eee"
size={2}
size={17}
speedMultiplier={0.4}
/>
<span style={{
marginLeft: "5px",
marginLeft: "7px",
color:"white",
fontFamily: "Chopsic, sans-serif"
}}> Alert </span>
</p>
<p style={{
padding : "1px",
fontSize : "11px",
fontWeight : "bolder",
fontSize : "13px",
fontWeight : "700",
color : "#FE5F75",
fontFamily: "Inter, sans-serif"
}} >
Expand Down
10 changes: 7 additions & 3 deletions store/result/result.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { RESULT_ACTION_TYPES } from './result.types';
// user types
interface resultTypes {
result : any,
hash: string
}

// initial state
const initialState: resultTypes= {
result : null
result : null,
hash: ""
}

// setting user actions
Expand All @@ -23,14 +25,16 @@ export const resultSlice= createSlice({
setResult : (state :any, action :PayloadAction<any>) => {
state.result = action.payload
},

hash : (state :any, action :PayloadAction<any>) => {
state.hash = action.payload
}
}


})

// dispatch
export const {setResult} = resultSlice.actions
export const {setResult, hash} = resultSlice.actions

//reducer
export default resultSlice.reducer
Expand Down
2 changes: 1 addition & 1 deletion styles/sass/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
--item-nb: 0;
--selected-item: 0;
--nb-turn: 20;
--spinning-duration: 10s;
--spinning-duration: 5s;
--reset-duration: 0.25s;
}

Expand Down
105 changes: 73 additions & 32 deletions ui/components/StakeCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const StakeCard = (props: StakeCardProps): JSX.Element => {
const dispatch = useDispatch();

// initial state
const [txHash, setTxHash] = useState('')
const [outcome, setOutcome]:any = useState([]);
const [chosenOutcome, setChosenOutcome] = useState(game === 'wheel' ? 'wheel' : '');
// console.log(stake, connected, game, result);
Expand All @@ -81,7 +82,7 @@ const StakeCard = (props: StakeCardProps): JSX.Element => {
//set address
const address = useSelector((state:RootState)=> state.address.address)

// result
// use result from smart contract to set frontend payout
useEffect(() => {
console.log(coin, 'coin')
if (game.includes('wheel')) {
Expand All @@ -105,7 +106,7 @@ const StakeCard = (props: StakeCardProps): JSX.Element => {
}
}, [result]);

//
//set outcome
useEffect(() => {
if (game.includes('dice')) {
setOutcome(['greater than 6', 'less than 6']);
Expand All @@ -127,7 +128,6 @@ const StakeCard = (props: StakeCardProps): JSX.Element => {

// button action
const spinGame = async () => {
console.log(game);
if(!address) {
dispatch(alert('connect your wallet'));
setTimeout(() => {
Expand All @@ -148,41 +148,82 @@ const StakeCard = (props: StakeCardProps): JSX.Element => {
}, 2000)
return;
}
// coins
if(game.includes('coins')) {
const bet:number = chosenOutcome.includes('head') ? 1 : 0
dispatch(alert('Processing transaction... 🔂'))
const result= await flip(bet, Math.round(Number(stake)*10**15), address)
const id = await getRequestId(bet)
console.log(id, 'id')
setTimeout(async ()=> {
console.log(id, 'id contract')
await getResult(id, dispatch)
onSpin();
setDisabled(false);
}, 40000)
setDisabled(true);
if(result.hash) {
setTxHash(result.hash)
const id = await getRequestId(bet)
setTimeout(async ()=> {
console.log(id, 'id contract')
await getResult(id, dispatch)
onSpin();
setDisabled(false);
dispatch(close(''))
}, 40000)
dispatch(alert('Processing Tnx blocks.. ⌛️'))
setDisabled(true);
} else {
dispatch(alert('😰 Error Processing... '))
setTimeout(() => {
dispatch(close(""))
}, 2000)
return;
}
// dicd
} else if (game.includes('dice')) {
const bet:number = chosenOutcome.includes('greater') ? 0 : 1
const result= await roll(bet, Math.round(Number(stake)*10**15), address)
const id = await getDiceRequestId(bet)
console.log(id, 'id')
setTimeout(async ()=> {
console.log(id, 'id contract')
await getDiceResult(id, dispatch)
onSpin();
setDisabled(false);
}, 40000)
setDisabled(true);
dispatch(alert('Processing transaction... 🔂'))
const result= await roll(bet, Math.round(Number(stake)*10**15), address)
if(result.hash) {
setTxHash(result.hash)
const id = await getDiceRequestId(bet)
console.log(id, 'id')
setTimeout(async ()=> {
console.log(id, 'id contract')
await getDiceResult(id, dispatch)
onSpin();
setDisabled(false);
dispatch(close(''));
}, 40000)
dispatch(alert('Processing Tnx blocks.. ⌛️'))
setDisabled(true);

} else {
dispatch(alert('😰 Error Processing... '))
setTimeout(() => {
dispatch(close(""))
}, 2000)
return;
}
//wheel
} else if(game.includes('wheel')) {
dispatch(alert('Processing Transaction... 🔂'))
const result= await spinWheel(Math.round(Number(stake)*10**15), address)
const id = await getWheelRequestId()
console.log(id, 'id')
setTimeout(async ()=> {
console.log(id, 'id contract')
await getWheelResult(id, dispatch)
onSpin();
setDisabled(false);
}, 40000)
setDisabled(true);
if(result.hash) {
setTxHash(result.hash)
dispatch(close(''))
const id = await getWheelRequestId()
console.log(id, 'id')
setTimeout(async ()=> {
console.log(id, 'id contract')
await getWheelResult(id, dispatch)
onSpin();
setDisabled(false);
dispatch(close(''));
}, 40000)
dispatch(alert('Processing Tnx blocks.. ⌛️'))
setDisabled(true);
} else {
dispatch(alert('😰 Error Processing... '))
setTimeout(() => {
dispatch(close(""))
}, 2000)
return;
}

}
}

Expand Down Expand Up @@ -280,7 +321,7 @@ const StakeCard = (props: StakeCardProps): JSX.Element => {
marginLeft: "-5px"
// marginTop: "1rem"
}}/>
<a href="/">(Polygonscan)</a>
<a href={`https://mumbai.polygonscan.com/tx/${txHash}`}>(Polygonscan)</a>
</span>
</Typography>
) : (
Expand Down
10 changes: 6 additions & 4 deletions ui/widgets/DiceGame/RollDice/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ const RollDice = ({
}
};
useEffect(() => {
const res = Number(result.randomWord1) + Number(result.randomWord2);
// console.log('res', res);
setResult(res.toString());
}, [result]);
if(spin) {
const res = Number(result.randomWord1) + Number(result.randomWord2);
// console.log('res', res);
setResult(res.toString());
}
}, [spin]);

useEffect(() => {
if (spin) {
Expand Down
Loading

0 comments on commit aa0e3ef

Please # to comment.