-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
161 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,56 @@ | ||
import { RootState } from ".."; | ||
import { sdk } from "../../sdk"; | ||
import { AssetsOwned } from "@sshlabs/typings"; | ||
import axios from "axios"; | ||
|
||
///////////// | ||
// SIGN_IN // | ||
///////////// | ||
export const SIGN_IN = "SIGN_IN"; | ||
export interface ActionInit { | ||
export interface ActionSignIn { | ||
type: typeof SIGN_IN; | ||
payload: { | ||
signedIn: boolean; | ||
address: string; | ||
}; | ||
} | ||
|
||
export const GET_ASSETS_OWNED = "GET_ASSETS_OWNED"; | ||
export interface ActionGetAssetOwned { | ||
type: typeof GET_ASSETS_OWNED; | ||
payload: AssetsOwned; | ||
} | ||
export const getAssetsOwned = (dropId: number, address: string) => { | ||
const toDispatch = (payload: ActionGetAssetOwned["payload"]): ActionGetAssetOwned => { | ||
return { | ||
type: GET_ASSETS_OWNED, | ||
payload: payload, | ||
}; | ||
}; | ||
|
||
return async (dispatch: any, getState: () => RootState) => { | ||
try { | ||
const result = (await axios.get(`http://localhost:3001/drop/${dropId}/${address}`)) | ||
.data as AssetsOwned; | ||
|
||
return dispatch(toDispatch(result)); | ||
} catch (e) {} | ||
}; | ||
}; | ||
|
||
export const signIn = () => { | ||
const toDispatch = (payload: ActionInit["payload"]): ActionInit => { | ||
const toDispatch = (payload: ActionSignIn["payload"]): ActionSignIn => { | ||
return { | ||
type: SIGN_IN, | ||
payload: payload, | ||
}; | ||
}; | ||
|
||
// | ||
return async (dispatch: any, getState: () => RootState) => { | ||
try { | ||
await sdk.connect(); | ||
const { address } = sdk.getInfo(); | ||
|
||
return dispatch(toDispatch({ signedIn: true, address: address })); | ||
} catch (e) { | ||
return dispatch(toDispatch({ signedIn: false, address: "" })); | ||
} | ||
} catch (e) {} | ||
}; | ||
}; | ||
|
||
export type AppActionTypes = ActionInit; | ||
export type AppActionTypes = ActionSignIn | ActionGetAssetOwned; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.