rename js "names" from bucket to redeemable

This commit is contained in:
Andrea Franz 2020-05-14 09:28:58 +02:00
parent bf00d10bd2
commit dedc818388
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
9 changed files with 105 additions and 105 deletions

View File

@ -1,7 +1,7 @@
import { RootState } from '../reducers'; import { RootState } from '../reducers';
import { config } from "../config"; import { config } from "../config";
import { Dispatch } from 'redux'; import { Dispatch } from 'redux';
import { newBucketContract } from "./bucket"; import { newBucketContract } from "./redeemable";
import { sha3 } from "web3-utils"; import { sha3 } from "web3-utils";
import { recoverTypedSignature } from 'eth-sig-util'; import { recoverTypedSignature } from 'eth-sig-util';
import { Web3Type } from "../actions/web3"; import { Web3Type } from "../actions/web3";
@ -117,7 +117,7 @@ export const redeem = (bucketAddress: string, recipientAddress: string, cleanCod
const domainName = isERC20 ? "KeycardERC20Bucket" : "KeycardNFTBucket"; const domainName = isERC20 ? "KeycardERC20Bucket" : "KeycardNFTBucket";
//FIXME: is signer needed? //FIXME: is signer needed?
signRedeem(web3Type, bucketAddress, state.web3.account!, message, domainName).then(async ({ sig, address }: SignRedeemResponse) => { signRedeem(web3Type, bucketAddress, state.web3.account!, message, domainName).then(async ({ sig, address }: SignRedeemResponse) => {
const recipient = state.bucket.recipient!; const recipient = state.redeemable.recipient!;
if (address.toLowerCase() !== recipient.toLowerCase()) { if (address.toLowerCase() !== recipient.toLowerCase()) {
//FIXME: handle error //FIXME: handle error
dispatch(wrongSigner(recipient, address)); dispatch(wrongSigner(recipient, address));

View File

@ -18,7 +18,7 @@ export interface ErrLoadingRedeemable {
message: string message: string
} }
export type BucketErrors = export type RedeemableErrors =
ErrRedeemableNotFound | ErrRedeemableNotFound |
ErrLoadingRedeemable; ErrLoadingRedeemable;
@ -31,37 +31,37 @@ const errLoadingRedeemable = (message: string): ErrLoadingRedeemable => ({
message, message,
}); });
export const BUCKET_REDEEMABLE_LOADING = "BUCKET_REDEEMABLE_LOADING"; export const REDEEMABLE_LOADING = "REDEEMABLE_LOADING";
export interface BucketRedeemableLoadingAction { export interface RedeemableLoadingAction {
type: typeof BUCKET_REDEEMABLE_LOADING type: typeof REDEEMABLE_LOADING
address: string address: string
recipient: string recipient: string
} }
export const BUCKET_REDEEMABLE_LOADING_ERROR = "BUCKET_REDEEMABLE_LOADING_ERROR"; export const REDEEMABLE_LOADING_ERROR = "REDEEMABLE_LOADING_ERROR";
export interface BucketRedeemableLoadingErrorAction { export interface RedeemableLoadingErrorAction {
type: typeof BUCKET_REDEEMABLE_LOADING_ERROR type: typeof REDEEMABLE_LOADING_ERROR
error: ErrLoadingRedeemable error: ErrLoadingRedeemable
} }
export const BUCKET_REDEEMABLE_LOADED = "BUCKET_REDEEMABLE_LOADED"; export const REDEEMABLE_LOADED = "REDEEMABLE_LOADED";
export interface BucketRedeemableLoadedAction { export interface RedeemableLoadedAction {
type: typeof BUCKET_REDEEMABLE_LOADED type: typeof REDEEMABLE_LOADED
expirationTime: number expirationTime: number
recipient: string recipient: string
amount: string amount: string
codeHash: string codeHash: string
} }
export const BUCKET_REDEEMABLE_NOT_FOUND = "BUCKET_REDEEMABLE_NOT_FOUND"; export const REDEEMABLE_NOT_FOUND = "REDEEMABLE_NOT_FOUND";
export interface BucketRedeemableNotFoundAction { export interface RedeemableNotFoundAction {
type: typeof BUCKET_REDEEMABLE_NOT_FOUND type: typeof REDEEMABLE_NOT_FOUND
error: ErrRedeemableNotFound error: ErrRedeemableNotFound
} }
export const BUCKET_TOKEN_LOADING = "BUCKET_TOKEN_LOADING"; export const TOKEN_LOADING = "TOKEN_LOADING";
export interface BucketTokenLoadingAction { export interface TokenLoadingAction {
type: typeof BUCKET_TOKEN_LOADING type: typeof TOKEN_LOADING
address: string address: string
} }
@ -84,79 +84,79 @@ export interface TokenNFT {
export type Token = TokenERC20 | TokenNFT; export type Token = TokenERC20 | TokenNFT;
export const BUCKET_TOKEN_LOADED = "BUCKET_TOKEN_LOADED"; export const TOKEN_LOADED = "TOKEN_LOADED";
export interface BucketTokenLoadedAction { export interface TokenLoadedAction {
type: typeof BUCKET_TOKEN_LOADED type: typeof TOKEN_LOADED
token: Token, token: Token,
} }
export const BUCKET_TOKEN_METADATA_LOADING = "BUCKET_TOKEN_METADATA_LOADING"; export const TOKEN_METADATA_LOADING = "TOKEN_METADATA_LOADING";
export interface BucketTokenMetadataLoadingAction { export interface TokenMetadataLoadingAction {
type: typeof BUCKET_TOKEN_METADATA_LOADING type: typeof TOKEN_METADATA_LOADING
tokenAddress: string tokenAddress: string
recipient: string recipient: string
} }
export const BUCKET_TOKEN_METADATA_LOADED = "BUCKET_TOKEN_METADATA_LOADED"; export const TOKEN_METADATA_LOADED = "TOKEN_METADATA_LOADED";
export interface BucketTokenMetadataLoadedAction { export interface TokenMetadataLoadedAction {
type: typeof BUCKET_TOKEN_METADATA_LOADED type: typeof TOKEN_METADATA_LOADED
tokenAddress: string tokenAddress: string
recipient: string recipient: string
metadata: TokenNFTMetadata metadata: TokenNFTMetadata
} }
export type BucketActions = export type RedeemableActions =
BucketRedeemableLoadingAction | RedeemableLoadingAction |
BucketRedeemableLoadingErrorAction | RedeemableLoadingErrorAction |
BucketRedeemableLoadedAction | RedeemableLoadedAction |
BucketRedeemableNotFoundAction | RedeemableNotFoundAction |
BucketTokenLoadingAction | TokenLoadingAction |
BucketTokenLoadedAction | TokenLoadedAction |
BucketTokenMetadataLoadingAction | TokenMetadataLoadingAction |
BucketTokenMetadataLoadedAction; TokenMetadataLoadedAction;
export const loadingRedeemable = (address: string, recipient: string): BucketRedeemableLoadingAction => ({ export const loadingRedeemable = (address: string, recipient: string): RedeemableLoadingAction => ({
type: BUCKET_REDEEMABLE_LOADING, type: REDEEMABLE_LOADING,
address, address,
recipient, recipient,
}); });
export const redeemableLoaded = (expirationTime: number, recipient: string, amount: string, codeHash: string): BucketRedeemableLoadedAction => ({ export const redeemableLoaded = (expirationTime: number, recipient: string, amount: string, codeHash: string): RedeemableLoadedAction => ({
type: BUCKET_REDEEMABLE_LOADED, type: REDEEMABLE_LOADED,
expirationTime, expirationTime,
recipient, recipient,
amount, amount,
codeHash, codeHash,
}); });
export const redeemableNotFound = (): BucketRedeemableNotFoundAction => ({ export const redeemableNotFound = (): RedeemableNotFoundAction => ({
type: BUCKET_REDEEMABLE_NOT_FOUND, type: REDEEMABLE_NOT_FOUND,
error: errRedeemableNotFound(), error: errRedeemableNotFound(),
}); });
export const errorLoadingRedeemable = (errorMessage: string): BucketRedeemableLoadingErrorAction => ({ export const errorLoadingRedeemable = (errorMessage: string): RedeemableLoadingErrorAction => ({
type: BUCKET_REDEEMABLE_LOADING_ERROR, type: REDEEMABLE_LOADING_ERROR,
error: errLoadingRedeemable(errorMessage), error: errLoadingRedeemable(errorMessage),
}); });
export const loadingToken = (address: string): BucketTokenLoadingAction => ({ export const loadingToken = (address: string): TokenLoadingAction => ({
type: BUCKET_TOKEN_LOADING, type: TOKEN_LOADING,
address, address,
}); });
export const tokenLoaded = (token: Token): BucketTokenLoadedAction => ({ export const tokenLoaded = (token: Token): TokenLoadedAction => ({
type: BUCKET_TOKEN_LOADED, type: TOKEN_LOADED,
token, token,
}); });
export const loadingTokenMetadata = (tokenAddress: string, recipient: string): BucketTokenMetadataLoadingAction => ({ export const loadingTokenMetadata = (tokenAddress: string, recipient: string): TokenMetadataLoadingAction => ({
type: BUCKET_TOKEN_METADATA_LOADING, type: TOKEN_METADATA_LOADING,
tokenAddress, tokenAddress,
recipient, recipient,
}); });
export const tokenMetadataLoaded = (tokenAddress: string, recipient: string, metadata: TokenNFTMetadata): BucketTokenMetadataLoadedAction => ({ export const tokenMetadataLoaded = (tokenAddress: string, recipient: string, metadata: TokenNFTMetadata): TokenMetadataLoadedAction => ({
type: BUCKET_TOKEN_METADATA_LOADED, type: TOKEN_METADATA_LOADED,
tokenAddress, tokenAddress,
recipient, recipient,
metadata, metadata,

View File

@ -6,15 +6,15 @@ import {
useSelector, useSelector,
useDispatch, useDispatch,
} from 'react-redux'; } from 'react-redux';
import { redeemPath } from '../config'; import { redeemablePath } from '../config';
import { import {
TokenERC20, TokenERC20,
TokenNFT, TokenNFT,
loadRedeemable, loadRedeemable,
BucketErrors, RedeemableErrors,
ERROR_LOADING_REDEEMABLE, ERROR_LOADING_REDEEMABLE,
ERROR_REDEEMABLE_NOT_FOUND, ERROR_REDEEMABLE_NOT_FOUND,
} from '../actions/bucket'; } from '../actions/redeemable';
import { import {
toBaseUnit, toBaseUnit,
KECCAK_EMPTY_STRING2, KECCAK_EMPTY_STRING2,
@ -27,7 +27,7 @@ import {
ERROR_WRONG_SIGNER, ERROR_WRONG_SIGNER,
} from '../actions/redeem'; } from '../actions/redeem';
const buckerErrorMessage = (error: BucketErrors): string => { const buckerErrorMessage = (error: RedeemableErrors): string => {
switch (error.type) { switch (error.type) {
case ERROR_LOADING_REDEEMABLE: case ERROR_LOADING_REDEEMABLE:
return "couldn't load redeemable"; return "couldn't load redeemable";
@ -62,7 +62,7 @@ export default function(ownProps: any) {
const dispatch = useDispatch() const dispatch = useDispatch()
const match = useRouteMatch<URLParams>({ const match = useRouteMatch<URLParams>({
path: redeemPath, path: redeemablePath,
exact: true, exact: true,
}); });
@ -75,16 +75,16 @@ export default function(ownProps: any) {
const props = useSelector((state: RootState) => { const props = useSelector((state: RootState) => {
return { return {
bucketAddress: state.bucket.address, bucketAddress: state.redeemable.address,
loading: state.bucket.loading, loading: state.redeemable.loading,
expirationTime: state.bucket.expirationTime, expirationTime: state.redeemable.expirationTime,
error: state.bucket.error, error: state.redeemable.error,
recipient: state.bucket.recipient, recipient: state.redeemable.recipient,
amount: state.bucket.amount, amount: state.redeemable.amount,
codeHash: state.bucket.codeHash, codeHash: state.redeemable.codeHash,
tokenAddress: state.bucket.tokenAddress, tokenAddress: state.redeemable.tokenAddress,
token: state.bucket.token, token: state.redeemable.token,
loadingTokenMetadata: state.bucket.loadingTokenMetadata, loadingTokenMetadata: state.redeemable.loadingTokenMetadata,
receiver: state.web3.account, receiver: state.web3.account,
redeeming: state.redeem.loading, redeeming: state.redeem.loading,
redeemError: state.redeem.error, redeemError: state.redeem.error,

View File

@ -8,4 +8,4 @@ export const config: Config = {
web3: undefined web3: undefined
}; };
export const redeemPath = "/redeem/:bucketAddress/:recipientAddress"; export const redeemablePath = "/buckets/:bucketAddress/redeemables/:recipientAddress";

View File

@ -11,8 +11,8 @@ import { createHashHistory } from 'history';
import ErrorBoundary from './components/ErrorBoundary'; import ErrorBoundary from './components/ErrorBoundary';
import App from './components/App'; import App from './components/App';
import Home from './components/Home'; import Home from './components/Home';
import Redeem from './components/Redeem'; import Redeemable from './components/Redeemable';
import { redeemPath } from './config'; import { redeemablePath } from './config';
const logger: Middleware = ({ getState }: MiddlewareAPI) => (next: Dispatch) => action => { const logger: Middleware = ({ getState }: MiddlewareAPI) => (next: Dispatch) => action => {
console.log('will dispatch', action); console.log('will dispatch', action);
@ -49,7 +49,7 @@ ReactDOM.render(
<ConnectedRouter history={history}> <ConnectedRouter history={history}>
<Switch> <Switch>
<Route exact path="/"><Home /></Route> <Route exact path="/"><Home /></Route>
<Route exact path={redeemPath}><Redeem /></Route> <Route exact path={redeemablePath}><Redeemable /></Route>
<Route render={() => "page not found"} /> <Route render={() => "page not found"} />
</Switch> </Switch>
</ConnectedRouter> </ConnectedRouter>

View File

@ -6,9 +6,9 @@ import {
web3Reducer, web3Reducer,
} from './web3'; } from './web3';
import { import {
BucketState, RedeemableState,
bucketReducer, redeemableReducer,
} from './bucket'; } from './redeemable';
import { import {
RedeemState, RedeemState,
redeemReducer, redeemReducer,
@ -16,7 +16,7 @@ import {
export interface RootState { export interface RootState {
web3: Web3State, web3: Web3State,
bucket: BucketState, redeemable: RedeemableState,
redeem: RedeemState, redeem: RedeemState,
} }
@ -24,7 +24,7 @@ export default function(history: History) {
return combineReducers({ return combineReducers({
web3: web3Reducer, web3: web3Reducer,
router: connectRouter(history), router: connectRouter(history),
bucket: bucketReducer, redeemable: redeemableReducer,
redeem: redeemReducer, redeem: redeemReducer,
}); });
} }

View File

@ -6,9 +6,9 @@ import {
REDEEM_DONE, REDEEM_DONE,
} from "../actions/redeem"; } from "../actions/redeem";
import { import {
BucketRedeemableLoadingAction, RedeemableLoadingAction,
BUCKET_REDEEMABLE_LOADING REDEEMABLE_LOADING
} from "../actions/bucket"; } from "../actions/redeemable";
export interface RedeemState { export interface RedeemState {
loading: boolean loading: boolean
@ -24,9 +24,9 @@ const initialState: RedeemState = {
receiver: undefined, receiver: undefined,
} }
export const redeemReducer = (state: RedeemState = initialState, action: RedeemActions | BucketRedeemableLoadingAction): RedeemState => { export const redeemReducer = (state: RedeemState = initialState, action: RedeemActions | RedeemableLoadingAction): RedeemState => {
switch (action.type) { switch (action.type) {
case BUCKET_REDEEMABLE_LOADING: { case REDEEMABLE_LOADING: {
return initialState; return initialState;
} }

View File

@ -1,31 +1,31 @@
import { import {
Token, Token,
BucketActions, RedeemableActions,
BucketErrors, RedeemableErrors,
BUCKET_REDEEMABLE_LOADING, REDEEMABLE_LOADING,
BUCKET_REDEEMABLE_LOADING_ERROR, REDEEMABLE_LOADING_ERROR,
BUCKET_REDEEMABLE_NOT_FOUND, REDEEMABLE_NOT_FOUND,
BUCKET_REDEEMABLE_LOADED, REDEEMABLE_LOADED,
BUCKET_TOKEN_LOADING, TOKEN_LOADING,
BUCKET_TOKEN_LOADED, TOKEN_LOADED,
BUCKET_TOKEN_METADATA_LOADING, TOKEN_METADATA_LOADING,
BUCKET_TOKEN_METADATA_LOADED, TOKEN_METADATA_LOADED,
} from "../actions/bucket"; } from "../actions/redeemable";
export interface BucketState { export interface RedeemableState {
loading: boolean loading: boolean
address: string | undefined address: string | undefined
expirationTime: number | undefined expirationTime: number | undefined
tokenAddress: string | undefined tokenAddress: string | undefined
token: Token | undefined token: Token | undefined
loadingTokenMetadata: boolean loadingTokenMetadata: boolean
error: BucketErrors | undefined error: RedeemableErrors | undefined
recipient: string | undefined recipient: string | undefined
amount: string | undefined amount: string | undefined
codeHash: string | undefined codeHash: string | undefined
} }
const initialState: BucketState = { const initialState: RedeemableState = {
loading: false, loading: false,
address: undefined, address: undefined,
expirationTime: undefined, expirationTime: undefined,
@ -38,9 +38,9 @@ const initialState: BucketState = {
codeHash: undefined, codeHash: undefined,
} }
export const bucketReducer = (state: BucketState = initialState, action: BucketActions): BucketState => { export const redeemableReducer = (state: RedeemableState = initialState, action: RedeemableActions): RedeemableState => {
switch (action.type) { switch (action.type) {
case BUCKET_REDEEMABLE_LOADING: { case REDEEMABLE_LOADING: {
return { return {
...initialState, ...initialState,
loading: true, loading: true,
@ -49,7 +49,7 @@ export const bucketReducer = (state: BucketState = initialState, action: BucketA
} }
} }
case BUCKET_REDEEMABLE_LOADING_ERROR: { case REDEEMABLE_LOADING_ERROR: {
return { return {
...initialState, ...initialState,
loading: false, loading: false,
@ -57,7 +57,7 @@ export const bucketReducer = (state: BucketState = initialState, action: BucketA
} }
} }
case BUCKET_REDEEMABLE_NOT_FOUND: { case REDEEMABLE_NOT_FOUND: {
return { return {
...state, ...state,
loading: false, loading: false,
@ -65,7 +65,7 @@ export const bucketReducer = (state: BucketState = initialState, action: BucketA
} }
} }
case BUCKET_REDEEMABLE_LOADED: { case REDEEMABLE_LOADED: {
return { return {
...state, ...state,
loading: false, loading: false,
@ -76,21 +76,21 @@ export const bucketReducer = (state: BucketState = initialState, action: BucketA
} }
} }
case BUCKET_TOKEN_LOADING: { case TOKEN_LOADING: {
return { return {
...state, ...state,
tokenAddress: action.address, tokenAddress: action.address,
} }
} }
case BUCKET_TOKEN_LOADED: { case TOKEN_LOADED: {
return { return {
...state, ...state,
token: action.token, token: action.token,
} }
} }
case BUCKET_TOKEN_METADATA_LOADING: { case TOKEN_METADATA_LOADING: {
if (action.tokenAddress !== state.tokenAddress || action.recipient !== state.recipient) { if (action.tokenAddress !== state.tokenAddress || action.recipient !== state.recipient) {
// bucket or recipient changed before starting loading // bucket or recipient changed before starting loading
return state; return state;
@ -102,7 +102,7 @@ export const bucketReducer = (state: BucketState = initialState, action: BucketA
} }
} }
case BUCKET_TOKEN_METADATA_LOADED: { case TOKEN_METADATA_LOADED: {
if (action.tokenAddress !== state.tokenAddress || action.recipient !== state.recipient) { if (action.tokenAddress !== state.tokenAddress || action.recipient !== state.recipient) {
// bucket or recipient changed after starting loading // bucket or recipient changed after starting loading
return state; return state;

View File

@ -3,7 +3,7 @@ import BN from "bn.js";
import { import {
Token, Token,
TokenERC20, TokenERC20,
} from "./actions/bucket"; } from "./actions/redeemable";
// keccak256("") // keccak256("")
export const KECCAK_EMPTY_STRING = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"; export const KECCAK_EMPTY_STRING = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470";