Skip to content

Commit

Permalink
Satscard: add wait unlock for rate-limited cards
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Apr 13, 2023
1 parent bde59d3 commit fccd32c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"views.Satscard.slotStatus": "Slot status",
"views.Satscard.generateAddress": "Generate address",
"views.Satscard.tapsignerNotSupported": "Tapsigner not supported",
"views.Satscard.wait": "Wait and unlock rate-limited card",
"views.Settings.AddEditNode.certificateButton": "Certificate Install Instructions",
"views.Settings.AddEditNode.nodeConfig": "Node Configuration",
"views.Settings.AddEditNode.connectionStringClipboard": "Detected the following connection string in your clipboard",
Expand Down
57 changes: 54 additions & 3 deletions views/Settings/Satscard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface SatscardState {
selectedSlot: number;
selectedSlotIndex: number;
selectedSlotStatus: string;
rateLimited: boolean;
}

interface CardStatus {
Expand Down Expand Up @@ -74,7 +75,8 @@ export default class Satscard extends React.Component<
privkey: '',
slotStatus: '',
tapsignerError: false,
error: ''
error: '',
rateLimited: false
};
}

Expand All @@ -101,7 +103,8 @@ export default class Satscard extends React.Component<
error,
selectedSlot,
selectedSlotIndex,
selectedSlotStatus
selectedSlotStatus,
rateLimited
} = this.state;

const BackButton = () => (
Expand Down Expand Up @@ -561,7 +564,55 @@ export default class Satscard extends React.Component<
error:
err.error ||
err.message ||
err.toString()
err.toString(),
rateLimited:
err.toString() ===
'Error: 429 on dump: rate limited'
});
}

if (Platform.OS === 'android') {
await card.endNfcSession();
ModalStore.toggleAndroidNfcModal(false);
}
}}
/>
</View>
)}
{!cardStatus && rateLimited && (
<View style={styles.button}>
<Button
title={localeString('views.Satscard.wait')}
onPress={async () => {
try {
awaitNfc();
await card.nfcWrapper(async () => {
const status = await card.first_look();
if (status.auth_delay) {
for (let i = 0; i < status.auth_delay; i++) {
await card.wait();
}
}
});

this.setState({
rateLimited: false
});

if (Platform.OS === 'android') {
ModalStore.toggleAndroidNfcModal(
false
);
}
} catch (err) {
this.setState({
error:
err.error ||
err.message ||
err.toString(),
rateLimited:
err.toString() ===
'Error: 429 on dump: rate limited'
});
}

Expand Down

0 comments on commit fccd32c

Please sign in to comment.