Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/stable'
Browse files Browse the repository at this point in the history
To bring the readonly ETH-token accounts removal operation.
  • Loading branch information
knocte authored and Mersho committed Feb 22, 2024
2 parents 279ff02 + 6d42a93 commit d9f316b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 13 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,14 @@ jobs:
# retry 3 times because of flakey nuget; TODO: remove retry when we migrate to .NET6 (removing LEGACY_FRAMEWORK support)
./scripts/snap_build.sh || ./scripts/snap_build.sh || ./scripts/snap_build.sh || ./scripts/snap_build.sh
- name: Find the snap file's path and name
id: find_snap_file
run: |
FILEPATH=$(ls *.snap)
FILENAME=$(basename $FILEPATH)
echo "file_path=$FILEPATH" >> $GITHUB_OUTPUT
echo "file_name=$FILENAME" >> $GITHUB_OUTPUT
- name: Install snap
# dangerous because it's a local snap (not one from the SnapStore)
run: sudo snap install --dangerous *.snap
Expand All @@ -535,6 +543,18 @@ jobs:
sudo apt update
./scripts/snap_release.sh
- name: Prepare release
id: prepare
if: startsWith(github.ref, 'refs/tags/')
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

snap_pkg_beta:

needs:
Expand Down Expand Up @@ -565,6 +585,14 @@ jobs:
# retry 3 times because of flakey nuget; TODO: remove retry when we migrate to .NET6 (removing LEGACY_FRAMEWORK support)
./scripts/snap_build.sh --native-segwit || ./scripts/snap_build.sh --native-segwit || ./scripts/snap_build.sh --native-segwit || ./scripts/snap_build.sh --native-segwit
- name: Find the snap file's path and name
id: find_snap_beta_file
run: |
FILEPATH=$(ls *.snap)
FILENAME=$(basename $FILEPATH)
echo "file_path=$FILEPATH" >> $GITHUB_OUTPUT
echo "file_name=$FILENAME" >> $GITHUB_OUTPUT
- name: Install snap
# dangerous because it's a local snap (not one from the SnapStore)
run: sudo snap install --dangerous *.snap
Expand All @@ -584,3 +612,15 @@ jobs:
run: |
sudo apt update
./scripts/snap_release.sh beta
- name: Prepare release
id: prepare
if: startsWith(github.ref, 'refs/tags/')
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
33 changes: 25 additions & 8 deletions src/GWallet.Backend/Config.fs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ module Config =
configDir.Create()
configDir

let private GetConfigDir (currency: Currency) (accountKind: AccountKind) =
let private GetConfigDirInternal (currency: Currency) (accountKind: AccountKind) (createIfNotAlreadyExisting: bool): Option<DirectoryInfo> =
let accountConfigDir = GetConfigDirForAccounts().FullName

let baseConfigDir =
Expand All @@ -114,8 +114,18 @@ module Config =

let configDir = Path.Combine(baseConfigDir, currency.ToString()) |> DirectoryInfo
if not configDir.Exists then
configDir.Create()
configDir
if createIfNotAlreadyExisting then
configDir.Create()
Some configDir
else
None
else
Some configDir

let private GetConfigDir (currency: Currency) (accountKind: AccountKind) =
match GetConfigDirInternal currency accountKind true with
| Some dir -> dir
| None -> failwith "Unreachable, after invoking with createIfNotAlreadyExisting=true, it should return Some"

// In case a new token was added it will not have a config for an existing user
// we copy the eth configs to the new tokens config directory
Expand All @@ -124,11 +134,18 @@ module Config =
let ethConfigDir = GetConfigDir Currency.ETH accountKind
for token in Currency.GetAll() do
if token.IsEthToken() then
let tokenConfigDir = GetConfigDir token accountKind
for ethAccountFilePath in Directory.GetFiles ethConfigDir.FullName do
let newPath = ethAccountFilePath.Replace(ethConfigDir.FullName, tokenConfigDir.FullName)
if not (File.Exists newPath) then
File.Copy(ethAccountFilePath, newPath)
let maybeTokenConfigDir = GetConfigDirInternal token accountKind false
match maybeTokenConfigDir with
| Some _ ->
// already removed token account before
()
| None ->
// now create it if it wasn't there before
let tokenConfigDir = GetConfigDir token accountKind
for ethAccountFilePath in Directory.GetFiles ethConfigDir.FullName do
let newPath = ethAccountFilePath.Replace(ethConfigDir.FullName, tokenConfigDir.FullName)
if not (File.Exists newPath) then
File.Copy(ethAccountFilePath, newPath)

let GetAccountFiles (currencies: seq<Currency>) (accountKind: AccountKind): seq<FileRepresentation> =
seq {
Expand Down
11 changes: 6 additions & 5 deletions src/GWallet.Frontend.Console/UserInteraction.fs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ module UserInteraction =
| _ ->
DisplayAccountStatusInner accountNumber account maybeBalance maybeUsdValue

let private GetAccountBalanceInner (account: IAccount): Async<IAccount*MaybeCached<decimal>*MaybeCached<decimal>> =
let private GetAccountBalanceInner (account: IAccount) (showProgress: bool): Async<IAccount*MaybeCached<decimal>*MaybeCached<decimal>> =
async {
// The console frontend cannot really take much advantage of the Fast|Analysis distinction here (as
// opposed to the other frontends) because it doesn't have automatic balance refresh (it's this
Expand All @@ -253,21 +253,22 @@ module UserInteraction =
// we don't need to query the fiat value at all (micro-optimization?)
let! (balance,_),usdValue = FSharpUtil.AsyncExtensions.MixedParallel2 balanceJob usdValueJob

let progressIteration = sprintf " %A" account.Currency
Console.Write progressIteration
if showProgress then
let progressIteration = sprintf " %A" account.Currency
Console.Write progressIteration

return (account,balance,usdValue)
}

let private GetAccountBalance (account: IAccount): Async<MaybeCached<decimal>*MaybeCached<decimal>> =
async {
let! (_, balance, maybeUsdValue) = GetAccountBalanceInner account
let! (_, balance, maybeUsdValue) = GetAccountBalanceInner account false
return (balance, maybeUsdValue)
}

let private GetAccountBalances (accounts: seq<IAccount>)
: Async<array<IAccount*MaybeCached<decimal>*MaybeCached<decimal>>> =
let accountAndBalancesToBeQueried = accounts |> Seq.map GetAccountBalanceInner
let accountAndBalancesToBeQueried = accounts |> Seq.map (fun acc -> GetAccountBalanceInner acc true)
Console.Write "Retrieving balances..."
Async.Parallel accountAndBalancesToBeQueried

Expand Down

0 comments on commit d9f316b

Please sign in to comment.