mirror of
https://github.com/status-im/keycard-redeem.git
synced 2025-02-05 16:53:35 +00:00
rename js "names" from bucket to redeemable
This commit is contained in:
parent
bf00d10bd2
commit
dedc818388
@ -1,7 +1,7 @@
|
||||
import { RootState } from '../reducers';
|
||||
import { config } from "../config";
|
||||
import { Dispatch } from 'redux';
|
||||
import { newBucketContract } from "./bucket";
|
||||
import { newBucketContract } from "./redeemable";
|
||||
import { sha3 } from "web3-utils";
|
||||
import { recoverTypedSignature } from 'eth-sig-util';
|
||||
import { Web3Type } from "../actions/web3";
|
||||
@ -117,7 +117,7 @@ export const redeem = (bucketAddress: string, recipientAddress: string, cleanCod
|
||||
const domainName = isERC20 ? "KeycardERC20Bucket" : "KeycardNFTBucket";
|
||||
//FIXME: is signer needed?
|
||||
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()) {
|
||||
//FIXME: handle error
|
||||
dispatch(wrongSigner(recipient, address));
|
||||
|
@ -18,7 +18,7 @@ export interface ErrLoadingRedeemable {
|
||||
message: string
|
||||
}
|
||||
|
||||
export type BucketErrors =
|
||||
export type RedeemableErrors =
|
||||
ErrRedeemableNotFound |
|
||||
ErrLoadingRedeemable;
|
||||
|
||||
@ -31,37 +31,37 @@ const errLoadingRedeemable = (message: string): ErrLoadingRedeemable => ({
|
||||
message,
|
||||
});
|
||||
|
||||
export const BUCKET_REDEEMABLE_LOADING = "BUCKET_REDEEMABLE_LOADING";
|
||||
export interface BucketRedeemableLoadingAction {
|
||||
type: typeof BUCKET_REDEEMABLE_LOADING
|
||||
export const REDEEMABLE_LOADING = "REDEEMABLE_LOADING";
|
||||
export interface RedeemableLoadingAction {
|
||||
type: typeof REDEEMABLE_LOADING
|
||||
address: string
|
||||
recipient: string
|
||||
}
|
||||
|
||||
export const BUCKET_REDEEMABLE_LOADING_ERROR = "BUCKET_REDEEMABLE_LOADING_ERROR";
|
||||
export interface BucketRedeemableLoadingErrorAction {
|
||||
type: typeof BUCKET_REDEEMABLE_LOADING_ERROR
|
||||
export const REDEEMABLE_LOADING_ERROR = "REDEEMABLE_LOADING_ERROR";
|
||||
export interface RedeemableLoadingErrorAction {
|
||||
type: typeof REDEEMABLE_LOADING_ERROR
|
||||
error: ErrLoadingRedeemable
|
||||
}
|
||||
|
||||
export const BUCKET_REDEEMABLE_LOADED = "BUCKET_REDEEMABLE_LOADED";
|
||||
export interface BucketRedeemableLoadedAction {
|
||||
type: typeof BUCKET_REDEEMABLE_LOADED
|
||||
export const REDEEMABLE_LOADED = "REDEEMABLE_LOADED";
|
||||
export interface RedeemableLoadedAction {
|
||||
type: typeof REDEEMABLE_LOADED
|
||||
expirationTime: number
|
||||
recipient: string
|
||||
amount: string
|
||||
codeHash: string
|
||||
}
|
||||
|
||||
export const BUCKET_REDEEMABLE_NOT_FOUND = "BUCKET_REDEEMABLE_NOT_FOUND";
|
||||
export interface BucketRedeemableNotFoundAction {
|
||||
type: typeof BUCKET_REDEEMABLE_NOT_FOUND
|
||||
export const REDEEMABLE_NOT_FOUND = "REDEEMABLE_NOT_FOUND";
|
||||
export interface RedeemableNotFoundAction {
|
||||
type: typeof REDEEMABLE_NOT_FOUND
|
||||
error: ErrRedeemableNotFound
|
||||
}
|
||||
|
||||
export const BUCKET_TOKEN_LOADING = "BUCKET_TOKEN_LOADING";
|
||||
export interface BucketTokenLoadingAction {
|
||||
type: typeof BUCKET_TOKEN_LOADING
|
||||
export const TOKEN_LOADING = "TOKEN_LOADING";
|
||||
export interface TokenLoadingAction {
|
||||
type: typeof TOKEN_LOADING
|
||||
address: string
|
||||
}
|
||||
|
||||
@ -84,79 +84,79 @@ export interface TokenNFT {
|
||||
|
||||
export type Token = TokenERC20 | TokenNFT;
|
||||
|
||||
export const BUCKET_TOKEN_LOADED = "BUCKET_TOKEN_LOADED";
|
||||
export interface BucketTokenLoadedAction {
|
||||
type: typeof BUCKET_TOKEN_LOADED
|
||||
export const TOKEN_LOADED = "TOKEN_LOADED";
|
||||
export interface TokenLoadedAction {
|
||||
type: typeof TOKEN_LOADED
|
||||
token: Token,
|
||||
}
|
||||
|
||||
export const BUCKET_TOKEN_METADATA_LOADING = "BUCKET_TOKEN_METADATA_LOADING";
|
||||
export interface BucketTokenMetadataLoadingAction {
|
||||
type: typeof BUCKET_TOKEN_METADATA_LOADING
|
||||
export const TOKEN_METADATA_LOADING = "TOKEN_METADATA_LOADING";
|
||||
export interface TokenMetadataLoadingAction {
|
||||
type: typeof TOKEN_METADATA_LOADING
|
||||
tokenAddress: string
|
||||
recipient: string
|
||||
}
|
||||
|
||||
export const BUCKET_TOKEN_METADATA_LOADED = "BUCKET_TOKEN_METADATA_LOADED";
|
||||
export interface BucketTokenMetadataLoadedAction {
|
||||
type: typeof BUCKET_TOKEN_METADATA_LOADED
|
||||
export const TOKEN_METADATA_LOADED = "TOKEN_METADATA_LOADED";
|
||||
export interface TokenMetadataLoadedAction {
|
||||
type: typeof TOKEN_METADATA_LOADED
|
||||
tokenAddress: string
|
||||
recipient: string
|
||||
metadata: TokenNFTMetadata
|
||||
}
|
||||
|
||||
export type BucketActions =
|
||||
BucketRedeemableLoadingAction |
|
||||
BucketRedeemableLoadingErrorAction |
|
||||
BucketRedeemableLoadedAction |
|
||||
BucketRedeemableNotFoundAction |
|
||||
BucketTokenLoadingAction |
|
||||
BucketTokenLoadedAction |
|
||||
BucketTokenMetadataLoadingAction |
|
||||
BucketTokenMetadataLoadedAction;
|
||||
export type RedeemableActions =
|
||||
RedeemableLoadingAction |
|
||||
RedeemableLoadingErrorAction |
|
||||
RedeemableLoadedAction |
|
||||
RedeemableNotFoundAction |
|
||||
TokenLoadingAction |
|
||||
TokenLoadedAction |
|
||||
TokenMetadataLoadingAction |
|
||||
TokenMetadataLoadedAction;
|
||||
|
||||
export const loadingRedeemable = (address: string, recipient: string): BucketRedeemableLoadingAction => ({
|
||||
type: BUCKET_REDEEMABLE_LOADING,
|
||||
export const loadingRedeemable = (address: string, recipient: string): RedeemableLoadingAction => ({
|
||||
type: REDEEMABLE_LOADING,
|
||||
address,
|
||||
recipient,
|
||||
});
|
||||
|
||||
export const redeemableLoaded = (expirationTime: number, recipient: string, amount: string, codeHash: string): BucketRedeemableLoadedAction => ({
|
||||
type: BUCKET_REDEEMABLE_LOADED,
|
||||
export const redeemableLoaded = (expirationTime: number, recipient: string, amount: string, codeHash: string): RedeemableLoadedAction => ({
|
||||
type: REDEEMABLE_LOADED,
|
||||
expirationTime,
|
||||
recipient,
|
||||
amount,
|
||||
codeHash,
|
||||
});
|
||||
|
||||
export const redeemableNotFound = (): BucketRedeemableNotFoundAction => ({
|
||||
type: BUCKET_REDEEMABLE_NOT_FOUND,
|
||||
export const redeemableNotFound = (): RedeemableNotFoundAction => ({
|
||||
type: REDEEMABLE_NOT_FOUND,
|
||||
error: errRedeemableNotFound(),
|
||||
});
|
||||
|
||||
export const errorLoadingRedeemable = (errorMessage: string): BucketRedeemableLoadingErrorAction => ({
|
||||
type: BUCKET_REDEEMABLE_LOADING_ERROR,
|
||||
export const errorLoadingRedeemable = (errorMessage: string): RedeemableLoadingErrorAction => ({
|
||||
type: REDEEMABLE_LOADING_ERROR,
|
||||
error: errLoadingRedeemable(errorMessage),
|
||||
});
|
||||
|
||||
export const loadingToken = (address: string): BucketTokenLoadingAction => ({
|
||||
type: BUCKET_TOKEN_LOADING,
|
||||
export const loadingToken = (address: string): TokenLoadingAction => ({
|
||||
type: TOKEN_LOADING,
|
||||
address,
|
||||
});
|
||||
|
||||
export const tokenLoaded = (token: Token): BucketTokenLoadedAction => ({
|
||||
type: BUCKET_TOKEN_LOADED,
|
||||
export const tokenLoaded = (token: Token): TokenLoadedAction => ({
|
||||
type: TOKEN_LOADED,
|
||||
token,
|
||||
});
|
||||
|
||||
export const loadingTokenMetadata = (tokenAddress: string, recipient: string): BucketTokenMetadataLoadingAction => ({
|
||||
type: BUCKET_TOKEN_METADATA_LOADING,
|
||||
export const loadingTokenMetadata = (tokenAddress: string, recipient: string): TokenMetadataLoadingAction => ({
|
||||
type: TOKEN_METADATA_LOADING,
|
||||
tokenAddress,
|
||||
recipient,
|
||||
});
|
||||
|
||||
export const tokenMetadataLoaded = (tokenAddress: string, recipient: string, metadata: TokenNFTMetadata): BucketTokenMetadataLoadedAction => ({
|
||||
type: BUCKET_TOKEN_METADATA_LOADED,
|
||||
export const tokenMetadataLoaded = (tokenAddress: string, recipient: string, metadata: TokenNFTMetadata): TokenMetadataLoadedAction => ({
|
||||
type: TOKEN_METADATA_LOADED,
|
||||
tokenAddress,
|
||||
recipient,
|
||||
metadata,
|
@ -6,15 +6,15 @@ import {
|
||||
useSelector,
|
||||
useDispatch,
|
||||
} from 'react-redux';
|
||||
import { redeemPath } from '../config';
|
||||
import { redeemablePath } from '../config';
|
||||
import {
|
||||
TokenERC20,
|
||||
TokenNFT,
|
||||
loadRedeemable,
|
||||
BucketErrors,
|
||||
RedeemableErrors,
|
||||
ERROR_LOADING_REDEEMABLE,
|
||||
ERROR_REDEEMABLE_NOT_FOUND,
|
||||
} from '../actions/bucket';
|
||||
} from '../actions/redeemable';
|
||||
import {
|
||||
toBaseUnit,
|
||||
KECCAK_EMPTY_STRING2,
|
||||
@ -27,7 +27,7 @@ import {
|
||||
ERROR_WRONG_SIGNER,
|
||||
} from '../actions/redeem';
|
||||
|
||||
const buckerErrorMessage = (error: BucketErrors): string => {
|
||||
const buckerErrorMessage = (error: RedeemableErrors): string => {
|
||||
switch (error.type) {
|
||||
case ERROR_LOADING_REDEEMABLE:
|
||||
return "couldn't load redeemable";
|
||||
@ -62,7 +62,7 @@ export default function(ownProps: any) {
|
||||
const dispatch = useDispatch()
|
||||
|
||||
const match = useRouteMatch<URLParams>({
|
||||
path: redeemPath,
|
||||
path: redeemablePath,
|
||||
exact: true,
|
||||
});
|
||||
|
||||
@ -75,16 +75,16 @@ export default function(ownProps: any) {
|
||||
|
||||
const props = useSelector((state: RootState) => {
|
||||
return {
|
||||
bucketAddress: state.bucket.address,
|
||||
loading: state.bucket.loading,
|
||||
expirationTime: state.bucket.expirationTime,
|
||||
error: state.bucket.error,
|
||||
recipient: state.bucket.recipient,
|
||||
amount: state.bucket.amount,
|
||||
codeHash: state.bucket.codeHash,
|
||||
tokenAddress: state.bucket.tokenAddress,
|
||||
token: state.bucket.token,
|
||||
loadingTokenMetadata: state.bucket.loadingTokenMetadata,
|
||||
bucketAddress: state.redeemable.address,
|
||||
loading: state.redeemable.loading,
|
||||
expirationTime: state.redeemable.expirationTime,
|
||||
error: state.redeemable.error,
|
||||
recipient: state.redeemable.recipient,
|
||||
amount: state.redeemable.amount,
|
||||
codeHash: state.redeemable.codeHash,
|
||||
tokenAddress: state.redeemable.tokenAddress,
|
||||
token: state.redeemable.token,
|
||||
loadingTokenMetadata: state.redeemable.loadingTokenMetadata,
|
||||
receiver: state.web3.account,
|
||||
redeeming: state.redeem.loading,
|
||||
redeemError: state.redeem.error,
|
@ -8,4 +8,4 @@ export const config: Config = {
|
||||
web3: undefined
|
||||
};
|
||||
|
||||
export const redeemPath = "/redeem/:bucketAddress/:recipientAddress";
|
||||
export const redeemablePath = "/buckets/:bucketAddress/redeemables/:recipientAddress";
|
||||
|
@ -11,8 +11,8 @@ import { createHashHistory } from 'history';
|
||||
import ErrorBoundary from './components/ErrorBoundary';
|
||||
import App from './components/App';
|
||||
import Home from './components/Home';
|
||||
import Redeem from './components/Redeem';
|
||||
import { redeemPath } from './config';
|
||||
import Redeemable from './components/Redeemable';
|
||||
import { redeemablePath } from './config';
|
||||
|
||||
const logger: Middleware = ({ getState }: MiddlewareAPI) => (next: Dispatch) => action => {
|
||||
console.log('will dispatch', action);
|
||||
@ -49,7 +49,7 @@ ReactDOM.render(
|
||||
<ConnectedRouter history={history}>
|
||||
<Switch>
|
||||
<Route exact path="/"><Home /></Route>
|
||||
<Route exact path={redeemPath}><Redeem /></Route>
|
||||
<Route exact path={redeemablePath}><Redeemable /></Route>
|
||||
<Route render={() => "page not found"} />
|
||||
</Switch>
|
||||
</ConnectedRouter>
|
||||
|
@ -6,9 +6,9 @@ import {
|
||||
web3Reducer,
|
||||
} from './web3';
|
||||
import {
|
||||
BucketState,
|
||||
bucketReducer,
|
||||
} from './bucket';
|
||||
RedeemableState,
|
||||
redeemableReducer,
|
||||
} from './redeemable';
|
||||
import {
|
||||
RedeemState,
|
||||
redeemReducer,
|
||||
@ -16,7 +16,7 @@ import {
|
||||
|
||||
export interface RootState {
|
||||
web3: Web3State,
|
||||
bucket: BucketState,
|
||||
redeemable: RedeemableState,
|
||||
redeem: RedeemState,
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ export default function(history: History) {
|
||||
return combineReducers({
|
||||
web3: web3Reducer,
|
||||
router: connectRouter(history),
|
||||
bucket: bucketReducer,
|
||||
redeemable: redeemableReducer,
|
||||
redeem: redeemReducer,
|
||||
});
|
||||
}
|
||||
|
@ -6,9 +6,9 @@ import {
|
||||
REDEEM_DONE,
|
||||
} from "../actions/redeem";
|
||||
import {
|
||||
BucketRedeemableLoadingAction,
|
||||
BUCKET_REDEEMABLE_LOADING
|
||||
} from "../actions/bucket";
|
||||
RedeemableLoadingAction,
|
||||
REDEEMABLE_LOADING
|
||||
} from "../actions/redeemable";
|
||||
|
||||
export interface RedeemState {
|
||||
loading: boolean
|
||||
@ -24,9 +24,9 @@ const initialState: RedeemState = {
|
||||
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) {
|
||||
case BUCKET_REDEEMABLE_LOADING: {
|
||||
case REDEEMABLE_LOADING: {
|
||||
return initialState;
|
||||
}
|
||||
|
||||
|
@ -1,31 +1,31 @@
|
||||
import {
|
||||
Token,
|
||||
BucketActions,
|
||||
BucketErrors,
|
||||
BUCKET_REDEEMABLE_LOADING,
|
||||
BUCKET_REDEEMABLE_LOADING_ERROR,
|
||||
BUCKET_REDEEMABLE_NOT_FOUND,
|
||||
BUCKET_REDEEMABLE_LOADED,
|
||||
BUCKET_TOKEN_LOADING,
|
||||
BUCKET_TOKEN_LOADED,
|
||||
BUCKET_TOKEN_METADATA_LOADING,
|
||||
BUCKET_TOKEN_METADATA_LOADED,
|
||||
} from "../actions/bucket";
|
||||
RedeemableActions,
|
||||
RedeemableErrors,
|
||||
REDEEMABLE_LOADING,
|
||||
REDEEMABLE_LOADING_ERROR,
|
||||
REDEEMABLE_NOT_FOUND,
|
||||
REDEEMABLE_LOADED,
|
||||
TOKEN_LOADING,
|
||||
TOKEN_LOADED,
|
||||
TOKEN_METADATA_LOADING,
|
||||
TOKEN_METADATA_LOADED,
|
||||
} from "../actions/redeemable";
|
||||
|
||||
export interface BucketState {
|
||||
export interface RedeemableState {
|
||||
loading: boolean
|
||||
address: string | undefined
|
||||
expirationTime: number | undefined
|
||||
tokenAddress: string | undefined
|
||||
token: Token | undefined
|
||||
loadingTokenMetadata: boolean
|
||||
error: BucketErrors | undefined
|
||||
error: RedeemableErrors | undefined
|
||||
recipient: string | undefined
|
||||
amount: string | undefined
|
||||
codeHash: string | undefined
|
||||
}
|
||||
|
||||
const initialState: BucketState = {
|
||||
const initialState: RedeemableState = {
|
||||
loading: false,
|
||||
address: undefined,
|
||||
expirationTime: undefined,
|
||||
@ -38,9 +38,9 @@ const initialState: BucketState = {
|
||||
codeHash: undefined,
|
||||
}
|
||||
|
||||
export const bucketReducer = (state: BucketState = initialState, action: BucketActions): BucketState => {
|
||||
export const redeemableReducer = (state: RedeemableState = initialState, action: RedeemableActions): RedeemableState => {
|
||||
switch (action.type) {
|
||||
case BUCKET_REDEEMABLE_LOADING: {
|
||||
case REDEEMABLE_LOADING: {
|
||||
return {
|
||||
...initialState,
|
||||
loading: true,
|
||||
@ -49,7 +49,7 @@ export const bucketReducer = (state: BucketState = initialState, action: BucketA
|
||||
}
|
||||
}
|
||||
|
||||
case BUCKET_REDEEMABLE_LOADING_ERROR: {
|
||||
case REDEEMABLE_LOADING_ERROR: {
|
||||
return {
|
||||
...initialState,
|
||||
loading: false,
|
||||
@ -57,7 +57,7 @@ export const bucketReducer = (state: BucketState = initialState, action: BucketA
|
||||
}
|
||||
}
|
||||
|
||||
case BUCKET_REDEEMABLE_NOT_FOUND: {
|
||||
case REDEEMABLE_NOT_FOUND: {
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
@ -65,7 +65,7 @@ export const bucketReducer = (state: BucketState = initialState, action: BucketA
|
||||
}
|
||||
}
|
||||
|
||||
case BUCKET_REDEEMABLE_LOADED: {
|
||||
case REDEEMABLE_LOADED: {
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
@ -76,21 +76,21 @@ export const bucketReducer = (state: BucketState = initialState, action: BucketA
|
||||
}
|
||||
}
|
||||
|
||||
case BUCKET_TOKEN_LOADING: {
|
||||
case TOKEN_LOADING: {
|
||||
return {
|
||||
...state,
|
||||
tokenAddress: action.address,
|
||||
}
|
||||
}
|
||||
|
||||
case BUCKET_TOKEN_LOADED: {
|
||||
case TOKEN_LOADED: {
|
||||
return {
|
||||
...state,
|
||||
token: action.token,
|
||||
}
|
||||
}
|
||||
|
||||
case BUCKET_TOKEN_METADATA_LOADING: {
|
||||
case TOKEN_METADATA_LOADING: {
|
||||
if (action.tokenAddress !== state.tokenAddress || action.recipient !== state.recipient) {
|
||||
// bucket or recipient changed before starting loading
|
||||
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) {
|
||||
// bucket or recipient changed after starting loading
|
||||
return state;
|
@ -3,7 +3,7 @@ import BN from "bn.js";
|
||||
import {
|
||||
Token,
|
||||
TokenERC20,
|
||||
} from "./actions/bucket";
|
||||
} from "./actions/redeemable";
|
||||
|
||||
// keccak256("")
|
||||
export const KECCAK_EMPTY_STRING = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470";
|
||||
|
Loading…
x
Reference in New Issue
Block a user