Skip to content

Commit c5d39e4

Browse files
committed
Runtime guard for invalid buttonType indexing (prevents crash + normalizes prop)
(cherry picked from commit 79d23999de7ac1a3863e881737dc746829d14e97)
1 parent a17cde7 commit c5d39e4

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/AddToWalletButton.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const BUTTON_DIMENSIONS = {
3232

3333
function AddToWalletButton({style, buttonStyle = 'black', buttonType = 'basic', borderRadius = 4, onPress}: Props) {
3434
const flattenedStyle = StyleSheet.flatten(style) || {};
35-
const currentDimensions = BUTTON_DIMENSIONS[buttonType][Platform.OS as 'ios' | 'android'];
35+
const safeButtonType: ButtonType = buttonType === 'badge' ? 'badge' : 'basic';
36+
const currentDimensions = BUTTON_DIMENSIONS[safeButtonType][Platform.OS as 'ios' | 'android'];
3637
const {width = currentDimensions.width, height = currentDimensions.height, ...rest} = flattenedStyle;
3738

3839
return (
@@ -55,7 +56,7 @@ function AddToWalletButton({style, buttonStyle = 'black', buttonType = 'basic',
5556
style={styles.fill}
5657
buttonStyle={buttonStyle}
5758
borderRadius={borderRadius}
58-
buttonType={buttonType}
59+
buttonType={safeButtonType}
5960
/>
6061
</TouchableOpacity>
6162
);

0 commit comments

Comments
 (0)