Skip to content

Commit

Permalink
adde Private Key filed under account
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Mar 18, 2024
1 parent 15daacd commit e40d733
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
40 changes: 40 additions & 0 deletions app/screens/account/account-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const AccountScreen: React.FC<Props> = ({ navigation }) => {
const [did, setDID] = useState(null)
const [poolOptions, setPoolOptions] = useState([])
const [cid, setCid] = useState<string | null>(null);
const [pk, setPk] = useState<string | null>(null);
const getCid = async () => {
try {
const cid_ = await AsyncStorage.getItem('@lastUploadedCid');
Expand All @@ -69,6 +70,18 @@ export const AccountScreen: React.FC<Props> = ({ navigation }) => {
}
};

const getPk = async () => {
try {
const _pk = await helper.getMyDIDKeyPair(dIDCredentials.username, dIDCredentials.password);
const identity = _pk.secretKey.toString();
if (identity) {
setPk(identity)
}
} catch (e) {
// error reading value
}
};

useEffect(() => {
if (!fulaPeerId) {
loadPeerId()
Expand Down Expand Up @@ -407,6 +420,32 @@ export const AccountScreen: React.FC<Props> = ({ navigation }) => {
</ListItem.Content>
</ListItem>
);

const copyToClipboardPrivateKey = (pkValue: string) => {
Clipboard.setString(pkValue);
Toast.show({
type: 'success',
text1: 'Your Private Key copied to the clipboard!',
position: 'bottom',
bottomOffset: 0,
});
};
const renderPrivateKeyListItem = () => (
<ListItem onPress={() => cid && copyToClipboardPrivateKey(pk)} containerStyle={{ width: '100%' }}>
<ListItem.Content>
<View style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
<Card.Title style={{ textAlign: 'left', paddingRight: 10 }}>
Private Key
</Card.Title>
<Icon name="content-copy" type="material-community" onPress={() => pk && copyToClipboardPrivateKey(pk)} />
</View>
<Icon name="refresh" type="material-community" onPress={getPk} />
</View>
<ListItem.Subtitle>{pk || 'No Private Key Available'}</ListItem.Subtitle>
</ListItem.Content>
</ListItem>
);
return (
<Screen preset="scroll" style={styles.screen}>
{renderHeader()}
Expand Down Expand Up @@ -464,6 +503,7 @@ export const AccountScreen: React.FC<Props> = ({ navigation }) => {
</ListItem.Content>
</ListItem>
{renderCIDListItem()}
{renderPrivateKeyListItem()}
<ListItem
onPress={() =>
fulaAccount
Expand Down
6 changes: 4 additions & 2 deletions app/services/sync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ const uploadAssetBackgroundTask = async (taskParameters?: TaskParams) => {
if (!api) {
api = await chainApi.init()
fulaAccount = await chainApi.getAccountIdFromSeed(fulaAccountSeed)
while (gasBalance <= 1000000) {
while (gasBalance <= 10000000) {
let gasBalanceStr = await chainApi.checkAccountBalance(api, fulaAccount)
if (gasBalanceStr) {
gasBalance = parseInt(gasBalanceStr)
}
if (gasBalance <= 1000000){
if (gasBalance <= 10000000){
await BackgroundJob.updateNotification({
taskTitle: `Waiting for enough gas balance in ${fulaAccount}`,
taskDesc: `Uploads are resumed as soon as gas balance is enough ...`,
Expand Down Expand Up @@ -521,6 +521,8 @@ export const initFula = async (
}
console.log('blox Address created: '+ bloxAddr)
}
console.log('identity:')
console.log(identity)
const fulaInit = await fula.init(
identity, //bytes of the privateKey of did identity in string format
storePath, // leave empty to use the default temp one
Expand Down

0 comments on commit e40d733

Please sign in to comment.