Skip to content

Commit

Permalink
feat(share): add share functionality for backup seed phrase
Browse files Browse the repository at this point in the history
  • Loading branch information
lgmarchi committed Dec 13, 2024
1 parent 18d9e2b commit d43abc4
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {
implementation project(':capacitor-filesystem')
implementation project(':capacitor-keyboard')
implementation project(':capacitor-screen-orientation')
implementation project(':capacitor-share')
implementation project(':capacitor-splash-screen')
}

Expand Down
3 changes: 3 additions & 0 deletions android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ project(':capacitor-keyboard').projectDir = new File('../node_modules/@capacitor
include ':capacitor-screen-orientation'
project(':capacitor-screen-orientation').projectDir = new File('../node_modules/@capacitor/screen-orientation/android')

include ':capacitor-share'
project(':capacitor-share').projectDir = new File('../node_modules/@capacitor/share/android')

include ':capacitor-splash-screen'
project(':capacitor-splash-screen').projectDir = new File('../node_modules/@capacitor/splash-screen/android')
1 change: 1 addition & 0 deletions ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def capacitor_pods
pod 'CapacitorFilesystem', :path => '../../node_modules/@capacitor/filesystem'
pod 'CapacitorKeyboard', :path => '../../node_modules/@capacitor/keyboard'
pod 'CapacitorScreenOrientation', :path => '../../node_modules/@capacitor/screen-orientation'
pod 'CapacitorShare', :path => '../../node_modules/@capacitor/share'
pod 'CapacitorSplashScreen', :path => '../../node_modules/@capacitor/splash-screen'
end

Expand Down
8 changes: 7 additions & 1 deletion ios/App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ PODS:
- Capacitor
- CapacitorScreenOrientation (6.0.3):
- Capacitor
- CapacitorShare (6.0.3):
- Capacitor
- CapacitorSplashScreen (6.0.2):
- Capacitor

Expand All @@ -26,6 +28,7 @@ DEPENDENCIES:
- "CapacitorFilesystem (from `../../node_modules/@capacitor/filesystem`)"
- "CapacitorKeyboard (from `../../node_modules/@capacitor/keyboard`)"
- "CapacitorScreenOrientation (from `../../node_modules/@capacitor/screen-orientation`)"
- "CapacitorShare (from `../../node_modules/@capacitor/share`)"
- "CapacitorSplashScreen (from `../../node_modules/@capacitor/splash-screen`)"

EXTERNAL SOURCES:
Expand All @@ -45,6 +48,8 @@ EXTERNAL SOURCES:
:path: "../../node_modules/@capacitor/keyboard"
CapacitorScreenOrientation:
:path: "../../node_modules/@capacitor/screen-orientation"
CapacitorShare:
:path: "../../node_modules/@capacitor/share"
CapacitorSplashScreen:
:path: "../../node_modules/@capacitor/splash-screen"

Expand All @@ -57,8 +62,9 @@ SPEC CHECKSUMS:
CapacitorFilesystem: c832a3f6d4870c3872688e782ae8e33665e6ecbf
CapacitorKeyboard: 460c6f9ec5e52c84f2742d5ce2e67bbc7ab0ebb0
CapacitorScreenOrientation: 3bb823f5d265190301cdc5d58a568a287d98972a
CapacitorShare: 7af6ca761ce62030e8e9fbd2eb82416f5ceced38
CapacitorSplashScreen: 250df9ef8014fac5c7c1fd231f0f8b1d8f0b5624

PODFILE CHECKSUM: 0bfaa008b5f31bb57606a8c6259197a6af507ba4
PODFILE CHECKSUM: daefcb9f29d499a6633a575f4f00448532a7aeff

COCOAPODS: 1.16.2
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@capacitor/ios": "^6.2.0",
"@capacitor/keyboard": "^6.0.3",
"@capacitor/screen-orientation": "^6.0.3",
"@capacitor/share": "^6.0.3",
"@capacitor/splash-screen": "^6.0.2",
"@dicebear/collection": "^9.0.1",
"@dicebear/core": "^9.0.1",
Expand Down
1 change: 1 addition & 0 deletions src/lib/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
"title": "Backup your seed!",
"save_warning": "Please ensure you write down this message with all words recorded in the order they appear. It can be helpful to write down the numbers along with the words.",
"download": "Download Backup",
"share": "Share Backup Seed Phrase",
"next_step": "Next Step"
},
"new_account": {
Expand Down
27 changes: 24 additions & 3 deletions src/lib/layouts/login/RecoveryCopy.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
<script lang="ts">
import { goto } from "$app/navigation"
import { OrderedPhrase } from "$lib/components"
import Controls from "$lib/layouts/Controls.svelte"
import { Button, Icon, Text, Title } from "$lib/elements"
import { Appearance, Route, Shape } from "$lib/enums"
import { Appearance, Shape } from "$lib/enums"
import { _ } from "svelte-i18n"
import { createEventDispatcher } from "svelte"
import { TesseractStoreInstance } from "$lib/wasm/TesseractStore"
import { isAndroidOriOS } from "$lib/utils/Mobile"
import { Share } from "@capacitor/share"
import { log } from "$lib/utils/Logger"
const dispatch = createEventDispatcher()
let phrase = TesseractStoreInstance.fetchSeed()?.split(" ")
let loading = false
// Function to handle downloading the seed phrase as a txt file
function downloadPhrase() {
async function downloadPhrase() {
if (!phrase) return
// Join the phrase array into a single string
const phraseText = phrase.join(" ")
if (isAndroidOriOS()) {
await sharePhraseIfMobile(phraseText)
return
}
const blob = new Blob([phraseText], { type: "text/plain" })
const link = document.createElement("a")
Expand All @@ -31,6 +38,20 @@
URL.revokeObjectURL(link.href)
}
async function sharePhraseIfMobile(phraseText: string) {
try {
await Share.share({
title: $_("pages.auth.recovery.title"),
text: phraseText,
dialogTitle: $_("pages.auth.recovery.share"),
})
log.info("Seed phrase shared successfully")
} catch (error) {
log.error("Error to share seed phrase:", error)
}
}
</script>

<div id="auth-recover">
Expand Down

0 comments on commit d43abc4

Please sign in to comment.