Skip to content

Commit

Permalink
Use P2TR by default and remove the setting for it
Browse files Browse the repository at this point in the history
  • Loading branch information
hsjoberg committed Nov 6, 2023
1 parent b4b0a1b commit a9e0b66
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 57 deletions.
3 changes: 0 additions & 3 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,6 @@
},
"zmqRawTx": {
"title": "Set bitcoind ZMQ Raw Tx Host"
},
"p2tr": {
"title": "Enable receiving on-chain via Taproot (P2TR)"
}
},
"LN": {
Expand Down
24 changes: 8 additions & 16 deletions src/state/OnChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface ISetTransactionsPayload {

export interface IGetAddressPayload {
forceNew?: boolean;
p2sh?: boolean;
p2wkh?: boolean;
}

export interface ISendCoinsPayload {
Expand Down Expand Up @@ -140,30 +140,22 @@ export const onChain: IOnChainModel = {
actions.setUnconfirmedBalance(walletBalanceResponse);
}),

getAddress: thunk(async (actions, { forceNew, p2sh }, { injections, getStoreState }) => {
getAddress: thunk(async (actions, { forceNew, p2wkh }, { injections }) => {
try {
const { newAddress } = injections.lndMobile.onchain;
let type: lnrpc.AddressType;

if (forceNew) {
if (p2sh) {
type = lnrpc.AddressType.NESTED_PUBKEY_HASH;
if (p2wkh) {
type = lnrpc.AddressType.WITNESS_PUBKEY_HASH;
} else {
if (getStoreState().settings.receiveViaP2TR) {
type = lnrpc.AddressType.TAPROOT_PUBKEY;
} else {
type = lnrpc.AddressType.WITNESS_PUBKEY_HASH;
}
type = lnrpc.AddressType.TAPROOT_PUBKEY;
}
} else {
if (p2sh) {
type = lnrpc.AddressType.UNUSED_NESTED_PUBKEY_HASH;
if (p2wkh) {
type = lnrpc.AddressType.UNUSED_WITNESS_PUBKEY_HASH;
} else {
if (getStoreState().settings.receiveViaP2TR) {
type = lnrpc.AddressType.UNUSED_TAPROOT_PUBKEY;
} else {
type = lnrpc.AddressType.UNUSED_WITNESS_PUBKEY_HASH;
}
type = lnrpc.AddressType.UNUSED_TAPROOT_PUBKEY;
}
}

Expand Down
14 changes: 0 additions & 14 deletions src/state/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export interface ISettingsModel {
changeLndNoGraphCache: Thunk<ISettingsModel, boolean>;
changeInvoiceExpiry: Thunk<ISettingsModel, number>;
changeRescanWallet: Thunk<ISettingsModel, boolean>;
changeReceiveViaP2TR: Thunk<ISettingsModel, boolean, any, IStoreModel>;
changeStrictGraphPruningEnabled: Thunk<ISettingsModel, boolean, any, IStoreModel>;
changeLndPathfindingAlgorithm: Thunk<ISettingsModel, routerrpcEstimator, any, IStoreModel>;
changeMaxLNFeePercentage: Thunk<ISettingsModel, number>;
Expand Down Expand Up @@ -124,7 +123,6 @@ export interface ISettingsModel {
setLndNoGraphCache: Action<ISettingsModel, boolean>;
setInvoiceExpiry: Action<ISettingsModel, number>;
setRescanWallet: Action<ISettingsModel, boolean>;
setReceiveViaP2TR: Action<ISettingsModel, boolean>;
setStrictGraphPruningEnabled: Action<ISettingsModel, boolean>;
setLndPathfindingAlgorithm: Action<ISettingsModel, routerrpcEstimator>;
setMaxLNFeePercentage: Action<ISettingsModel, number>;
Expand Down Expand Up @@ -169,7 +167,6 @@ export interface ISettingsModel {
lndNoGraphCache: boolean;
invoiceExpiry: number;
rescanWallet: boolean;
receiveViaP2TR: boolean;
strictGraphPruningEnabled: boolean;
lndPathfindingAlgorithm: routerrpcEstimator;
maxLNFeePercentage: number;
Expand Down Expand Up @@ -243,7 +240,6 @@ export const settings: ISettingsModel = {
(await getItemObject(StorageItem.invoiceExpiry)) ?? DEFAULT_INVOICE_EXPIRY,
);
actions.setRescanWallet(await getRescanWallet());
actions.setReceiveViaP2TR((await getItemObject(StorageItem.receiveViaP2TR)) ?? false);
actions.setStrictGraphPruningEnabled(
(await getItemObject(StorageItem.strictGraphPruningEnabled)) ?? false,
);
Expand Down Expand Up @@ -447,12 +443,6 @@ export const settings: ISettingsModel = {
actions.setRescanWallet(payload);
}),

changeReceiveViaP2TR: thunk(async (actions, payload, { getStoreActions }) => {
await setItemObject(StorageItem.receiveViaP2TR, payload);
actions.setReceiveViaP2TR(payload);
await getStoreActions().onChain.getAddress({});
}),

changeStrictGraphPruningEnabled: thunk(async (actions, payload) => {
await setItemObject(StorageItem.strictGraphPruningEnabled, payload);
actions.setStrictGraphPruningEnabled(payload);
Expand Down Expand Up @@ -605,9 +595,6 @@ export const settings: ISettingsModel = {
setRescanWallet: action((state, payload) => {
state.rescanWallet = payload;
}),
setReceiveViaP2TR: action((state, payload) => {
state.receiveViaP2TR = payload;
}),
setStrictGraphPruningEnabled: action((state, payload) => {
state.strictGraphPruningEnabled = payload;
}),
Expand Down Expand Up @@ -673,7 +660,6 @@ export const settings: ISettingsModel = {
lndNoGraphCache: false,
invoiceExpiry: DEFAULT_INVOICE_EXPIRY,
rescanWallet: false,
receiveViaP2TR: false,
strictGraphPruningEnabled: false,
lndPathfindingAlgorithm: DEFAULT_PATHFINDING_ALGORITHM,
maxLNFeePercentage: DEFAULT_MAX_LN_FEE_PERCENTAGE,
Expand Down
3 changes: 0 additions & 3 deletions src/storage/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export enum StorageItem { // const enums not supported in Babel 7...
lndNoGraphCache = "lndNoGraphCache",
invoiceExpiry = "invoiceExpiry", // in seconds
rescanWallet = "rescanWallet",
receiveViaP2TR = "receiveViaP2TR",
strictGraphPruningEnabled = "strictGraphPruningEnabled",
lndPathfindingAlgorithm = "lndPathfindingAlgorithm",
maxLNFeePercentage = "maxLNFeePercentage",
Expand Down Expand Up @@ -176,7 +175,6 @@ export const clearApp = async () => {
removeItem(StorageItem.lndNoGraphCache),
removeItem(StorageItem.invoiceExpiry),
removeItem(StorageItem.rescanWallet),
removeItem(StorageItem.receiveViaP2TR),
removeItem(StorageItem.strictGraphPruningEnabled),
removeItem(StorageItem.lndPathfindingAlgorithm),
removeItem(StorageItem.maxLNFeePercentage),
Expand Down Expand Up @@ -262,7 +260,6 @@ export const setupApp = async () => {
setItemObject<boolean>(StorageItem.lndNoGraphCache, false),
setItemObject<number>(StorageItem.invoiceExpiry, DEFAULT_INVOICE_EXPIRY),
setItemObject<boolean>(StorageItem.rescanWallet, false),
setItemObject<boolean>(StorageItem.receiveViaP2TR, false),
setItemObject<boolean>(StorageItem.strictGraphPruningEnabled, false),
setItem(StorageItem.lndPathfindingAlgorithm, DEFAULT_PATHFINDING_ALGORITHM),
setItemObject<number>(StorageItem.maxLNFeePercentage, DEFAULT_MAX_LN_FEE_PERCENTAGE),
Expand Down
4 changes: 2 additions & 2 deletions src/windows/OnChain/OnChainInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const OnChainInfo = ({ navigation }: IOnChainInfoProps) => {
}, [navigation]);

const onGeneratePress = async () => await getAddress({ forceNew: true });
const onGenerateP2SHPress = async () => await getAddress({ forceNew: true, p2sh: true });
const onGenerateP2WPKHPress = async () => await getAddress({ forceNew: true, p2wkh: true });

const onWithdrawPress = () => navigation.navigate("Withdraw");

Expand Down Expand Up @@ -134,7 +134,7 @@ export const OnChainInfo = ({ navigation }: IOnChainInfoProps) => {
disabled={!rpcReady}
style={style.button}
onPress={onGeneratePress}
onLongPress={() => onGenerateP2SHPress()}
onLongPress={() => onGenerateP2WPKHPress()}
>
<Text>{t("newAddress.title")}</Text>
</Button>
Expand Down
19 changes: 0 additions & 19 deletions src/windows/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1157,13 +1157,6 @@ ${t("experimental.tor.disabled.msg2")}`;
await changeDunderEnabled(!dunderEnabled);
};

// Enable Receive by P2TR
const receiveViaP2TR = useStoreState((store) => store.settings.receiveViaP2TR);
const changeReceiveViaP2TR = useStoreActions((store) => store.settings.changeReceiveViaP2TR);
const onToggleReceiveViaP2TR = async () => {
await changeReceiveViaP2TR(!receiveViaP2TR);
};

// Set Max LN Fee Percentage
const maxLNFeePercentage = useStoreState((store) => store.settings.maxLNFeePercentage);
const changeMaxLNFeePercentage = useStoreActions(
Expand Down Expand Up @@ -1865,18 +1858,6 @@ ${t("experimental.tor.disabled.msg2")}`;
</>
)}

<ListItem style={style.listItem} icon={true} onPress={onToggleReceiveViaP2TR}>
<Left>
<Icon style={style.icon} type="MaterialCommunityIcons" name="carrot" />
</Left>
<Body>
<Text>{t("bitcoinNetwork.p2tr.title")}</Text>
</Body>
<Right>
<CheckBox checked={receiveViaP2TR} onPress={onToggleReceiveViaP2TR} />
</Right>
</ListItem>

<ListItem style={style.itemHeader} itemHeader={true}>
<Text>{t("LN.title")}</Text>
</ListItem>
Expand Down

0 comments on commit a9e0b66

Please sign in to comment.