Skip to content

Commit

Permalink
Merge pull request #401 from Foundation-Devices/SFT-2851-streamline-s…
Browse files Browse the repository at this point in the history
…inglesig-multisig-choice

SFT-2851: streamline singlesig multisig choice
  • Loading branch information
mjg-foundation authored Oct 11, 2023
2 parents c46749d + 66ed889 commit bc4178c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ def __init__(self, sig_type=None, multisig_wallet=None):
async def choose_sig_type(self):
from pages import SinglesigMultisigChooserPage
from multisig_wallet import MultisigWallet
from common import settings

xfp = settings.get('xfp')
multisigs = MultisigWallet.get_by_xfp(xfp)

if MultisigWallet.get_count() == 0:
if len(multisigs) == 0:
self.sig_type = 'single-sig'
self.goto(self.scan_address, save_curr=False) # Don't save this since we're skipping this state
else:
result = await SinglesigMultisigChooserPage(
initial_value=self.sig_type).show()
initial_value=self.sig_type, multisigs=multisigs).show()
if result is None:
if not self.back():
self.set_result(False)
Expand Down
13 changes: 13 additions & 0 deletions ports/stm32/boards/Passport/modules/multisig_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,19 @@ def get_by_id(cls, id):

return None

@classmethod
def get_by_xfp(cls, xfp):
lst = cls.get_all()
lst_by_xfp = []

for ms in lst:
for xpub in ms.xpubs:
if xfp == xpub[0]: # XFP entry in the multisig's xpub tuple
lst_by_xfp.append(ms)
break

return lst_by_xfp

@classmethod
def delete_by_id(cls, id):
from utils import to_str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,12 @@


class SinglesigMultisigChooserPage(ChooserPage):
def __init__(self, card_header={'title': 'Single/Multisig'}, initial_value=None):
from multisig_wallet import MultisigWallet
from common import settings

def __init__(self, multisigs, card_header={'title': 'Single/Multisig'}, initial_value=None):
options = [{'label': 'Single-sig', 'value': ('single-sig', None)}]

xfp = settings.get('xfp')

for ms in MultisigWallet.get_all():
for xpub in ms.xpubs:
if xfp == xpub[0]: # XFP entry in the multisig's xpub tuple
label = '%d/%d: %s' % (ms.M, ms.N, ms.name)
options.append({'label': label, 'value': ('multisig', ms)})
continue
for ms in multisigs:
label = '%d/%d: %s' % (ms.M, ms.N, ms.name)
options.append({'label': label, 'value': ('multisig', ms)})

super().__init__(
card_header=card_header,
Expand Down

0 comments on commit bc4178c

Please sign in to comment.