-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updated react shopper hooks to use common elements from shopper…
… common
- Loading branch information
Showing
25 changed files
with
151 additions
and
132 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
6 changes: 4 additions & 2 deletions
6
packages/react-shopper-hooks/lib/cart/types/cart-reducer-types.ts
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
29 changes: 18 additions & 11 deletions
29
packages/react-shopper-hooks/lib/payment-gateway-register/use-payment-gateway.ts
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,34 +1,41 @@ | ||
import { useContext } from "react"; | ||
import { PGRContext } from "./payment-gateway-provider"; | ||
import { useContext } from "react" | ||
import { PGRContext } from "./payment-gateway-provider" | ||
import { | ||
PGRAction, | ||
PGRState, | ||
ResolvePaymentFunction, | ||
SupportedGateway, | ||
} from "./types/payment-gateway-reducer-types"; | ||
} from "./types/payment-gateway-reducer-types" | ||
|
||
export function usePaymentGateway() { | ||
const context = useContext(PGRContext); | ||
export function usePaymentGateway(): { | ||
registerGateway: ( | ||
resolvePayment: ResolvePaymentFunction, | ||
type: SupportedGateway, | ||
) => void | ||
state: PGRState | ||
} { | ||
const context = useContext(PGRContext) | ||
|
||
if (context === undefined) { | ||
throw new Error("usePaymentGateway must be used within a PGRProvider"); | ||
throw new Error("usePaymentGateway must be used within a PGRProvider") | ||
} | ||
|
||
const { state, dispatch } = context; | ||
const { state, dispatch } = context | ||
|
||
return { | ||
registerGateway: _registerGateway(dispatch), | ||
state, | ||
}; | ||
} | ||
} | ||
|
||
function _registerGateway(dispatch: (action: PGRAction) => void) { | ||
return ( | ||
resolvePayment: ResolvePaymentFunction, | ||
type: SupportedGateway | ||
type: SupportedGateway, | ||
): void => { | ||
dispatch({ | ||
type: "update-payment-gateway-register", | ||
payload: { type, resolvePayment }, | ||
}); | ||
}; | ||
}) | ||
} | ||
} |
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,6 +1,4 @@ | ||
export * from "./bundle-provider" | ||
export * from "./use-bundle-hook" | ||
export * from "./util/create-bundle-configure-validator" | ||
export * from "./use-bundle-component-options-hook" | ||
export * from "./bundle.types" | ||
export * from "./use-bundle-component-hook" |
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.